-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
351 lines (303 loc) · 9.94 KB
/
main.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
require('dotenv').config()
const Telegraf = require("telegraf");
const low = require("lowdb");
const characters = require("./characters.json");
const stripHtml = require("string-strip-html");
const FileSync = require("lowdb/adapters/FileSync");
const adapter = new FileSync("db.json");
const db = low(adapter);
db.defaults({
supports: {
na: {},
eu: {},
sea: {},
cn: {},
},
}).write();
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.catch(err => {
console.error("[Exception]", err);
});
if (process.env.NODE_ENV === 'development') {
bot.use((ctx, next) => {
try {
if (ctx.update.inline_query && ctx.update.inline_query.query) {
const { inline_query } = ctx.update;
const name = inline_query.from.username
? `@${inline_query.from.username}`
: inline_query.from.first_name;
console.info("[inline]", name, inline_query.query);
}
if (
ctx.update.message &&
ctx.update.message.text &&
ctx.update.message.text[0] === "/"
) {
const { message } = ctx.update;
const maybeTitle =
message.chat.type === "group" || message.chat.type === "supergroup"
? message.chat.username
? `[@${message.chat.username}]`
: `[${message.chat.title}]`
: "";
const name = message.from.username
? `@${message.from.username}`
: message.from.first_name;
console.info("[command]", ...[maybeTitle], name, message.text);
}
} catch (err) {
console.error(err);
}
return next();
});
}
bot.command("start", ctx => {
ctx.reply(
`Genshin Impact Utility Bot.
Run /help to learn how to use.`,
{
reply_to_message_id: ctx.update.message.message_id
}
);
});
bot.command("rotations", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/ji2jwd/genshin_impact_guide_album_v04/)`;
ctx.replyWithPhoto("https://i.imgur.com/b76dEGS.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("respawn", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/ji3uhp/updated_respawns_infographic/)`;
ctx.replyWithPhoto("https://i.imgur.com/xGupAcE.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("materialroutes", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/j9q810/i_made_a_little_character_ascension_material)`;
ctx.replyWithPhoto("https://i.imgur.com/udQD7pD.jpeg", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("weapons", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/jf8ed6/table_of_weapon_types_and_character_elements/)`;
ctx.replyWithPhoto("https://i.imgur.com/sa9CFDw.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("charexp", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/j9942t/exp_requirements_per_ascensionphase/)`;
ctx.replyWithPhoto("https://i.imgur.com/gE0YL3Q.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("talentcost", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/jf8awf/talent_ascension_grind_cheat_sheet/)`;
ctx.replyWithPhoto("https://i.imgur.com/m87oXqx.jpeg", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("talentcost2", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/jhtnni/table_of_material_types_for_leveling_6_talents/)`;
ctx.replyWithPhoto("https://i.imgur.com/g3NAhtf.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("dishes", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/jcxkwo/i_created_a_spreadsheet_to_visualize_all/g949miw/)`;
ctx.replyWithPhoto("https://i.imgur.com/MZjSvex.jpeg", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("artifactstats", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/jcz6rg/artifact_stats_handbook/)`;
ctx.replyWithPhoto("https://i.imgur.com/9DcOeYb.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("reactions", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/j9qevf/guide_how_stats_work_and_why_you_shouldnt_only/)`;
ctx.replyWithPhoto("https://i.imgur.com/eBaGQdl.png", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("mobs", ctx => {
const text = `[Source](https://www.reddit.com/r/Genshin_Impact/comments/j6yngs/another_mob_map_gallery/g84gj8l/)`;
ctx.replyWithPhoto("https://i.imgur.com/qM4WwG9.jpeg", {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("ascensionitems", ctx => {
const text = `[Biiiig image ⚓️](https://i.imgur.com/2utiAJY.jpeg)`;
ctx.reply(text, {
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
bot.command("quests", ctx => {
const text = `[All hidden quest location](https://www.reddit.com/r/Genshin_Impact/comments/j5lx3c/all_hidden_quest_location/)`;
ctx.reply(text, {
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
});
for (const char of characters) {
bot.command(char.key, ctx => {
const text =
`[${char.name}](${char.page})`;
if (!char.image) {
return ctx.reply(text, {
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
}
return ctx.replyWithPhoto(char.image, {
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
})
}
bot.command("help", ctx => {
const text = `
*General*
/start - Start the bot
/rotations - Daily domain rotations
/respawn - Respawining resources
/materialroutes - Common routes to farm materials
/weapons - Weapon materials
/charexp - How much character XP is needed
/talentcost - Cost to level talents
/talentcost2 - Cost to level talents more
/dishes - Special dishes
/artifactstats - Possible artifact main status
/reactions - Elemental reaction charts
/mobs - Mob locations
/ascensionitems - Big image over all ascension items
/quests - List all hidden quests
*Characters*
/amber - Info about Amber
/barbara - Info about Barbara
/beidou - Info about Beidou
/bennett - Info about Bennett
/chongyun - Info about Chongyun
/diluc - Info about Diluc
/fischl - Info about Fischl
/jean - Info about Jean
/kaeya - Info about Kaeya
/keqing - Info about Keqing
/klee - Info about Klee
/lisa - Info about Lisa
/mona - Info about Mona
/ningguang - Info about Ningguang
/noelle - Info about Noelle
/qiqi - Info about Qiqi
/razor - Info about Razor
/sucrose - Info about Sucrose
/traveleranemo - Info about Traveler (Anemo)
/travelergeo - Info about Traveler (Geo)
/venti - Info about Venti
/xiangling - Info about Xiangling
/xiao - Info about Xiao
/xingqiu - Info about Xingqiu
*Support*
[Call senpai](https://t.me/lubien)
`;
ctx.replyWithMarkdown(text, {
reply_to_message_id: ctx.update.message.message_id
});
});
function supportCommandFactory(server) {
return ctx => {
const { reply_to_message } = ctx.update.message;
const userId = ctx.update.message.from.id;
const key = `supports.${server}.${userId}`;
const support = db.get(key).value() || {
file_id: undefined,
code: undefined
};
// Update Code
const { text } = ctx.update.message;
const [, ...argsArr] = text.trim().split(" ");
const code = argsArr.join(" ");
if (code.length) {
db.set(key, {
...support,
code
}).write();
return ctx.reply(`Updated friend code`, {
reply_to_message_id: ctx.update.message.message_id
});
}
// Show support
if (!reply_to_message) {
if (!support || !support.file_id) {
return ctx.replyWithMarkdown(
`No ${server.toUpperCase()} friend code. Use /friend to learn how to setup`
);
}
return ctx.replyWithPhoto(support.file_id, {
caption: support.code || `No ${server.toUpperCase()} friend code`,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
});
}
// Update photo
const photos = reply_to_message.photo;
const photo = Array.isArray(photos) ? photos[photos.length - 1] : photos;
const hasPhotos = Boolean(photo);
if (!hasPhotos) {
return ctx.reply(`Reply to a photo`, {
reply_to_message_id: ctx.update.message.message_id
});
}
db.set(key, {
...support,
file_id: photo.file_id
}).write();
return ctx.replyWithMarkdown(`Updated ${server.toUpperCase()} support`, {
reply_to_message_id: ctx.update.message.message_id
});
};
}
bot.command("friendna", supportCommandFactory("na"));
bot.command("friendeu", supportCommandFactory("eu"));
bot.command("friendsea", supportCommandFactory("sea"));
bot.command("friendcn", supportCommandFactory("cn"));
bot.command("friend", ctx => {
const text = `*Servers:*
/friendna - Show or update NA support
/friendeu - Show or update EU support
/friendsea - Show or update SEA support
/friendcn - Show or update CN support`;
ctx.replyWithDocument(
"https://github.com/lubien/imgur/blob/master/bbchanne-support.gif?raw=true",
{
caption: text,
parse_mode: "markdown",
reply_to_message_id: ctx.update.message.message_id
}
);
});
bot.launch();