-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.js
218 lines (192 loc) · 8.42 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
require('dotenv').config();
const TelegramBot = require('node-telegram-bot-api');
const config = require('./config');
const commands = require('./commands');
// const sequelize = require('./models').sequelize;
const { Activity } = require('./services/activity');
const Redis = require('./services/redis');
const { update_username } = require('./utils');
// sequelize
// .sync({
// //force: true
// })
// .then(function () {
// console.log('Db synced');
// });
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(config.telegram.token, {
polling: true,
});
const redis = new Redis();
const activity = new Activity(redis);
redis.connect();
const start_command = commands.start(bot);
const tip_empty_command = commands.tip_empty(bot);
const tip_command = commands.tip(bot);
const rain_command = commands.rain(bot);
const balance_command = commands.balance(bot);
const deposit_command = commands.deposit(bot);
const withdraw_command = commands.withdraw(bot);
const withdraw_empty_command = commands.withdraw_empty(bot);
const transactions_command = commands.transactions(bot);
const wallet_command = commands.wallet(bot);
const setwallet_command = commands.setwallet(bot);
const setwallet_empty_command = commands.setwallet_empty(bot);
const nam_command = commands.nam(bot);
const filantropica_command = commands.filantropica(bot);
const help_command = commands.help(bot);
const fees_command = commands.fees(bot);
const price_command = commands.price(bot);
const staking_command = commands.staking(bot);
const system_command = commands.system(bot);
const stats_command = commands.stats(bot);
const scoreboard_command = commands.scoreboard(bot);
const tutorial_command = commands.tutorial(bot);
const lottery_command = commands.lottery(bot);
const lotterytickets_command = commands.lotterytickets(bot);
const lotterydeposit_command = commands.lotterydeposit(bot);
const lotterywithdraw_command = commands.lotterywithdraw(bot);
const lotteryfaq_command = commands.lotteryfaq(bot);
const lotteryhistory_command = commands.lotteryhistory(bot);
// Middleware
bot.on('message', async (msg) => {
// FIXME: Possibly only run update_username for msg.chat.type === private (less events)
try {
await update_username(msg.from);
} catch (error) {
console.error(error);
}
// Do not log activity with bot in private (only channels)
if (msg.chat && msg.chat.type && msg.chat.type !== 'private') {
//console.log(msg.chat);
const message_size = msg.text ? msg.text.length : 0;
activity
.add(msg.chat.id, msg.from.id, msg.from.username, message_size)
.catch(console.error);
}
// For debugging
// console.log(msg);
});
bot.on('inline_query', function (iq) {
bot.answerInlineQuery(iq.id, [
{ type: 'game', id: '0', game_short_name: config.game.id },
]);
});
bot.on('callback_query', function (q) {
const key = `query_${q.id}`;
const message = q.message ? q.message.message_id : q.inline_message_id;
const url = `${config.game.url}/#query=${q.id}&message=${message}`;
console.log(`[CALLBACK] query: ${q.id}, url: ${url}, message: ${message}`);
redis.set(key, JSON.stringify(q));
redis.expire(key, 60 * 60 * 24 * 30); // 1 month
bot.answerCallbackQuery(q.id, { url });
});
bot.onText(/\/game$/, function (msg) {
bot.sendGame(msg.chat.id, config.game.id);
});
bot.onText(/\/game@webdollar_tip_bot$/, function (msg) {
bot.sendGame(msg.chat.id, config.game.id);
});
// bot.onText(/\/tip$/, tip_empty_command);
// bot.onText(/\/tip \w+$/, tip_empty_command);
// bot.onText(/\/tip @\w+$/, tip_empty_command);
// bot.onText(/\/tip \w+$/, tip_empty_command);
// bot.onText(/\/tip \w+ [0-9]+$/, tip_empty_command);
// bot.onText(/\/tip@webdollar_tip_bot$/, tip_empty_command);
// bot.onText(/\/tip@webdollar_tip_bot \w+$/, tip_empty_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+$/, tip_empty_command);
// bot.onText(/\/tip@webdollar_tip_bot \w+$/, tip_empty_command);
// bot.onText(/\/tip@webdollar_tip_bot \w+ [0-9]+$/, tip_empty_command);
// bot.onText(/\/tip @\w+ \w+$/, tip_command);
// bot.onText(/\/tip @\w+ \w+ webd$/, tip_command);
// bot.onText(/\/tip @\w+ \w+$/, tip_command);
// bot.onText(/\/tip @\w+ \$\w+$/, tip_command);
// bot.onText(/\/tip @\w+ \$\w+$/, tip_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+ \w+$/, tip_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+ \w+ webd$/, tip_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+ \w+$/, tip_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+ \$\w+$/, tip_command);
// bot.onText(/\/tip@webdollar_tip_bot @\w+ \$\w+$/, tip_command);
// bot.onText(/\/rain$/, rain_command);
// bot.onText(/\/rain [0-9]+$/, rain_command);
// bot.onText(/\/rain [0-9]+ [0-9]+$/, rain_command);
bot.onText(/\/start$/, start_command);
bot.onText(/\/tipbalance$/, balance_command);
bot.onText(/\/deposit$/, deposit_command);
bot.onText(/\/withdraw$/, withdraw_empty_command);
bot.onText(/\/withdraw [0-9]+$/, withdraw_command);
bot.onText(
/\/withdraw [0-9]+ WEBD\$[a-km-zA-NP-Z0-9+@#$]{33,34}\$$/,
withdraw_command
);
bot.onText(/\/transactions$/, transactions_command);
bot.onText(/\/wallet$/, wallet_command);
bot.onText(/\/setwallet$/, setwallet_empty_command);
bot.onText(
/\/setwallet WEBD\$[a-km-zA-NP-Z0-9+@#$]{33,34}\$$/,
setwallet_command
);
// bot.onText(/\/filantropica$/, filantropica_command);
// bot.onText(/\/nam$/, nam_command);
// bot.onText(/\/help$/, help_command);
bot.onText(/\/fees$/, fees_command);
// bot.onText(/\/price$/, price_command);
// bot.onText(/\/price [0-9]+$/, price_command);
bot.onText(/\/staking$/, staking_command);
// bot.onText(/\/system$/, system_command);
// bot.onText(/\/stats$/, stats_command);
// bot.onText(/\/scoreboard$/, scoreboard_command);
// bot.onText(/\/tutorial$/, tutorial_command);
// bot.onText(/\/lottery$/, lottery_command);
// bot.onText(/\/lotterytickets$/, lotterytickets_command);
// bot.onText(/\/lotterydeposit$/, lotterydeposit_command);
// bot.onText(/\/lotterydeposit [0-9]+$/, lotterydeposit_command);
// bot.onText(/\/lotterywithdraw$/, lotterywithdraw_command);
// bot.onText(/\/lotterywithdraw [0-9]+$/, lotterywithdraw_command);
// bot.onText(/\/lotteryfaq$/, lotteryfaq_command);
// bot.onText(/\/lotteryhistory$/, lotteryhistory_command);
// bot.onText(/\/rain@webdollar_tip_bot$/, rain_command);
// bot.onText(/\/rain@webdollar_tip_bot [0-9]+$/, rain_command);
// bot.onText(/\/rain@webdollar_tip_bot [0-9]+ [0-9]+$/, rain_command);
bot.onText(/\/start@webdollar_tip_bot$/, start_command);
bot.onText(/\/tipbalance@webdollar_tip_bot$/, balance_command);
bot.onText(/\/deposit@webdollar_tip_bot$/, deposit_command);
bot.onText(/\/withdraw@webdollar_tip_bot$/, withdraw_empty_command);
bot.onText(/\/withdraw@webdollar_tip_bot [0-9]+$/, withdraw_command);
bot.onText(
/\/withdraw@webdollar_tip_bot [0-9]+ WEBD\$[a-km-zA-NP-Z0-9+@#$]{33,34}\$$/,
withdraw_command
);
bot.onText(/\/transactions@webdollar_tip_bot$/, transactions_command);
bot.onText(/\/wallet@webdollar_tip_bot$/, wallet_command);
bot.onText(/\/setwallet@webdollar_tip_bot$/, setwallet_empty_command);
bot.onText(
/\/setwallet@webdollar_tip_bot WEBD\$[a-km-zA-NP-Z0-9+@#$]{33,34}\$$/,
setwallet_command
);
// bot.onText(/\/filantropica@webdollar_tip_bot$/, filantropica_command);
// bot.onText(/\/nam@webdollar_tip_bot$/, nam_command);
// bot.onText(/\/help@webdollar_tip_bot$/, help_command);
bot.onText(/\/fees@webdollar_tip_bot$/, fees_command);
// bot.onText(/\/price@webdollar_tip_bot$/, price_command);
// bot.onText(/\/price@webdollar_tip_bot [0-9]+$/, price_command);
bot.onText(/\/staking@webdollar_tip_bot$/, staking_command);
// bot.onText(/\/system@webdollar_tip_bot$/, system_command);
// bot.onText(/\/stats@webdollar_tip_bot$/, stats_command);
// bot.onText(/\/scoreboard@webdollar_tip_bot$/, scoreboard_command);
// bot.onText(/\/tutorial@webdollar_tip_bot$/, tutorial_command);
// bot.onText(/\/lottery@webdollar_tip_bot$/, lottery_command);
// bot.onText(/\/lotterytickets@webdollar_tip_bot$/, lotterytickets_command);
// bot.onText(/\/lotterydeposit@webdollar_tip_bot$/, lotterydeposit_command);
// bot.onText(
// /\/lotterydeposit@webdollar_tip_bot [0-9]+$/,
// lotterydeposit_command
// );
// bot.onText(/\/lotterywithdraw@webdollar_tip_bot$/, lotterywithdraw_command);
// bot.onText(
// /\/lotterywithdraw@webdollar_tip_bot [0-9]+$/,
// lotterywithdraw_command
// );
// bot.onText(/\/lotteryfaq@webdollar_tip_bot$/, lotteryfaq_command);
// bot.onText(/\/lotteryhistory@webdollar_tip_bot$/, lotteryhistory_command);
module.exports = { bot };