-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (56 loc) · 2.56 KB
/
main.cpp
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
#include <iostream>
#include "config.hpp"
#include "settings.hpp"
#include "UserContext.hpp"
#include "ManagmentBot.hpp"
int main() {
ManagmentBot mBot(bot::token, "service_desk.db3");
database::createDB(mBot.db);
ConversationMap conversations;
// Обработчик команды /start
mBot.bot.getEvents().onCommand("start", [&mBot, &conversations](TgBot::Message::Ptr message) {
mBot.eventStart(conversations, message);
});
// Обработчик команды /view для просмотра заявок по табельному номеру
mBot.bot.getEvents().onCommand("view", [&mBot, &conversations](TgBot::Message::Ptr message) {
mBot.eventView(conversations, message);
});
// Обработчик команды /view_all для просмотра всех заявок
mBot.bot.getEvents().onCommand("view_all", [&mBot, &conversations](TgBot::Message::Ptr message) {
mBot.eventViewAll(conversations, message);
});
// Обработчик команды /add для добавления новой заявки
mBot.bot.getEvents().onCommand("add", [&mBot, &conversations](TgBot::Message::Ptr message) {
mBot.eventAdd(conversations, message);
});
// Обработчик команды /work для взятия в работу заявки
mBot.bot.getEvents().onCommand("work", [&mBot, &conversations](TgBot::Message::Ptr message) {
mBot.eventWork(conversations, message);
});
mBot.bot.getEvents().onNonCommandMessage([&mBot, &conversations](TgBot::Message::Ptr message) {
if (conversations[message->chat->id].currentCommand == "start") {
mBot.activityStart(conversations, message);
}
if (conversations[message->chat->id].currentCommand == "view") {
mBot.activityView(conversations, message);
}
if (conversations[message->chat->id].currentCommand == "add") {
mBot.activityAdd(conversations, message);
}
if (conversations[message->chat->id].currentCommand == "work") {
mBot.activityWork(conversations, message);
}
});
try {
std::cout << "Bot username: " << mBot.bot.getApi().getMe()->username.data() << std::endl;
mBot.bot.getApi().deleteWebhook();
TgBot::TgLongPoll longPoll(mBot.bot);
while (true) {
std::cout << "Long poll started" << std::endl;
longPoll.start();
}
} catch (TgBot::TgException& e) {
std::cerr << "error: " << e.what() << std::endl;
}
return 0;
}