-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
128 lines (107 loc) · 3.84 KB
/
index.js
File metadata and controls
128 lines (107 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const express = require('express');
const chalk = require('chalk');
const mongoose = require('mongoose');
const path = require('path');
const cfonts = require('cfonts');
const chokidar = require('chokidar');
const fetch = require("node-fetch");
require('./config');
const { bot, User } = require('./main/bot');
let bott = require('./main/bot');
let config = require('./config');
let menu = require('./main/menu');
const app = express();
const PORT = process.env.PORT || 3000;
if (web_view) {
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.json());
app.use(express.static(path.join(__dirname, 'views')));
app.get('/', async (req, res) => {
try {
const users = await User.find();
const totalUsers = users.length;
const premiumUsers = users.filter(user => user.isPremium).length;
let botStatus = 'offline';
const response = await fetch(`https://api.telegram.org/bot${botToken}/getMe`);
const data = await response.json();
if (data.ok) {
botStatus = 'online';
}
res.render('index', { totalUsers, premiumUsers, botStatus, botName: data.result.first_name, botUsername: data.result.username, totalFeatures, ownerName, github, telegram });
} catch (error) {
console.error('Error fetching users:', error);
res.status(500).send('Failed to fetch users.');
}
});
app.post('/webhook', (req, res) => {
bot.handleUpdate(req.body);
res.sendStatus(200);
});
app.listen(PORT, () => {
console.log(chalk.whiteBright('╭─── [ LOG ]'));
console.log(chalk.whiteBright('├'), chalk.cyanBright(`</> Server running on port ${PORT}`));
});
}
cfonts.say('ITzpire', {
font: 'block',
align: 'center',
colors: ['cyan', 'red', 'yellow', 'blue'],
background: 'transparent',
space: true,
maxLength: '0',
gradient: true,
independentGradient: false,
transitionGradient: true,
env: 'node'
});
cfonts.say('ITzpire simple bot telegram created by Miftah', {
font: 'console',
align: 'center',
colors: ['red', '#f80'],
background: 'transparent',
space: true,
maxLength: '0',
gradient: true,
independentGradient: false,
transitionGradient: true,
env: 'node'
});
const clearRequireCache = (module) => {
const resolvedModule = require.resolve(module);
if (require.cache[resolvedModule]) {
console.log(chalk.whiteBright('├'), chalk.yellowBright(`Clearing cache for: ${module}`));
}
delete require.cache[resolvedModule];
};
const reloadModules = () => {
console.log(chalk.whiteBright('├'), chalk.blueBright('Reloading the file...'));
clearRequireCache('./main/bot');
clearRequireCache('./config');
clearRequireCache('./main/menu');
bott = require('./main/bot');
config = require('./config');
menu = require('./main/menu');
console.log(chalk.whiteBright('├'), chalk.greenBright('File reloaded successfully.'));
};
const watcher = chokidar.watch(['./main/bot.js', './config.js', './main/menu.js'], {
persistent: true,
ignoreInitial: true,
usePolling: true,
interval: 1000
});
watcher.on('change', (filePath) => {
console.log(chalk.whiteBright('├'), chalk.cyanBright(`${path.basename(filePath)} already changed. Reloading...`));
reloadModules();
});
watcher.on('ready', () => {
console.log(chalk.whiteBright('├'), chalk.greenBright('Watcher is ready.'));
});
watcher.on('error', (err) => {
console.error(chalk.whiteBright('├'), chalk.redBright('Error with watcher:'), err);
});
bot.launch().then(() => {
console.log(chalk.whiteBright('├'), chalk.cyanBright('[✓] Bot is now running!'));
}).catch((err) => {
console.error(chalk.whiteBright('├'), chalk.redBright('[✗] Error starting the bot:'), err);
});