summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-08-30 00:25:15 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-08-30 00:25:15 +0200
commit76a362631705d9adcc2709e6d8f9b327112ae306 (patch)
treefb14421e54a844bb9b698b5049339323085de343 /src
parented5065b35911a6d7d3dff30bd80600cc593901a3 (diff)
Update to API 4.7
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp64
-rw-r--r--src/TgTypeParser.cpp73
2 files changed, 123 insertions, 14 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index f1a1065..22115c2 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -320,19 +320,28 @@ File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSt
return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args));
}
-bool Api::createNewStickerSet(std::int64_t userId, const string& name, const string& title, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
+bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, const std::string& emojis,
+ boost::variant<InputFile::Ptr, std::string> pngSticker, boost::variant<InputFile::Ptr, std::string> tgsSticker,
+ bool containsMasks, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.reserve(7);
+ args.reserve(8);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
args.emplace_back("title", title);
+ args.emplace_back("emojis", emojis);
+
if (pngSticker.which() == 0 /* InputFile::Ptr */) {
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
} else /* std::string */ {
args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
}
- args.emplace_back("emojis", emojis);
+ if (tgsSticker.which() == 0 /* InputFile::Ptr */) {
+ auto file = boost::get<InputFile::Ptr>(tgsSticker);
+ args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName);
+ } else /* std::string */ {
+ args.emplace_back("tgs_sticker", boost::get<std::string>(tgsSticker));
+ }
if (containsMasks) {
args.emplace_back("contains_mask", containsMasks);
}
@@ -342,18 +351,27 @@ bool Api::createNewStickerSet(std::int64_t userId, const string& name, const str
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
-bool Api::addStickerToSet(std::int64_t userId, const string& name, boost::variant<InputFile::Ptr, std::string> pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
+bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis,
+ boost::variant<InputFile::Ptr, std::string> pngSticker, boost::variant<InputFile::Ptr, std::string> tgsSticker,
+ MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
args.reserve(6);
args.emplace_back("user_id", userId);
args.emplace_back("name", name);
+ args.emplace_back("emojis", emojis);
+
if (pngSticker.which() == 0 /* InputFile::Ptr */) {
auto file = boost::get<InputFile::Ptr>(pngSticker);
args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName);
} else /* std::string */ {
args.emplace_back("png_sticker", boost::get<std::string>(pngSticker));
}
- args.emplace_back("emojis", emojis);
+ if (tgsSticker.which() == 0 /* InputFile::Ptr */) {
+ auto file = boost::get<InputFile::Ptr>(tgsSticker);
+ args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName);
+ } else /* std::string */ {
+ args.emplace_back("tgs_sticker", boost::get<std::string>(tgsSticker));
+ }
if (maskPosition != nullptr) {
args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition));
}
@@ -375,6 +393,20 @@ bool Api::deleteStickerFromSet(const string& sticker) const {
return sendRequest("deleteStickerFromSet", args).get<bool>("", false);
}
+bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant<InputFile::Ptr, std::string> thumb) const {
+ vector<HttpReqArg> args;
+ args.reserve(3);
+ args.emplace_back("name", name);
+ args.emplace_back("user_id", userId);
+ if (thumb.which() == 0 /* InputFile::Ptr */) {
+ auto file = boost::get<InputFile::Ptr>(thumb);
+ args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName);
+ } else /* std::string */ {
+ args.emplace_back("thumb", boost::get<std::string>(thumb));
+ }
+ return sendRequest("setStickerSetThumb", args).get<bool>("", false);
+}
+
Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant<InputFile::Ptr, std::string> video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant<InputFile::Ptr, std::string> thumb, const string &caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
args.reserve(12);
@@ -1194,6 +1226,24 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con
return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args));
}
+Message::Ptr Api::sendDice(std::int64_t chatId, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const {
+ vector<HttpReqArg> args;
+ args.reserve(4);
+ args.emplace_back("chat_id", chatId);
+
+ if (disableNotification) {
+ args.emplace_back("disable_notification", disableNotification);
+ }
+ if (replyToMessageId != 0) {
+ args.emplace_back("reply_to_message_id", replyToMessageId);
+ }
+ if (replyMarkup) {
+ args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
+ }
+
+ return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args));
+}
+
Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
args.reserve(3);
@@ -1206,7 +1256,6 @@ Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const Inlin
}
bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands) const {
-
vector<HttpReqArg> args;
args.reserve(5);
@@ -1216,8 +1265,7 @@ bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands) const {
return sendRequest("setMyCommands",args).get<bool>("",false);
}
-std::vector<BotCommand::Ptr> Api::getMyCommands() const
-{
+std::vector<BotCommand::Ptr> Api::getMyCommands() const {
return _tgTypeParser.parseJsonAndGetArray<BotCommand>(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands"));
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 4528d62..37dafb6 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -148,6 +148,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
result->forwardDate = data.get("forward_date", 0);
result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message");
result->editDate = data.get<int32_t>("edit_date", 0);
+ result->mediaGroupId = data.get("media_group_id", "");
result->authorSignature = data.get("author_signature", "");
result->text = data.get("text", "");
result->entities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities");
@@ -160,17 +161,20 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker");
result->video = tryParseJson<Video>(&TgTypeParser::parseJsonAndGetVideo, data, "video");
result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice");
+ result->videoNote = tryParseJson<VideoNote>(&TgTypeParser::parseJsonAndGetVideoNote, data, "video_note");
+ result->caption = data.get("caption", "");
result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact");
result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->venue = tryParseJson<Venue>(&TgTypeParser::parseJsonAndGetVenue, data, "venue");
result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll");
- result->newChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant");
+ result->dice = tryParseJson<Dice>(&TgTypeParser::parseJsonAndGetDice, data, "dice");
+ result->newChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_member");
result->newChatMembers = parseJsonAndGetArray<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_members");
- result->leftChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_participant");
+ result->leftChatMember = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_member");
result->newChatTitle = data.get("new_chat_title", "");
result->newChatPhoto = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "new_chat_photo");
result->deleteChatPhoto = data.get("delete_chat_photo", false);
result->groupChatCreated = data.get("group_chat_created", false);
- result->caption = data.get("caption", "");
result->supergroupChatCreated = data.get("supergroup_chat_created", false);
result->channelChatCreated = data.get("channel_chat_created", false);
result->migrateToChatId = data.get<int64_t>("migrate_to_chat_id", 0);
@@ -179,8 +183,10 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
result->invoice = tryParseJson<Invoice>(&TgTypeParser::parseJsonAndGetInvoice, data, "invoice");
result->successfulPayment = tryParseJson<SuccessfulPayment>(&TgTypeParser::parseJsonAndGetSuccessfulPayment, data, "successful_payment");
result->connectedWebsite = data.get("connected_website", "");
+ // result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
result->replyMarkup = tryParseJson<InlineKeyboardMarkup>(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup");
result->automaticForward = data.get("is_automatic_forward", false);
+
return result;
}
@@ -202,18 +208,26 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "forward_date", object->forwardDate);
appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage));
appendToJson(result, "edit_date", object->editDate);
+ appendToJson(result, "media_group_id", object->mediaGroupId);
appendToJson(result, "author_signature", object->authorSignature);
appendToJson(result, "text", object->text);
+ appendToJson(result, "entities", parseArray(&TgTypeParser::parseMessageEntity, object->entities));
+ appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
appendToJson(result, "audio", parseAudio(object->audio));
appendToJson(result, "document", parseDocument(object->document));
appendToJson(result, "animation", parseAnimation(object->animation));
+ appendToJson(result, "game", parseGame(object->game));
appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo));
appendToJson(result, "sticker", parseSticker(object->sticker));
appendToJson(result, "video", parseVideo(object->video));
appendToJson(result, "voice", parseVoice(object->voice));
+ appendToJson(result, "video_note", parseVideoNote(object->videoNote));
+ appendToJson(result, "caption", object->caption);
appendToJson(result, "contact", parseContact(object->contact));
appendToJson(result, "location", parseLocation(object->location));
+ appendToJson(result, "venue", parseVenue(object->venue));
appendToJson(result, "poll", parsePoll(object->poll));
+ appendToJson(result, "dice", parseDice(object->dice));
appendToJson(result, "new_chat_member", parseUser(object->newChatMember));
appendToJson(result, "new_chat_members", parseArray(&TgTypeParser::parseUser, object->newChatMembers));
appendToJson(result, "left_chat_member", parseUser(object->leftChatMember));
@@ -221,15 +235,15 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "new_chat_photo", parseArray(&TgTypeParser::parsePhotoSize, object->newChatPhoto));
appendToJson(result, "delete_chat_photo", object->deleteChatPhoto);
appendToJson(result, "group_chat_created", object->groupChatCreated);
- appendToJson(result, "caption", object->caption);
appendToJson(result, "supergroup_chat_created", object->supergroupChatCreated);
appendToJson(result, "channel_chat_created", object->channelChatCreated);
appendToJson(result, "migrate_to_chat_id", object->migrateToChatId);
appendToJson(result, "migrate_from_chat_id", object->migrateFromChatId);
appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage));
- appendToJson(result, "connected_website", object->connectedWebsite);
appendToJson(result, "invoice", parseInvoice(object->invoice));
appendToJson(result, "successful_payment", parseSuccessfulPayment(object->successfulPayment));
+ appendToJson(result, "connected_website", object->connectedWebsite);
+ // appendToJson(result, "passport_data", parsePassportData(object->passportData));
appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup));
removeLastComma(result);
result += '}';
@@ -362,9 +376,10 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const ptree& data) const
auto result(make_shared<StickerSet>());
result->name = data.get("name", "");
result->title = data.get("title", "");
- result->containsMasks = data.get<bool>("contains_masks", false);
result->isAnimated = data.get<bool>("is_animated", false);
+ result->containsMasks = data.get<bool>("contains_masks", false);
result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers");
+ result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb");
return result;
}
@@ -379,6 +394,7 @@ string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const {
appendToJson(result, "is_animated", object->isAnimated);
appendToJson(result, "contains_masks", object->containsMasks);
appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers));
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
removeLastComma(result);
result += '}';
return result;
@@ -442,6 +458,24 @@ string TgTypeParser::parsePoll(const Poll::Ptr& object) const {
return result;
}
+Dice::Ptr TgTypeParser::parseJsonAndGetDice(const ptree& data) const {
+ auto result(make_shared<Dice>());
+ result->value = data.get("value", 0);
+ return result;
+}
+
+string TgTypeParser::parseDice(const Dice::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "value", object->value);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
PollAnswer::Ptr TgTypeParser::parseJsonAndGetPollAnswer(const ptree& data) const {
auto result(make_shared<PollAnswer>());
result->pollId = data.get("poll_id", "");
@@ -737,6 +771,33 @@ string TgTypeParser::parseLocation(const Location::Ptr& object) const {
return result;
}
+Venue::Ptr TgTypeParser::parseJsonAndGetVenue(const ptree& data) const {
+ auto result(make_shared<Venue>());
+ result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->title = data.get<string>("title", "");
+ result->address = data.get<string>("address", "");
+ result->foursquareId = data.get<string>("foursquare_id", "");
+ result->foursquareType = data.get<string>("foursquare_type", "");
+
+ return result;
+}
+
+string TgTypeParser::parseVenue(const Venue::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "location", parseLocation(object->location));
+ appendToJson(result, "title", object->title);
+ appendToJson(result, "address", object->address);
+ appendToJson(result, "foursquare_id", object->foursquareId);
+ appendToJson(result, "foursquare_type", object->foursquareType);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const {
auto result(make_shared<Update>());
result->updateId = data.get<int32_t>("update_id");