Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
132 lines (114 loc) · 4.46 KB
/
Copy pathindex.js
File metadata and controls
132 lines (114 loc) · 4.46 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
129
130
131
132
const express = require('express');
const TelegramBot = require('node-telegram-bot-api');
const { Message } = require("./lib/message");
const env = require("./env");
const path = require("path");
const prefix = (!env.HANDLERS || env.HANDLERS.trim() === 'null' || env.HANDLERS.trim() === 'false') ? '' : env.HANDLERS.trim();
const fs = require("fs");
const cmds = require("./lib/events");
let regex = new RegExp("^(" + prefix.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + ")(\\s)(.+)");
const app = express();
const port = process.env.PORT || 3000;
const client = new TelegramBot(env.TOKEN, { polling: true });
console.log("Bot started!");
console.log("🔀 Installing Plugins...");
fs.readdirSync(path.join(__dirname, "/plugins")).forEach((plugin) => {
if (path.extname(plugin).toLowerCase() === ".js") {
try {
const pluginPath = path.join(__dirname, "/plugins/", plugin);
require(pluginPath);
console.log(`Folder loaded: ${plugin}`);
} catch (e) {
console.error(`Error in loading folder ${plugin}:`, e);
fs.unlinkSync(path.join(__dirname, '/plugins/', plugin));
}
}
});
console.log("✅ Plugins Installed!");
client.onText(/\/start (.+)/, async (msg, match) => {
try {
const message = new Message(client, msg, prefix);
if (!message.admin) {
await message.send("<b>Ask admin for sudo to use Doraemon</b> \n\n <i>Your ID: " + msg.chat.id + "</i> \n <b>Admin: <a href=\"https://wa.me/917025673121\">Loki-Xer</a></b>", {
parse_mode: "HTML",
disable_web_page_preview: true
});
}
} catch (error) {
console.error("An error occurred:", error);
}
});
client.on('message', async (msg) => {
try {
if (!msg) return;
const message = new Message(client, msg, prefix);
if (message.isBot) return;
if (message.text.startsWith(prefix) && message.text[1] === " ") {
message.text = message.text.replace(regex, '$1$3');
}
if (message.admin) {
if (message.text.startsWith(">")) {
let m = message;
const code = message.text.slice(1).trim();
try {
let evaled = await eval(`(async () => { ${code} })()`);
if (typeof evaled !== "string") evaled = require("util").inspect(evaled);
return await message.send(evaled);
} catch (error) {
return await message.send(`${error.message}`);
}
}
}
for (const command of cmds.commands) {
if (typeof command.pattern === 'string' && command.pattern.replace(/[^a-zA-Z0-9-+]/g, '')) {
if (command.fromAdmin && !message.admin) return;
const EventCmd = prefix + command.pattern.replace(/[^a-zA-Z0-9-+]/g, '');
if (message.text.toLowerCase().startsWith(EventCmd)) {
try {
message.command = EventCmd.replace(prefix, "").trim();
message.match = message.text.toLowerCase().replace(message.command, '').replace(prefix, "").trim();
await command.function(message, message.match, client);
} catch (e) {
console.log(e);
}
}
}
}
console.log("[TG BOT MESSAGE]");
console.log(new Date());
console.log(message.user.firstName);
console.log(msg.text);
} catch (error) {
console.error('Error handling message:', error);
}
});
client.on('callback_query', async (callbackQuery) => {
try {
const message = new Message(client, callbackQuery.message, prefix);
message.action = prefix + callbackQuery.data;
for (const command of cmds.commands) {
if (typeof command.pattern === 'string' && command.pattern.replace(/[^a-zA-Z0-9-+]/g, '')) {
if (command.fromAdmin && !message.admin) return;
const EventCmd = prefix + command.pattern.replace(/[^a-zA-Z0-9-+]/g, '');
if (message.action.toLowerCase().startsWith(EventCmd)) {
try {
message.command = EventCmd.replace(prefix, "").trim();
message.match = message.action.toLowerCase().replace(message.command, '').replace(prefix, "").trim();
await command.function(message, message.match, client);
} catch (e) {
console.log(e);
}
}
}
}
console.log("[TG BOT CALLBACK QUERY]");
console.log(new Date());
console.log(message.user.firstName);
console.log(callbackQuery.data);
} catch (error) {
console.error('Error handling callback query:', error);
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});