SecretService 0.13.2d47dfe
SecretService is base back end library for your c++ Qt projects.
yourtimebot.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2023-2023 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "yourtimebot.h"
9
10#include <qTbot/messages/telegramupdate.h>
11
12#include <QCoreApplication>
13#include <locales.h>
14
15YourTimeBot::YourTimeBot(const QSharedPointer<YourTimeDeliviry::IDataBase> &db) {
16 _db = db;
17
18 connect(this, &YourTimeBot::sigReceiveUpdate, this, &YourTimeBot::handleIncomeNewUpdate);
19}
20
21bool YourTimeBot::login(const QByteArray &token) {
22
23 if (!_db)
24 return false;
25
26 setProcessed(_db->getProcessedIds());
27
28
29 if(!QuasarAppUtils::Locales::init( {QLocale::English,
30 QLocale::Russian,
31 QLocale::Ukrainian,
32 QLocale::Serbian}, {
33 ":/YourTime/languages/"
34 }
35 )){
36 return false;
37 }
38
39 return qTbot::TelegramRestBot::login(token);
40}
41
42void YourTimeBot::handleIncomeNewUpdate(const QSharedPointer<qTbot::iUpdate> &update) {
43
44 if (auto&& tupdate = update.dynamicCast<qTbot::TelegramUpdate>()) {
45 if (tupdate->contains(tupdate->MessageUpdate)) {
46 auto mesg = tupdate->message();
47 if (mesg->text() == "/start") {
48
49 sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("This bot is still under development.",
50 QLocale(mesg->languageCode())));
51 QCoreApplication::processEvents();
52
53 sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("We are working very hard on our new delivery service to make it as easy as possible for you to be with us wherever you are.",
54 QLocale(mesg->languageCode())));
55 QCoreApplication::processEvents();
56
57
58 sendMessage(mesg->chatId(), QuasarAppUtils::Locales::tr("Thank you for your wait.",
59 QLocale(mesg->languageCode())));
60
61 }
62 }
63 }
64
65 markUpdateAsProcessed(update);
66 _db->addProcessedId(update->updateId());
67}
bool login(const QByteArray &token) override
void handleIncomeNewUpdate(const QSharedPointer< qTbot::iUpdate > &update) override
YourTimeBot(const QSharedPointer< YourTimeDeliviry::IDataBase > &db)