This repository has been archived by the owner on Jan 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
95 lines (81 loc) · 2.38 KB
/
index.js
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
const TeleBot = require('telebot');
const store = require('./store');
const BIBIN_ID = 280807529;
const SILENCE_TIMEOUT = 45 * 60 * 1000;
const BUTTONS = {
joke: {
label: 'Хочу шутейку',
command: '/joke'
},
support: {
label: 'Как добавить фразочки?',
command: '/support'
},
shutUp: {
label: "Завали",
command: "/shutUp"
}
};
const bot = new TeleBot({
token: getAPIToken(),
usePlugins: ['namedButtons'],
pluginConfig: {
namedButtons: {
buttons: BUTTONS
}
}
});
const replyMarkup = bot.keyboard(
[
[BUTTONS.joke.label],
[BUTTONS.support.label, BUTTONS.shutUp.label]
], {resize: true});
bot.on([BUTTONS.joke.command], msg => {
if (msg.from.id !== BIBIN_ID) {
bot.sendMessage(msg.chat.id, store.joke(), {replyMarkup});
} else {
bot.sendMessage(msg.chat.id, store.fuckYou(), {replyMarkup});
}
});
bot.on([BUTTONS.support.command], msg => {
if (msg.from.id !== BIBIN_ID) {
bot.sendMessage(msg.chat.id, store.howToSupport(), {replyMarkup});
} else {
bot.sendMessage(msg.chat.id, store.fuckYou(), {replyMarkup});
}
});
bot.on([/.*@PedoBeerBot.*/, '/help', '/start'], msg => {
if (msg.from.id !== BIBIN_ID) {
bot.sendMessage(msg.chat.id, store.startMessage(), {replyMarkup})
} else {
bot.sendMessage(msg.chat.id, store.fuckYou(), {replyMarkup});
}
});
const onSilence = {};
bot.on(['text'], msg => {
const chatId = msg.chat.id;
clearSilence(chatId);
if (!msg.skipSilenceTimeout) {
onSilence[chatId] = setInterval(() => bot.sendMessage(chatId, store.silence(), {replyMarkup}), SILENCE_TIMEOUT);
}
});
bot.on([BUTTONS.shutUp.command], msg => {
msg.skipSilenceTimeout = true;
const chatId = msg.chat.id;
bot.sendMessage(chatId, store.forceShutUp(!onSilence[chatId]));
});
bot.start();
function clearSilence(chatId) {
const element = onSilence[chatId];
if (element) {
clearTimeout(element);
onSilence[chatId] = undefined;
}
}
function getAPIToken() {
if (process.argv.length < 3 || !process.argv[2] || process.argv[2].trim() === ''){
console.error("You must provide Telegram token. Ex: `node index.js YOUR_TOKEN`");
throw new Error("Please, provide token");
}
return process.argv[2];
}