-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
81 lines (68 loc) · 1.77 KB
/
index.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
const { Telegraf, Markup } = require("telegraf");
const fs = require("fs");
const Menu = require("./Menu");
const image = new (require("./Image"))("./image/template.svg", "");
const storage = new (require("./Storage"))("./data.json");
var menu = new Menu(
"Bienvenue, veuillez indiquer votre présence physique à l'EPFL"
);
require("dotenv").config();
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.start(async (ctx) => {
ctx.reply("Bienvenue, utilisez la commande /menu pour afficher le menu");
});
bot.command("menu", (ctx) => {
return menu.sendMenu(ctx);
});
bot.on("callback_query", async (ctx) => {
var callback_queryData = JSON.parse(ctx.update.callback_query.data);
switch (callback_queryData.action) {
case "goToPage":
try {
menu.goToPage(callback_queryData.data, ctx);
} catch (error) {
}
break;
case "goToWeek":
var userId = ctx.update.callback_query.from.id;
var data = callback_queryData.data;
try {
menu.sendWeekDays(data, storage, ctx);
} catch (error) {
}
break;
case "togglePresence":
var userId = ctx.update.callback_query.from.id;
var data = callback_queryData.data;
let tmpWeekObj = {
year: data[0],
week: data[1],
perPage: 4,
};
let presenceState = storage.getPresence(
data[0],
data[1],
userId,
data[2],
data[3]
)
? false
: true;
storage.setPresence(
data[0],
data[1],
userId,
data[2],
data[3],
presenceState
);
try {
menu.sendWeekDays(tmpWeekObj, storage, ctx);
} catch (error) {
}
break;
default:
break;
}
});
bot.launch();