-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
82 lines (67 loc) · 2.63 KB
/
index.js
File metadata and controls
82 lines (67 loc) · 2.63 KB
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
const Discord = require('discord.js');
const bot = new Discord.Client();
const DBConnector = require('./dbconnector');
const CreateEvent = require('./createevent');
const SeeEvents = require('./seeevents');
const Join = require('./join');
const Quit = require('./quit');
const See = require('./see');
const Delete = require('./deleteevent');
const MyEvents = require('./myevents');
const Help = require('./help');
const Variable = require('./variable');
bot.login(Variable.GetToken());
var BreakException = {};
Number.prototype.pad = function (width) {
width -= this.toString().length;
if (width > 0) {
return new Array(width + (/\./.test(this) ? 2 : 1)).join('0') + this;
}
return this + "";
}
bot.on('message', function (message) {
if (message.author != bot.user) { }
let data = CreateEvent.UseCommands(message) ||
SeeEvents.UseCommands(message) ||
Join.UseCommands(message) ||
Quit.UseCommands(message) ||
See.UseCommands(message) ||
Delete.UseCommands(message) ||
MyEvents.UseCommands(message) ||
Help.UseCommands(message);
})
setInterval(function () {
let date = new Date();
DBConnector.GetUsersToAlert(date, function (rows) {
rows.forEach((row) => {
let dateEvent = new Date(row.date * 1);
let diff = dateEvent - date;
let channel = bot.channels.get(row.dmId);
if (!channel) {
try {
bot.guilds.forEach((guild) => {
channel = guild.members.get(row.userId);
if (channel) {
throw BreakException;
}
});
} catch (e) {
if (e !== BreakException) throw e;
}
}
if (diff < 1000 * 60 * 60 * 36 && row.alertId < 4) {
channel.send("L'évènement " + row.id + " se déroule dans moins de 36h");
DBConnector.SetAlertID(row.userId, row.id, 4);
} else if (diff < 1000 * 60 * 60 * 24 * 3 && row.alertId < 3) {
channel.send("L'évènement " + row.id + " se déroule dans moins de 3 jours");
DBConnector.SetAlertID(row.userId, row.id, 3);
} else if (diff < 1000 * 60 * 60 * 24 * 7 && row.alertId < 2) {
channel.send("L'évènement " + row.id + " se déroule dans moins d'une semaine");
DBConnector.SetAlertID(row.userId, row.id, 2);
}
});
});
}, 1000 * 60 * 60 * 12);
//cluster par guilds
//delete avec alerte de delete + cascade ?
//pm2 pour start