-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
79 lines (65 loc) · 2.47 KB
/
bot.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
const TelegramBot = require('node-telegram-bot-api');
require('dotenv').config();
const get_data = require('./getData').get_data;
const Constants = require('./Constants');
const bot = new TelegramBot(Constants.TOKEN, {polling: true});
let deal_with_message = (msg) => {
if (msg.text.includes(Constants.BOT_NAME)) {
if (msg.text.length <= 90){
let user_id = msg.from.id;
//check if text message is properly formatted
let user_name = msg.from.first_name;
let current_chat = msg.chat.id;
let input_array = msg.text.replace(Constants.BOT_NAME,'').split(/(\s+)/).filter( e => e.trim().length > 0);
let temp = input_array.join(" "); //gets which command to run
//console.log("main menu option= ",temp);
switch (temp) {
case 'all':
get_data('a', current_chat, bot, false);
break;
case 'eu':
get_data(2, current_chat, bot, false);
break;
case 'sa':
get_data(3, current_chat, bot, false);
break;
case 'us east':
get_data(1, current_chat, bot, false);
break;
case 'us west':
get_data(0, current_chat, bot, false);
break;
case 'help':
bot.sendMessage(current_chat, Constants.HELP_MESSAGE, {parse_mode: "HTML"});
break;
default:
get_data(temp, current_chat, bot, false);
}
}else{
bot.sendMessage(current_chat, "<b>"+user_name+" that query is too long what are you trying to do you smelly teapot?</b>", {parse_mode : "HTML"});
}
}else if(msg.text[0] === '/'){
}
};
bot.on('message', (msg) => {
//console.log(msg);
// if(!Constants.APPROVED_CHANNELS.includes(parseInt(msg.chat.id) )){
// console.log("inside wrong channel leaving:", msg.chat.id, " ", msg.chat.title);
// return bot.leaveChat(msg.chat.id);
// }
if(msg.text){
deal_with_message(msg);
}
});
bot.on('polling_error', (error) => {
if( error.code ){
if(error.code !== 'EFATAL'){
console.log("error code: ", error);
}
}else{
console.log("error code: ", error);
}
});
setTimeout( () => {
process.exit();
},3600000);