This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (73 loc) · 2.24 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
82
83
84
85
86
87
88
89
90
91
require("dotenv").config({ path: __dirname + "/.env" });
const Telegraf = require("telegraf");
const session = require("telegraf/session");
const Stage = require("telegraf/stage");
const { enter, leave } = Stage;
const bot = new Telegraf(process.env.BOT_TOKEN);
// Database
const low = require("lowdb");
const FileSync = require("lowdb/adapters/FileSync");
const adapter = new FileSync(__dirname + "/Database/db.json");
const db = low(adapter);
// Set some defaults (required if your JSON file is empty)
db.defaults({ users: [] }).write();
// App Object
let app = {
db: db,
enter: enter,
leave: leave,
};
//bot.use(Telegraf.log())
require("./Core/canteens.js")(app);
let scene_settings = require("./Scenes/settings.js")(app);
let scene_search = require("./Scenes/search.js")(app);
let scene_canteen_delete = require("./Scenes/canteen_delete.js")(app);
let scene_plan = require("./Scenes/plan.js")(app);
const stage = new Stage(
[scene_settings, scene_search, scene_canteen_delete, scene_plan],
{ ttl: 100 }
);
bot.use(session());
bot.use(stage.middleware());
bot.command("start", (ctx) => {
ctx.reply(
"Willkommen beim Mensa-Bot! Beginne, in dem du /settings aufrufst, um deine Mensa auszuwählen."
);
});
// settings
bot.command("settings", enter("settings"));
// plan
bot.command("today", (ctx) => {
ctx.session.editLast = false;
ctx.scene.enter("plan");
});
bot.action("notes", (ctx) => {
ctx.session.editLast = true;
ctx.session.showNotes = true;
ctx.scene.enter("plan");
});
bot.action("unfiltered", (ctx) => {
ctx.session.editLast = true;
ctx.session.showAll = true;
ctx.scene.enter("plan");
});
bot.action("next_canteen", (ctx) => {
ctx.session.currentCanteen = ctx.session.currentCanteen || 0;
ctx.session.currentCanteen++;
ctx.session.editLast = true;
ctx.session.showNotes = false;
ctx.session.showAll = false;
ctx.scene.enter("plan");
});
bot.action("last_canteen", (ctx) => {
ctx.session.currentCanteen = ctx.session.currentCanteen || 0;
ctx.session.currentCanteen--;
ctx.session.editLast = true;
ctx.session.showNotes = false;
ctx.session.showAll = false;
ctx.scene.enter("plan");
});
bot.on("message", (ctx) =>
ctx.reply("Befehl nicht verstanden. Benutze /settings oder /today")
);
bot.startPolling();