-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegramBot.js
More file actions
88 lines (79 loc) · 2.92 KB
/
Copy pathtelegramBot.js
File metadata and controls
88 lines (79 loc) · 2.92 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
const TelegramBot = require('node-telegram-bot-api');
const user = require('./models/user');
const event = require('./models/event');
// replace the value below with the Telegram token you receive from @BotFather
const token = '885391252:AAGvMLDuOXELn7kKjSb1RI48QW4idPgGw4A';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, { polling: true });
bot.onText(/\/RazmerChlena/, async (msg, match) => {
const chatId = msg.chat.id;
try {
let fetchedUser = await user.findUserByTlegramLogin(msg.from.username);
if (fetchedUser) {
const resp = Math.ceil(Math.random() * 32);
if (fetchedUser.telegramChatId)
bot.sendMessage(tee, resp);
else {
fetchedUser.telegramChatId = chatId;
let updUser = await user.update(fetchedUser);
}
bot.sendMessage(chatId, resp);
} else {
bot.sendMessage(chatId, "Enemy spy detected!!! Ruslan ne proidet!!!");
}
} catch (err) {
console.log(err);
}
});
bot.onText(/\/hello/, (msg, match) => {
const chatId = msg.chat.id;
const resp = "Hello, is anybody else there?";
bot.sendMessage(chatId, resp);
});
bot.onText(/\/events/, async (msg, match) => {
const chatId = msg.chat.id;
try {
let fetchedUser = await user.findUserByTlegramLogin(msg.from.username);
if (fetchedUser) {
if (fetchedUser.events.length == 0)
bot.sendMessage(chatId, "You don`t have any events, please add some on our website!");
else {
let events = "\n";
for (let i = 0; i < fetchedUser.events.length; i++) {
events += (`${i + 1} : ` + fetchedUser.events[i].name + "\n");
}
const htmlEvents = `
<strong>Your events : </strong>
<pre>
${events}
</pre>
`
bot.sendMessage(chatId, htmlEvents, {
parse_mode: 'HTML'
});
}
} else {
bot.sendMessage(chatId, "Enemy spy detected!!! Ruslan ne proidet!!!");
}
} catch (err) {
console.log(err);
}
});
bot.onText(/\/help/, async (msg, match) => {
const chatId = msg.chat.id;
try {
let fetchedUser = await user.findUserByTlegramLogin(msg.from.username);
if (fetchedUser) {
bot.sendMessage(chatId, "To start using bot just edit your telegram username in your profile");
} else {
bot.sendMessage(chatId, "Enemy spy detected!!! Ruslan ne proidet!!!");
}
} catch (err) {
console.log(err);
}
});
bot.onText(/\/start/, async (msg, match) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, "Hello my young user, to start enjoying your life just edit your profile, kk w8!");
});
module.exports = bot;