tes-wc-bot
Version:
š Advanced Telegram Bot for Cloudflare Wildcard Domain Management with Telegram Notifications
310 lines (254 loc) ⢠9.35 kB
JavaScript
/*
* Tes Wildcard Bot
* Created by @AutoFtBot69 (https://t.me/AutoFtBot69)
* Copyright (c) 2023 AutoFtBot69
* MIT License
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const readline = require('readline');
// Colors for better UX
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
};
const log = {
info: (msg) => console.log(`${colors.blue}ā¹${colors.reset} ${msg}`),
success: (msg) => console.log(`${colors.green}ā
${colors.reset} ${msg}`),
error: (msg) => console.log(`${colors.red}ā${colors.reset} ${msg}`),
warn: (msg) => console.log(`${colors.yellow}ā ļø${colors.reset} ${msg}`),
title: (msg) => console.log(`${colors.cyan}${colors.bright}${msg}${colors.reset}`),
subtitle: (msg) => console.log(`${colors.magenta}${msg}${colors.reset}`),
};
// Create readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Prompt user for input
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
// Main setup function
async function setupBot() {
console.clear();
log.title('š TES WC BOT SETUP');
log.subtitle('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
log.subtitle('Created by @AutoFtBot69 (https://t.me/AutoFtBot69)');
console.log();
log.info("Welcome! Let's set up your Tes WC Bot in 3 easy steps:");
console.log(' 1ļøā£ Bot Token Configuration');
console.log(' 2ļøā£ Admin Setup');
console.log(' 3ļøā£ Launch Bot');
console.log();
// Create working directory
const workDir = process.cwd();
const botDir = path.join(workDir, 'tes-wc-bot'); // Changed: wc-bot -> tes-wc-bot
// Check if directory exists
if (fs.existsSync(botDir)) {
log.warn(`Directory ${botDir} already exists!`);
const overwrite = await question('Do you want to overwrite it? (y/N): ');
if (overwrite.toLowerCase() !== 'y') {
log.info('Setup cancelled.');
rl.close();
return;
}
// Remove existing directory
fs.rmSync(botDir, { recursive: true, force: true });
}
// Create bot directory
fs.mkdirSync(botDir, { recursive: true });
process.chdir(botDir);
log.success(`Created bot directory: ${botDir}`);
console.log();
// Step 1: Bot Token
log.subtitle('1ļøā£ BOT TOKEN CONFIGURATION');
log.info('Get your bot token from @BotFather on Telegram');
log.info('Link: https://t.me/BotFather');
console.log();
let botToken = '';
while (!botToken) {
botToken = await question('Enter your bot token: ');
if (!botToken) {
log.error('Bot token is required!');
} else if (!botToken.includes(':')) {
log.error('Invalid bot token format!');
botToken = '';
}
}
// Step 2: Admin Setup
console.log();
log.subtitle('2ļøā£ ADMIN CONFIGURATION');
log.info('Get your Telegram ID from @userinfobot');
log.info('Link: https://t.me/userinfobot');
console.log();
let adminId = '';
while (!adminId) {
adminId = await question('Enter your Telegram ID: ');
if (!adminId || isNaN(adminId)) {
log.error('Please enter a valid numeric Telegram ID!');
adminId = '';
}
}
// Optional: Telegram Group ID
console.log();
log.subtitle('š± NOTIFICATIONS (Optional)');
const groupId = await question(
'Telegram Group ID for notifications (optional, press Enter to skip): '
);
// Step 3: Create config files
console.log();
log.subtitle('3ļøā£ GENERATING CONFIGURATION FILES');
// Create .env file
const envContent = `# Tes WC Bot Configuration
# Generated by CLI setup
# Required: Telegram Bot Token from @BotFather
BOT_TOKEN=${botToken}
# Optional: Telegram Group ID for notifications
${groupId ? `TELEGRAM_GROUP_ID=${groupId}` : '# TELEGRAM_GROUP_ID=your_group_id_here'}
# === ADMIN CONFIGURATION ===
ADMIN_IDS=${adminId}
# === DOMAIN CONFIGURATION ===
MAX_CUSTOM_DOMAINS=5
# === TELEGRAM NOTIFICATIONS ===
TELEGRAM_GROUP_ID=${groupId || ''}
# === OPTIONAL CONFIGURATION ===
NODE_ENV=production
LOG_LEVEL=info
`;
fs.writeFileSync('.env', envContent);
log.success('Created .env file');
// Create config file
const configContent = `module.exports = {
// Admin Configuration - Add your Telegram ID here
ADMIN_IDS: [${adminId}],
// Bot Limits
MAX_CUSTOM_DOMAINS: 5,
MAX_DOMAINS_PER_USER: 10,
// Notification Settings
NOTIFICATIONS: {
TELEGRAM: {
enabled: true,
groupId: process.env.TELEGRAM_GROUP_ID || '',
},
},
// Default Domains (you can customize these)
DEFAULT_DOMAINS: [
'example.com',
'test.com',
'demo.com'
]
};`;
fs.mkdirSync('config', { recursive: true });
fs.writeFileSync('config/default.js', configContent);
log.success('Created config/default.js');
// Create package.json for user project
const userPackageJson = {
name: 'my-tes-wc-bot', // Changed: my-wc-bot -> my-tes-wc-bot
version: '1.0.0',
description: 'My Tes WC Bot instance', // Changed: My WC Bot instance -> My Tes WC Bot instance
main: 'index.js',
scripts: {
start: 'node index.js',
dev: 'nodemon index.js',
stop: "pkill -f 'node index.js'",
restart: 'npm run stop && npm start',
logs: 'tail -f bot.log',
},
dependencies: {
'tes-wc-bot': '^1.2.3', // Changed: wc-bot -> tes-wc-bot
dotenv: '^16.3.1',
},
keywords: ['telegram', 'bot', 'wildcard', 'cloudflare', 'tes-wc-bot'], // Changed: wc-bot -> tes-wc-bot
author: 'Bot Owner',
license: 'MIT',
};
fs.writeFileSync('package.json', JSON.stringify(userPackageJson, null, 2));
log.success('Created package.json');
// Create main index.js file
const indexContent = `// Tes WC Bot
// Auto-generated by CLI setup
require('dotenv').config();
const WildcardBot = require('tes-wc-bot'); // Changed: wc-bot -> tes-wc-bot
// Start the bot with your configuration
const bot = new WildcardBot({
configPath: './config/default.js'
});
bot.start().then(() => {
console.log('š Tes WC Bot is running!'); // Changed: WC Bot -> Tes WC Bot
console.log('š± Send /start to your bot to begin');
}).catch(error => {
console.error('ā Failed to start bot:', error.message);
process.exit(1);
});
// Graceful shutdown
process.on('SIGINT', () => {
console.log('\\nš Shutting down bot...');
bot.stop();
process.exit(0);
});`;
fs.writeFileSync('index.js', indexContent);
log.success('Created index.js');
// Create data directory
fs.mkdirSync('data', { recursive: true });
log.success('Created data directory');
// Install dependencies
console.log();
log.subtitle('š¦ INSTALLING DEPENDENCIES');
log.info('Installing tes-wc-bot package...'); // Changed: wc-bot -> tes-wc-bot
try {
execSync('npm install', { stdio: 'pipe' });
log.success('Dependencies installed successfully!');
} catch (error) {
log.error('Failed to install dependencies');
log.info('You can manually run: npm install');
}
// Final success message
console.log();
log.title('š SETUP COMPLETED SUCCESSFULLY!');
log.subtitle('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā');
console.log();
log.success('Your Tes WC Bot is ready to use!'); // Changed: WC Bot -> Tes WC Bot
console.log();
log.info('š Bot files created in:');
console.log(` ${botDir}`);
console.log();
log.info('š To start your bot:');
console.log(` cd ${path.relative(workDir, botDir)}`);
console.log(' npm start');
console.log();
log.info('š± Next steps:');
console.log(' 1. Send /start to your bot on Telegram');
log.info(' 2. Use /addcf to configure Cloudflare');
log.info(' 3. Start setting up wildcard domains!');
console.log();
log.info('š Need help? Join our Telegram support group:'); // Changed: Check the documentation -> Join our Telegram support group
log.info(' https://t.me/AutoFtBot69'); // Changed: GitHub link -> Telegram support group link
rl.close();
}
// CLI argument handling
const args = process.argv.slice(2);
if (args.includes('--help') || args.includes('-h')) {
console.log(`
š Tes WC Bot CLI
Usage:
tes-wc-bot Start interactive setup
tes-wc-bot --help Show this help message
tes-wc-bot --setup Start interactive setup (same as no args)
Examples:
tes-wc-bot # Interactive setup
tes-wc-bot --setup # Interactive setup
`);
process.exit(0);
}
// Start setup
setupBot().catch((error) => {
log.error('Setup failed:', error.message);
process.exit(1);
});