-
Notifications
You must be signed in to change notification settings - Fork 3
/
Main.ts
471 lines (452 loc) Β· 27.7 KB
/
Main.ts
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
//version 2.15.0
//Bot Modules Written by the bot devs
import HDB from "./ModulesDatabase/HandleDB.js";
import HF from "./ModulesDatabase/HandleFilters.js";
import HT from "./ModulesDatabase/HandleTags.js";
import HB from "./ModulesDatabase/HandleBirthdays.js";
import HS from "./ModulesImmediate/HandleStickers.js";
import HAF from "./ModulesDatabase/HandleAdminFunctions.js";
import HL from "./ModulesDatabase/HandleLanguage.js";
import HP from "./ModulesDatabase/HandlePermissions.js";
import HAPI from "./ModulesImmediate/HandleAPIs.js";
import HR from "./ModulesDatabase/HandleReminders.js";
import HAFK from "./ModulesDatabase/HandleAFK.js";
import HO from "./ModulesImmediate/HandleOther.js";
import Group from "./Classes/Group.js";
import Person from "./Classes/Person.js";
import apiKeys from "./apiKeys.js";
import {Strings} from "./Strings.js";
//Open-Whatsapp and Schedule libraries and child_process library
import {create, Chat, Message, Client} from "@open-wa/wa-automate";
import {ChatId, ContactId, MessageId} from "@open-wa/wa-automate/dist/api/model/aliases";
import Schedule from "node-schedule";
import childProcess from "child_process";
//The bot devs' phone numbers
const botDevs: ContactId[] = apiKeys.botDevs;
//Local storage of data to not require access to the database at all times ("cache")
let groupsDict: { [key: ChatId]: Group } = {}, usersDict: { [key: ContactId]: Person } = {};
let restGroups: ChatId[] = [], restPersons: ContactId[] = [],
restGroupsFilterSpam: ChatId[] = [], restPersonsCommandSpam: ContactId[] = [];
let chatsWithReminders: ChatId[] = [], afkPersons: ContactId[] = [];
//Scheduling tasks
let scheduleRule = new Schedule.RecurrenceRule();
scheduleRule.tz = apiKeys.region;
scheduleRule.second = 0;
scheduleRule.minute = 0;
scheduleRule.hour = 0;
//Helper type for the Group and Person objects' properties
export type TillZero<N extends number> = HelpType<N, []>;
type HelpType<N extends number, A extends unknown[]> = A['length'] extends N ? A[number] : HelpType<N, [A['length'], ...A]>;
process.on('uncaughtException', err => {
console.log(err);
});
async function HandleImmediate(client: Client, message: Message, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "make_sticker")).test(bodyText)) {
await HS.handleStickers(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "create_text_sticker")).test(bodyText)) {
await HS.createTextSticker(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if (Strings["help_me_pwease"]["he"].test(bodyText) || Strings["help_me_pwease"]["en"].test(bodyText) || Strings["help_me_pwease"]["la"].test(bodyText) || Strings["help_me_pwease"]["fr"].test(bodyText)) {
await HL.sendHelpMessage(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "translate_to")).test(bodyText)) {
await HAPI.translate(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "scan_link")).test(bodyText)) {
await HAPI.scanLinks(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "change_link_type")).test(bodyText)) {
await HO.changeLinkType(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "fetch_stock")).test(bodyText)) {
await HAPI.fetchStock(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "search_in_urban")).test(bodyText)) {
await HAPI.searchUrbanDictionary(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "check_crypto")).test(bodyText)) {
await HAPI.fetchCryptocurrency(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_profile")).test(bodyText)) {
await HO.ShowStats(client, bodyText, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "afk_me_pwease")).test(bodyText)) {
await HAFK.afkOn(client, chatID, messageID, authorID, groupsDict, usersDict, afkPersons);
usersDict[authorID].commandCounter++;
return false;
/* } else if ((await HL.getGroupLang(groupsDict, chatID, "init_tic_tac_toe")).test(bodyText)) {
await H3T.TicTacToe(client, bodyText, chatID, messageID, authorID, groupsDict);
usersDict[authorID].commandCounter++;
return true; */
} else if ((await HL.getGroupLang(groupsDict, chatID, "download_music")).test(bodyText)) {
await HAPI.downloadMusic(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "create_survey")).test(bodyText)) {
await HO.makeButtons(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "wordle_game")).test(bodyText)) {
await HO.wordleGame(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "stable_diffusion_create")).test(bodyText)) {
await HAPI.stableDiffusion(client, bodyText, chatID, authorID, messageID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "transcribe_audio")).test(bodyText)) {
await HAPI.transcribeAudio(client, message, chatID, authorID, messageID, groupsDict, usersDict, botDevs);
usersDict[authorID].commandCounter++;
return false;
} else if (Strings["change_language"]["he"].test(bodyText) || Strings["change_language"]["en"].test(bodyText) || Strings["change_language"]["la"].test(bodyText) || Strings["change_language"]["fr"].test(bodyText)) {
await HL.changeGroupLang(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandleShows(client: Client, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "show_filters")).test(bodyText)) {
await HF.showFilters(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_tags")).test(bodyText)) {
await HT.showTags(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_birthdays")).test(bodyText)) {
await HB.showBirthdays(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_group_function_permissions")).test(bodyText)) {
await HP.showGroupFunctionsPermissions(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_group_user_permissions")).test(bodyText)) {
await HP.showGroupPersonsPermissions(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function Tags(client: Client, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId, quotedMsgID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "tag_all")).test(bodyText)) {
await HT.tagEveryone(client, bodyText, chatID, quotedMsgID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "tag_person")).test(bodyText)) {
await HT.checkTags(client, bodyText, chatID, messageID, authorID, quotedMsgID, groupsDict, usersDict, afkPersons);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "check_tags")).test(bodyText)) {
await HT.whichMessagesTaggedIn(client, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "clear_tags")).test(bodyText)) {
await HT.clearTaggedMessaged(client, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "next_tag_list")).test(bodyText)) {
await HT.nextPersonInList(client, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandleFilters(client: Client, message: Message, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "add_filter")).test(bodyText)) {
await HF.addFilter(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return [false, false];
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_filter")).test(bodyText)) {
await HF.remFilter(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return [false, false];
} else if ((await HL.getGroupLang(groupsDict, chatID, "edit_filter")).test(bodyText)) {
await HF.editFilter(client, message, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return [false, false];
}
return [true, true];
}
async function HandleTags(client: Client, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "add_tag")).test(bodyText)) {
await HT.addTag(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_tag")).test(bodyText)) {
await HT.remTag(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "create_tag_list")).test(bodyText)) {
await HT.createTagList(client, bodyText, chatID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "add_tagging_group")).test(bodyText)) {
await HT.addTaggingGroup(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_tagging_group")).test(bodyText)) {
await HT.removeTaggingGroup(client, bodyText, chatID, messageID, groupsDict)
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "add_person_to_tagging_group")).test(bodyText)) {
await HT.addPersonToTaggingGroup(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_person_from_tagging_group")).test(bodyText)) {
await HT.removePersonFromTaggingGroup(client, bodyText, chatID, messageID, groupsDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandleBirthdays(client: Client, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "add_birthday")).test(bodyText)) {
await HB.addBirthday(client, bodyText, chatID, authorID, messageID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_birthday")).test(bodyText)) {
await HB.remBirthday(client, bodyText, authorID, chatID, messageID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "add_birthday_to_group")).test(bodyText)) {
await HB.addCurrentGroupToBirthDayBroadcastList(client, bodyText, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_birthday_from_group")).test(bodyText)) {
await HB.remCurrentGroupFromBirthDayBroadcastList(client, bodyText, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandlePermissions(client: Client, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "set_permissions")).test(bodyText)) {
await HP.updateGroupAdmins(client, chatID, groupsDict);
await HP.setFunctionPermissionLevel(client, bodyText, chatID, messageID, usersDict[authorID].permissionLevel[chatID], groupsDict[chatID].functionPermissions, groupsDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "mute_participant")).test(bodyText)) {
await HP.muteParticipant(client, bodyText, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "unmute_participant")).test(bodyText)) {
await HP.unmuteParticipant(client, bodyText, chatID, messageID, authorID, groupsDict, usersDict);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandleReminders(client: Client, message: Message, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
if ((await HL.getGroupLang(groupsDict, chatID, "add_reminder")).test(bodyText)) {
await HR.addReminder(client, message, bodyText, chatID, messageID, groupsDict, chatsWithReminders);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "remove_reminder")).test(bodyText)) {
await HR.removeReminder(client, bodyText, chatID, messageID, groupsDict, chatsWithReminders);
usersDict[authorID].commandCounter++;
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "show_reminders")).test(bodyText)) {
await HR.showReminders(client, groupsDict, messageID, chatID);
usersDict[authorID].commandCounter++;
return false;
}
return true;
}
async function HandleAdminFunctions(client: Client, message: Message, bodyText: string, chatID: ChatId, authorID: ContactId, messageID: MessageId) {
usersDict[authorID].permissionLevel[chatID] = 3;
if (/^\/Ban/i.test(bodyText) || /^\/Unban/i.test(bodyText)) {
await HAF.handleUserRest(client, bodyText, chatID, messageID, message.quotedMsgObj, restPersons, restPersonsCommandSpam, usersDict[authorID]);
return false;
} else if (/^\/Block group/i.test(bodyText) || /^\/Unblock group/i.test(bodyText)) {
await HAF.handleGroupRest(client, bodyText, chatID, messageID, restGroups, restGroupsFilterSpam, groupsDict[chatID]);
return false;
} else if ((/^Join /.test(bodyText)) || (/^ΧΧ¦ΧΧ¨Χ£ /.test(bodyText))) {
await HAF.handleBotJoin(client, bodyText, chatID, messageID);
return false;
} else if (/^!ping$/i.test(bodyText)) {
await HAF.ping(client, message, bodyText, chatID, messageID, groupsDict, usersDict, restGroups, restPersons, restGroupsFilterSpam, restPersonsCommandSpam);
return false;
} else if (/^\/exec/i.test(bodyText)) {
await HAF.execute(client, bodyText, message, chatID, messageID, authorID, groupsDict, usersDict, restGroups, restPersons, restGroupsFilterSpam, restPersonsCommandSpam, afkPersons, botDevs, HDB, HF, HT, HB, HS, HAF, HL, HP, HAPI, HR, HAFK, HO, Group, Person, Strings);
return false;
} else if ((await HL.getGroupLang(groupsDict, chatID, "help_admin")).test(bodyText)) {
await client.reply(chatID, await HL.getGroupLang(groupsDict, chatID, "help_admin_reply"), messageID);
return false;
}
return true;
}
//Main function
function start(client: Client) {
//Check if VPN is on
childProcess.exec("sh /app/checkVpn.sh", async (_, stdout) => {
if (stdout.includes("1")) {
console.log("VPN is on");
} else {
console.log("VPN is off");
process.exit();
}
});
//Check if there are birthdays everyday at midnight
Schedule.scheduleJob(scheduleRule, async function () {
await HB.checkBirthdays(client, usersDict, groupsDict);
});
//Reset all group counters everyday at midnight
Schedule.scheduleJob(scheduleRule, async function () {
for (const groupID in groupsDict)
groupsDict[groupID].resetCounters();
for (const personID in usersDict)
usersDict[personID].resetCounters();
});
//Reset the filter & command counters for all the groups & persons
setInterval(function () {
for (const groupID in groupsDict)
groupsDict[groupID].filterCounter = 0;
for (const personID in usersDict)
usersDict[personID].commandCounter = 0;
}, 5 * 60 * 1000); /* In ms; 5 min */
//Check if a group/person need to be freed from prison (if 15 minutes passed) and check reminders
setTimeout(function () {
setInterval(async function () {
const currentDate = new Date();
currentDate.setSeconds(0);
currentDate.setMilliseconds(0);
//Remove users from command rest list
for (let i = 0; i < restPersonsCommandSpam.length; i++) {
const personID = restPersonsCommandSpam[i];
if (usersDict[personID].autoBanned.toString() === currentDate.toString()) {
usersDict[personID].autoBanned = null;
usersDict[personID].commandCounter = 0;
restPersonsCommandSpam.splice(restPersonsCommandSpam.indexOf(personID), 1);
}
}
//Remove groups from filters rest list
for (let i = 0; i < restGroupsFilterSpam.length; i++) {
const chatID = restGroupsFilterSpam[i];
if (groupsDict[chatID].autoBanned.toString() === currentDate.toString()) {
groupsDict[chatID].autoBanned = null;
groupsDict[chatID].filterCounter = 0;
restGroupsFilterSpam.splice(restGroupsFilterSpam.indexOf(chatID), 1);
}
}
//Check reminders
await HR.checkReminders(client, groupsDict, chatsWithReminders, currentDate);
}, 60 * 1000); /* In ms; 1 min */
}, 60000 - (new Date().getTime() % 60000)); /* to make it run at the start of every minute */
//Send a message to the original chat cause of a stupid bug not letting the bot reply to messages before it sent a regular message
client.sendText(apiKeys.originalGroup, "Bot started successfully at " + new Date().toString());
//Send a starting help message when the bot is added to a group
client.onAddedToGroup(async (chat: Chat) => {
await HL.sendStartMessage(client, chat.id);
});
//Check every command each time a message is received
client.onMessage(async (message: Message) => {
if (message !== null) {
//Initialize basic message properties: its ID, the ID of its sender and the ID of the chat it was sent in
const chatID: ChatId = message.chat.id,
authorID: ContactId = message.sender.id,
messageID: MessageId = message.id;
//Define quotedMsgID properties depending on if a message was quoted
const quotedMsgID: MessageId = message.quotedMsg ? message.quotedMsg.id : message.id;
//Define bodyText depending on if the message a text message or a media message
let bodyText: string =
message.type === "image" || message.type === "video" ? message.caption : message.text;
bodyText = bodyText === undefined || bodyText === null || bodyText === "" ? message.text : bodyText;
//Boolean to check if commands were used to maximize performance
let checkCommands: boolean = true;
//Boolean to check if a filter altering command was used and if not check if the message contains filters
let checkFilters: boolean = true;
//Create new group/person if they don't exist in the DB
if (!(chatID in groupsDict))
groupsDict[chatID] = new Group(chatID);
if (!(authorID in usersDict))
usersDict[authorID] = new Person(authorID);
//Add author to group's DB if not already in it
if (!(groupsDict[chatID].personsIn.some(person => authorID === person.personID))) {
await HDB.addArgsToDB(chatID, authorID, null, null, "personIn", function () {
// @ts-ignore
groupsDict[chatID].personsIn = ["add", usersDict[authorID]];
});
}
//Update group admins if they don't exist
if (groupsDict[chatID].groupAdmins.length === 0)
await HP.updateGroupAdmins(client, chatID, groupsDict);
//If the author lacks a permission level give them one
if (!(chatID in usersDict[authorID].permissionLevel))
await HP.autoAssignPersonPermissions(groupsDict[chatID], usersDict[authorID], chatID);
//Handle bot developer functions if the author is a dev
if (botDevs.includes(authorID) || usersDict[authorID].permissionLevel[chatID] === 3)
checkCommands = await HandleAdminFunctions(client, message, bodyText, chatID, authorID, messageID);
//Log messages with tags for later use in HT.whichMessagesTaggedIn()
await HT.logMessagesWithTags(client, message, bodyText, chatID, messageID, usersDict, groupsDict, afkPersons);
//Remove a person from afk
if (afkPersons.includes(authorID) && !((await HL.getGroupLang(groupsDict, chatID, "afk_me_pwease")).test(bodyText)))
await HAFK.afkOff(client, chatID, messageID, authorID, groupsDict, usersDict, afkPersons);
//If the group the message was sent in isn't blocked, check for commands
if (!restGroups.includes(chatID)) {
//If the user who sent the message isn't blocked, check for commands
if (!restPersons.includes(authorID) && !restPersonsCommandSpam.includes(authorID)) {
//Check all functions for commands if the user has a high enough permission level to use them
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["tags"])
checkCommands = await Tags(client, bodyText, chatID, authorID, messageID, quotedMsgID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["handleOther"] && checkCommands)
checkCommands = await HandleImmediate(client, message, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["handleShows"] && checkCommands)
checkCommands = await HandleShows(client, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["handleFilters"] && checkCommands)
[checkCommands, checkFilters] = await HandleFilters(client, message, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["handleTags"] && checkCommands)
checkCommands = await HandleTags(client, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["HandleReminders"] && checkCommands)
checkCommands = await HandleReminders(client, message, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["handleBirthdays"] && checkCommands)
checkCommands = await HandleBirthdays(client, bodyText, chatID, authorID, messageID);
if (usersDict[authorID].permissionLevel[chatID] >= 2 && checkCommands)
await HandlePermissions(client, bodyText, chatID, authorID, messageID);
//If the user used too many commands, put them on a cool down
if (usersDict[authorID].commandCounter === 14) {
let bannedDate = new Date();
bannedDate.setMinutes(bannedDate.getMinutes() + 15);
bannedDate.setSeconds(0);
bannedDate.setMilliseconds(0);
usersDict[authorID].autoBanned = bannedDate;
restPersonsCommandSpam.push(authorID);
await client.reply(chatID, await HL.getGroupLang(groupsDict, chatID, "command_spam_reply",
bannedDate.getHours().toString(), bannedDate.getMinutes() > 10 ?
bannedDate.getMinutes().toString() : "0" + bannedDate.getMinutes().toString()), messageID);
}
}
//If the group the message was sent in isn't blocked and no filter altering commands were used, check for filters
if (checkFilters && !restGroupsFilterSpam.includes(chatID)
&& usersDict[authorID].permissionLevel[chatID] >= groupsDict[chatID].functionPermissions["filters"])
await HF.checkFilters(client, bodyText, chatID, messageID, groupsDict, 15, restGroupsFilterSpam);
}
} else console.log("ERROR: the message was (somehow) null"); //Shouldn't ever happen
});
}
//Start the bot - get all the groups from mongoDB (cache) and make an instance of every group object in every group
await HDB.getAllGroupsFromDB(groupsDict, usersDict, restPersons, restGroups, chatsWithReminders, afkPersons, async function () {
create(apiKeys.configObj)
.then(client => start(client))
.then(_ => console.log("Bot started successfully at " + new Date().toString()));
});
//TODO: pins
//TODO: add male/female strings
//TODO: website
//TODO: search on ME
//TODO: stock checking
//TODO: send bus stop times
//TODO: chess - Lichess API?
//TODO: XO against John?