From 84a70acefa63c74f30e49d25134fb537f32a6412 Mon Sep 17 00:00:00 2001 From: light Date: Sun, 12 Dec 2021 14:31:23 +0500 Subject: [PATCH 1/4] added include file for lib --- include.pri | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include.pri diff --git a/include.pri b/include.pri new file mode 100644 index 0000000..e5f2f1d --- /dev/null +++ b/include.pri @@ -0,0 +1,11 @@ + +HEADERS += \ + $$PWD/src/telegrambot.h \ + $$PWD/modules/httpserver/httpserver.h \ + $$PWD/vendor/qdelegate/include/qdelegate.h + +INCLUDEPATH += $$PWD/src/ +INCLUDEPATH += $$PWD/modules/sslserver/ +INCLUDEPATH += $$PWD/modules/httpserver/ +INCLUDEPATH += $$PWD/vendor/qdelegate/include/ + From ddde9f0b3857489ffc8910ef8f527a96e1a6d125 Mon Sep 17 00:00:00 2001 From: light Date: Mon, 13 Dec 2021 02:15:14 +0500 Subject: [PATCH 2/4] 64 bit identifiers --- src/telegramdatastructs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/telegramdatastructs.h b/src/telegramdatastructs.h index c8e16c9..5023a75 100644 --- a/src/telegramdatastructs.h +++ b/src/telegramdatastructs.h @@ -234,7 +234,7 @@ typedef QList> TelegramKeyboard; // TelegramBotChat - This object represents a chat. struct TelegramBotChat : public TelegramBotObject { - qint32 id; // Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier. + qint64 id; // Unique identifier for this chat. This number from now can be signed 64 bit integer or double-precision float type are safe for storing this identifier. QString type; // Type of chat, can be either “private”, “group”, “supergroup” or “channel” QString title; // Optional. Title, for supergroups, channels and group chats QString username; // Optional. Username, for private chats, supergroups and channels if available @@ -247,7 +247,7 @@ struct TelegramBotChat : public TelegramBotObject { // parse logic virtual void fromJson(QJsonObject& object) { - JsonHelperT::jsonPathGet(object, "id", this->id); + JsonHelperT::jsonPathGet(object, "id", this->id); JsonHelperT::jsonPathGet(object, "type", this->type); JsonHelperT::jsonPathGet(object, "title", this->title, false); JsonHelperT::jsonPathGet(object, "username", this->username, false); From 5921d5ac23ebb0e4de9ada513909729a022ad17a Mon Sep 17 00:00:00 2001 From: light Date: Wed, 5 Jan 2022 21:33:45 +0500 Subject: [PATCH 3/4] fix build Qt 5.15+ --- modules/httpserver/httpserver.cpp | 7 ++++--- src/jsonhelper.cpp | 2 +- src/telegrambot.cpp | 2 -- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/httpserver/httpserver.cpp b/modules/httpserver/httpserver.cpp index 82978e3..9a64913 100644 --- a/modules/httpserver/httpserver.cpp +++ b/modules/httpserver/httpserver.cpp @@ -46,14 +46,15 @@ void HttpServer::handleNewData() // build response QByteArray responseContent; - responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version) + " "; // Version - responseContent += QByteArray::number((qint32)response->status) + " " + response->StatusNames.value((qint32)response->status, "") + "\r\n"; // Status + responseContent += (response->version.isEmpty() ? "HTTP/1.1" : response->version.toUtf8()) + " "; // Version + responseContent += QByteArray::number((qint32)response->status) + " " + + response->StatusNames.value((qint32)response->status, "").toUtf8() + "\r\n"; // Status // add headers qint64 contentLength = 0; for(auto itr = response->headers.begin(); itr != response->headers.end(); itr++) { if(itr.key().toLower() == "content-length") contentLength = itr.value().toLongLong(); - responseContent += itr.key() + ": " + itr.value() + "\r\n"; + responseContent += itr.key().toUtf8() + ": " + itr.value().toUtf8() + "\r\n"; } // add content length if not available diff --git a/src/jsonhelper.cpp b/src/jsonhelper.cpp index c8352b0..643d7a8 100644 --- a/src/jsonhelper.cpp +++ b/src/jsonhelper.cpp @@ -3,7 +3,7 @@ QVariant JsonHelper::jsonPathGetImpl(QJsonValue data, QString path, bool showWarnings) { // json parse - QStringList splittedPath = path.split('.', QString::SkipEmptyParts); + QStringList splittedPath = path.split('.'); QStringList processed; while(!splittedPath.isEmpty()) { QString pathElement = splittedPath.takeFirst(); diff --git a/src/telegrambot.cpp b/src/telegrambot.cpp index a5df7a1..40ec79c 100644 --- a/src/telegrambot.cpp +++ b/src/telegrambot.cpp @@ -754,8 +754,6 @@ QNetworkReply* TelegramBot::callApi(QString method, QUrlQuery params, bool delet QUrl url(QString("https://api.telegram.org/bot%1/%2").arg(this->apiKey, method)); url.setQuery(params); - qDebug() << url; - // execute QNetworkRequest request(url); QNetworkReply* reply = multiPart ? this->aManager.post(request, multiPart) : this->aManager.get(request); From f73a259ad7502e0f7e5eba065596c00ce921784f Mon Sep 17 00:00:00 2001 From: light Date: Thu, 6 Jan 2022 04:16:52 +0500 Subject: [PATCH 4/4] name corrections and defaults --- src/telegrambot.cpp | 30 +++++++++++++++--------------- src/telegrambot.h | 2 +- src/telegramdatastructs.h | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/telegrambot.cpp b/src/telegrambot.cpp index 40ec79c..d0123bf 100644 --- a/src/telegrambot.cpp +++ b/src/telegrambot.cpp @@ -207,7 +207,7 @@ void TelegramBot::sendMessage(QVariant chatId, QString text, int replyToMessageI if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api return this->callApiTemplate("sendMessage", params, response); @@ -233,7 +233,7 @@ void TelegramBot::editMessageText(QVariant chatId, QVariant messageId, QString t // only build inline keyboard if(!(flags && TelegramFlags::ReplyKeyboardMarkup) && !(flags && TelegramFlags::ForceReply) && !(flags && TelegramFlags::ReplyKeyboardRemove)) { - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); } // call api @@ -251,7 +251,7 @@ void TelegramBot::editMessageCaption(QVariant chatId, QVariant messageId, QStrin if(!caption.isNull()) params.addQueryItem("caption", caption); // only build inline keyboard - this->hanldeReplyMarkup(params, TelegramFlags(), keyboard); + this->handleReplyMarkup(params, TelegramFlags(), keyboard); // call api this->callApiTemplate("editMessageCaption", params, response); @@ -267,7 +267,7 @@ void TelegramBot::editMessageReplyMarkup(QVariant chatId, QVariant messageId, Te params.addQueryItem(isInlineMessageId ? "inline_message_id" : "message_id", messageId.toString()); // only build inline keyboard - this->hanldeReplyMarkup(params, TelegramFlags(), keyboard); + this->handleReplyMarkup(params, TelegramFlags(), keyboard); // call api this->callApiTemplate("editMessageReplyMarkup", params, response); @@ -305,7 +305,7 @@ void TelegramBot::sendPhoto(QVariant chatId, QVariant photo, QString caption, in if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("photo", photo, params); @@ -326,7 +326,7 @@ void TelegramBot::sendAudio(QVariant chatId, QVariant audio, QString caption, QS if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("audio", audio, params); @@ -344,7 +344,7 @@ void TelegramBot::sendDocument(QVariant chatId, QVariant document, QString capti if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("document", document, params); @@ -361,7 +361,7 @@ void TelegramBot::sendSticker(QVariant chatId, QVariant sticker, int replyToMess if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("sticker", sticker, params); @@ -382,7 +382,7 @@ void TelegramBot::sendVideo(QVariant chatId, QVariant video, QString caption, in if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("video", video, params); @@ -401,7 +401,7 @@ void TelegramBot::sendVoice(QVariant chatId, QVariant voice, QString caption, in if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("voice", voice, params); @@ -420,7 +420,7 @@ void TelegramBot::sendVideoNote(QVariant chatId, QVariant videoNote, int length, if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // handle file QHttpMultiPart* multiPart = this->handleFile("video_note", videoNote, params); @@ -439,7 +439,7 @@ void TelegramBot::sendLocation(QVariant chatId, double latitude, double longitud if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendLocation", params, response); @@ -458,7 +458,7 @@ void TelegramBot::sendVenue(QVariant chatId, double latitude, double longitude, if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendVenue", params, response); @@ -475,7 +475,7 @@ void TelegramBot::sendContact(QVariant chatId, QString phoneNumber, QString firs if(replyToMessageId) params.addQueryItem("reply_to_message_id", QString::number(replyToMessageId)); // handle reply markup - this->hanldeReplyMarkup(params, flags, keyboard); + this->handleReplyMarkup(params, flags, keyboard); // call api this->callApiTemplate("sendContact", params, response); @@ -791,7 +791,7 @@ QHttpMultiPart* TelegramBot::createUploadFile(QString name, QString fileName, QB return multiPart; } -void TelegramBot::hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard) +void TelegramBot::handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest &keyboard) { // handle types QString replyMarkup; diff --git a/src/telegrambot.h b/src/telegrambot.h index 2627511..00d3fbc 100644 --- a/src/telegrambot.h +++ b/src/telegrambot.h @@ -164,7 +164,7 @@ class TelegramBot : public QObject // helpers QHttpMultiPart* createUploadFile(QString name, QString fileName, QByteArray& content, bool detectMimeType = false, QHttpMultiPart* multiPart = 0); - void hanldeReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard); + void handleReplyMarkup(QUrlQuery& params, TelegramFlags flags, TelegramKeyboardRequest& keyboard); QHttpMultiPart* handleFile(QString fieldName, QVariant file, QUrlQuery& params, QHttpMultiPart* multiPart = 0); // global data diff --git a/src/telegramdatastructs.h b/src/telegramdatastructs.h index 5023a75..71fa073 100644 --- a/src/telegramdatastructs.h +++ b/src/telegramdatastructs.h @@ -18,8 +18,8 @@ QString switchInlineQueryCurrentChat; \ \ /* normal keyboard */ \ - bool requestContact; \ - bool requestLocation; + bool requestContact = false; \ + bool requestLocation = false; struct TelegramBotKeyboardButtonRequest {