Add internalLinkTypeGame.

This commit is contained in:
levlam 2021-05-30 03:46:06 +03:00
parent 1eb62acc07
commit 27369944a7
4 changed files with 65 additions and 11 deletions

View File

@ -3019,6 +3019,10 @@ internalLinkTypeBotStartInGroup bot_username:string start_parameter:string = Int
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
internalLinkTypeChatInvite = InternalLinkType;
//@description The link is a link to a game. Call searchPublicChat with the given bot username, check that the user is a bot, ask the current user to select a group to send the game, and then call sendMessage with inputMessageGame
//@bot_username Username of the bot that owns the game @game_short_name Short name of the game
internalLinkTypeGame bot_username:string game_short_name:string = InternalLinkType;
//@description The link is a link to a language pack. Call getLanguagePackInfo with the given language pack identifier to process the link @language_pack_id Language pack identifier
internalLinkTypeLanguagePack language_pack_id:string = InternalLinkType;

View File

@ -89,7 +89,7 @@ class LinkManager::InternalLinkBotStartInGroup : public InternalLink {
}
InternalLinkType get_type() const final {
return InternalLinkType::BotStart;
return InternalLinkType::BotStartInGroup;
}
public:
@ -126,6 +126,24 @@ class LinkManager::InternalLinkDialogInvite : public InternalLink {
}
};
class LinkManager::InternalLinkGame : public InternalLink {
string bot_username_;
string game_short_name_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeGame>(bot_username_, game_short_name_);
}
InternalLinkType get_type() const final {
return InternalLinkType::Game;
}
public:
InternalLinkGame(string bot_username, string game_short_name)
: bot_username_(std::move(bot_username)), game_short_name_(std::move(game_short_name)) {
}
};
class LinkManager::InternalLinkLanguage : public InternalLink {
string language_pack_id_;
@ -598,23 +616,27 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (path.size() == 1 && path[0] == "resolve") {
if (has_arg("domain")) {
if (has_arg("post")) {
// resolve?domain=username&post=12345&single
// resolve?domain=<username>&post=12345&single
return td::make_unique<InternalLinkMessage>();
}
for (auto &arg : url_query.args_) {
if (arg.first == "voicechat") {
// resolve?domain=username&voicechat
// resolve?domain=username&voicechat=<invite_hash>
// resolve?domain=<username>&voicechat
// resolve?domain=<username>&voicechat=<invite_hash>
return td::make_unique<InternalLinkVoiceChat>(get_arg("domain"), arg.second);
}
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
// /<bot_username>?start=<parameter>
// resolve?domain=<bot_username>?start=<parameter>
return td::make_unique<InternalLinkBotStart>(get_arg("domain"), arg.second);
}
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
// /<bot_username>?startgroup=<parameter>
// resolve?domain=<bot_username>?startgroup=<parameter>
return td::make_unique<InternalLinkBotStartInGroup>(get_arg("domain"), arg.second);
}
if (arg.first == "game" && !arg.second.empty()) {
// resolve?domain=<bot_username>?game=<short_name>
return td::make_unique<InternalLinkGame>(get_arg("domain"), arg.second);
}
}
}
} else if (path.size() == 1 && path[0] == "login") {
@ -622,27 +644,27 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("code")) {
return td::make_unique<InternalLinkAuthenticationCode>(get_arg("code"));
}
// login?token=abacaba
// login?token=<token>
if (has_arg("token")) {
return td::make_unique<InternalLinkQrCodeAuthentication>();
}
} else if (path.size() == 1 && path[0] == "join") {
// join?invite=abcdef
// join?invite=<hash>
if (has_arg("invite")) {
return td::make_unique<InternalLinkDialogInvite>();
}
} else if (path.size() == 1 && path[0] == "addstickers") {
// addstickers?set=name
// addstickers?set=<name>
if (has_arg("set")) {
return td::make_unique<InternalLinkStickerSet>(get_arg("set"));
}
} else if (path.size() == 1 && path[0] == "setlanguage") {
// setlanguage?lang=name
// setlanguage?lang=<name>
if (has_arg("lang")) {
return td::make_unique<InternalLinkLanguage>(get_arg("lang"));
}
} else if (path.size() == 1 && path[0] == "addtheme") {
// addtheme?slug=name
// addtheme?slug=<name>
if (has_arg("slug")) {
return td::make_unique<InternalLinkTheme>(get_arg("slug"));
}
@ -816,6 +838,10 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /<bot_username>?startgroup=<parameter>
return td::make_unique<InternalLinkBotStartInGroup>(path[0], arg.second);
}
if (arg.first == "game" && !arg.second.empty()) {
// /<bot_username>?game=<short_name>
return td::make_unique<InternalLinkGame>(path[0], arg.second);
}
}
}
}

View File

@ -41,6 +41,7 @@ class LinkManager : public Actor {
BotStartInGroup,
ConfirmPhone,
DialogInvite,
Game,
Language,
Message,
MessageDraft,
@ -96,6 +97,7 @@ class LinkManager : public Actor {
class InternalLinkBotStartInGroup;
class InternalLinkConfirmPhone;
class InternalLinkDialogInvite;
class InternalLinkGame;
class InternalLinkLanguage;
class InternalLinkMessage;
class InternalLinkMessageDraft;

View File

@ -78,6 +78,9 @@ TEST(Link, parse_internal_link) {
auto chat_invite = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
};
auto game = [](td::string bot_username, td::string game_short_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeGame>(bot_username, game_short_name);
};
auto language_pack = [](td::string language_pack_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeLanguagePack>(language_pack_name);
};
@ -491,4 +494,23 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/username#startgroup=asdas", nullptr);
parse_internal_link("t.me//username?startgroup=", nullptr);
parse_internal_link("https://telegram.dog/tele%63ram?startgroup=t%63st", bot_start_in_group("telecram", "tcst"));
parse_internal_link("tg:resolve?domain=username&game=aasdasd", game("username", "aasdasd"));
parse_internal_link("TG://resolve?domain=username&game=", unknown_deep_link());
parse_internal_link("TG://test@resolve?domain=username&game=asd", nullptr);
parse_internal_link("tg:resolve:80?domain=username&game=asd", nullptr);
parse_internal_link("tg:http://resolve?domain=username&game=asd", nullptr);
parse_internal_link("tg:https://resolve?domain=username&game=asd", nullptr);
parse_internal_link("tg:resolve?domain=&game=asd", unknown_deep_link());
parse_internal_link("tg:resolve?domain=telegram&&&&&&&game=%30", game("telegram", "0"));
parse_internal_link("t.me/username/0/a//s/as?game=asd", game("username", "asd"));
parse_internal_link("t.me/username/aasdas?test=1&game=asd#12312", game("username", "asd"));
parse_internal_link("t.me/username/0?game=asd", game("username", "asd"));
parse_internal_link("t.me/username/-1?game=asdasd", game("username", "asdasd"));
parse_internal_link("t.me/username?game=asd", game("username", "asd"));
parse_internal_link("t.me/username?game=", nullptr);
parse_internal_link("t.me/username#game=asdas", nullptr);
parse_internal_link("t.me//username?game=asd", nullptr);
parse_internal_link("https://telegram.dog/tele%63ram?game=t%63st", game("telecram", "tcst"));
}