-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (23 loc) · 827 Bytes
/
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
const TelegramBot = require('node-telegram-bot-api');
const token = require('./token');
const bot = new TelegramBot(token, { polling: true });
const avengers = require('./avengers');
const voteKeyboard = require('./vote-keyboard');
const removeKeyboard = require('./remove-keyboard');
const saveVote = require('./save-vote');
bot.onText(/\/votar/, function (msg, match) {
const chatId = msg.chat.id;
const avenger = avengers.getAvenger();
bot.sendPhoto(chatId, avenger.picture, voteKeyboard)
.then(res => {
bot.once('message', (msg) => {
let vote = Number(msg.text);
if (!vote) {
bot.sendMessage(chatId, 'Vota direito ae! \u{1F44E}', removeKeyboard);
return false;
}
saveVote(vote, avenger);
bot.sendMessage(chatId, '\u{1F44D}', removeKeyboard);
});
});
});