-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.server.js
112 lines (92 loc) · 2.79 KB
/
main.server.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
import fs from 'fs';
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
export default class PersonalStats {
static activitiesStart = {};
static init() {
const activities = JSON.parse(JSON.stringify(config.activities));
activities['Sleep'] = true;
for(const activity in activities) {
if(!activities[activity]) {
continue;
}
const lowerActivity = activity.toLowerCase();
console.log(lowerActivity);
Discord.registerCmd(
lowerActivity,
(c, i) => PersonalStats.startActivity(activity, c, i),
{
description: `Start ${activity} now !`,
}
);
Discord.registerCmd(
'stop' + lowerActivity,
(c, i) => PersonalStats.endActivity(activity, c, i),
{
description: `Stops ${activity} now.`,
}
);
Discord.registerBtn(
lowerActivity + '-restart',
(c, i) => PersonalStats.restartActivity(activity, c, i),
);
Discord.registerBtn(
lowerActivity + '-end',
(c, i) => PersonalStats.endActivity(activity, c, i),
);
}
}
static close() {
}
static restartActivity(activity, discordClient, interaction) {
PersonalStats.startActivity(activity, discordClient, interaction, true);
}
static startActivity(activity, discordClient, interaction, restarted = false) {
const lowerActivity = activity.toLowerCase();
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(lowerActivity + '-restart')
.setLabel('Restart')
.setStyle(ButtonStyle.Danger),
)
.addComponents(
new ButtonBuilder()
.setCustomId(lowerActivity + '-end')
.setLabel('End ' + activity)
.setStyle(ButtonStyle.Primary),
);
PersonalStats.activitiesStart[activity] = new Date();
const verb = restarted ? 'Restarted' : 'Started';
interaction.reply({
content: `${verb} at ${PersonalStats.activitiesStart[activity].toLocaleTimeString(config.locale)}`,
components: [row],
ephemeral: true
})
}
static endActivity(activity, discordClient, interaction) {
if(!PersonalStats.activitiesStart[activity]) {
interaction.reply({
content: `Error: you didn't start to ${activity} !`,
ephemeral: true
})
}
const activityEnd = new Date();
const [query, values] = Database.buildInsertQuery('calendar', {
id: `${activity.toUpperCase()}-${PersonalStats.activitiesStart[activity].toISOString()}`,
title: activity,
description: '',
start: PersonalStats.activitiesStart[activity],
end: activityEnd,
origin: 'Lumen Discord Bot'
});
Database.execQuery(
query,
values
);
interaction.reply({
content: `Did "${activity}" from ${PersonalStats.activitiesStart[activity].toLocaleTimeString(config.locale)} to ${activityEnd.toLocaleTimeString(config.locale)} !`,
ephemeral: true
});
PersonalStats.activitiesStart[activity] = null;
}
}