From dcfa198c8cca94eda02d1a34d9601e5bc65eff58 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 7 Feb 2020 00:25:24 +0600 Subject: [PATCH] send game and other extensions --- .../requests/games/SetGameScoreByChatId.kt | 69 +++++++++++++++++++ .../requests/send/games/SendGame.kt | 47 ++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt index 7cb00e4dc8..36c157a8ec 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt @@ -1,8 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.GameContent import kotlinx.serialization.* @Serializable @@ -23,3 +27,68 @@ data class SetGameScoreByChatId ( override val requestSerializer: SerializationStrategy<*> get() = serializer() } + + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + chatId: ChatId, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = execute( + SetGameScoreByChatId(userId, score, chatId, messageId, force, disableEditMessage) +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + chatId: ChatId, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, chatId, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + chat: Chat, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + userId, score, chat.id, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + chat: Chat, + messageId: MessageIdentifier, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, chat.id, messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + userId: UserId, + score: Long, + message: ContentMessage, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + userId, score, message.chat.id, message.messageId, force, disableEditMessage +) + +suspend fun RequestsExecutor.setGameScore( + user: CommonUser, + score: Long, + message: ContentMessage, + force: Boolean = false, + disableEditMessage: Boolean = false +) = setGameScore( + user.id, score, message.chat.id, message.messageId, force, disableEditMessage +) diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt index 29edbdd2a6..d254bc29ba 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/games/SendGame.kt @@ -1,9 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.games import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.GameContent @@ -31,4 +34,46 @@ data class SendGame ( get() = commonResultDeserializer override val requestSerializer: SerializationStrategy<*> get() = serializer() -} \ No newline at end of file +} + +suspend fun RequestsExecutor.sendGame( + chatId: ChatIdentifier, + gameShortName: String, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendGame( + chatId, gameShortName, disableNotification, replyToMessageId, replyMarkup + ) +) + +suspend fun RequestsExecutor.sendGame( + chat: Chat, + gameShortName: String, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chat.id, gameShortName, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendGame( + chatId: ChatIdentifier, + game: Game, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chatId, game.title, disableNotification, replyToMessageId, replyMarkup +) + +suspend fun RequestsExecutor.sendGame( + chat: Chat, + game: Game, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendGame( + chat.id, game.title, disableNotification, replyToMessageId, replyMarkup +)