From 57dd2380cd6c0a92b75c65e3ae119147eb3ed5f8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Mar 2024 13:46:15 +0600 Subject: [PATCH] fix up to 11.0.0 --- FSMBot/src/main/kotlin/SimpleFSMBot.kt | 4 ++-- InlineQueriesBot/src/commonMain/kotlin/Bot.kt | 5 +++-- .../KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt | 3 ++- PollsBot/src/main/kotlin/PollsBot.kt | 7 ++----- RightsChangerBot/src/main/kotlin/RightsChanger.kt | 6 +++--- .../src/commonMain/kotlin/StickerInfoBot.kt | 2 +- StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt | 5 +++-- WebApp/src/jvmMain/kotlin/WebAppServer.kt | 5 +++-- gradle.properties | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/FSMBot/src/main/kotlin/SimpleFSMBot.kt b/FSMBot/src/main/kotlin/SimpleFSMBot.kt index c5fe9ed..c5b6c21 100644 --- a/FSMBot/src/main/kotlin/SimpleFSMBot.kt +++ b/FSMBot/src/main/kotlin/SimpleFSMBot.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.api.send.sendMessage import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.* import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* -import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams +import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.types.IdChatIdentifier @@ -54,7 +54,7 @@ suspend fun main(args: Array) { val content = contentMessage.content when { - content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context) + content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context) else -> { execute(content.createResend(it.context)) it diff --git a/InlineQueriesBot/src/commonMain/kotlin/Bot.kt b/InlineQueriesBot/src/commonMain/kotlin/Bot.kt index 03027c0..18019d8 100644 --- a/InlineQueriesBot/src/commonMain/kotlin/Bot.kt +++ b/InlineQueriesBot/src/commonMain/kotlin/Bot.kt @@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLi import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent +import dev.inmo.tgbotapi.types.InlineQueryId import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit import dev.inmo.tgbotapi.utils.buildEntities @@ -31,9 +32,9 @@ suspend fun doInlineQueriesBot(token: String) { answer( it, results = results.map { resultNumber -> - val resultAsString = resultNumber.toString() + val inlineQueryId = InlineQueryId(resultNumber.toString()) InlineQueryResultArticle( - resultAsString, + inlineQueryId, "Title $resultNumber", InputTextMessageContent( buildEntities { diff --git a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt index b808b8e..3b8155b 100644 --- a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt +++ b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt @@ -15,6 +15,7 @@ import dev.inmo.tgbotapi.extensions.utils.withContent import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent +import dev.inmo.tgbotapi.types.InlineQueryId import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.utils.* import kotlinx.coroutines.* @@ -137,7 +138,7 @@ suspend fun activateKeyboardsBot( it, results = listOf( InlineQueryResultArticle( - it.query, + InlineQueryId(it.query), "Send buttons", InputTextMessageContent("It is sent via inline mode inline buttons"), replyMarkup = inlineKeyboard { diff --git a/PollsBot/src/main/kotlin/PollsBot.kt b/PollsBot/src/main/kotlin/PollsBot.kt index 1587ecc..647a167 100644 --- a/PollsBot/src/main/kotlin/PollsBot.kt +++ b/PollsBot/src/main/kotlin/PollsBot.kt @@ -11,10 +11,7 @@ import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.ifChannelChat import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.PollIdentifier -import dev.inmo.tgbotapi.types.ReplyParameters +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.GroupChat import dev.inmo.tgbotapi.types.chat.PrivateChat @@ -44,7 +41,7 @@ suspend fun main(vararg args: String) { telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { val me = getMe() - val pollToChat = mutableMapOf() + val pollToChat = mutableMapOf() val pollToChatMutex = Mutex() onCommand("anonymous") { diff --git a/RightsChangerBot/src/main/kotlin/RightsChanger.kt b/RightsChangerBot/src/main/kotlin/RightsChanger.kt index 6f74e69..dad7585 100644 --- a/RightsChangerBot/src/main/kotlin/RightsChanger.kt +++ b/RightsChangerBot/src/main/kotlin/RightsChanger.kt @@ -67,7 +67,7 @@ suspend fun main(args: Array) { val bot = telegramBot(botToken) - val allowedAdmin = ChatId(args[1].toLong()) + val allowedAdmin = ChatId(RawChatId(args[1].toLong())) fun Boolean?.allowedSymbol() = when (this) { true -> "✅" @@ -377,8 +377,8 @@ suspend fun main(args: Array) { initialFilter = { it.user.id == allowedAdmin } ) { val (channelIdString, userIdString) = it.data.split(" ").drop(1) - val channelId = ChatId(channelIdString.toLong()) - val userId = ChatId(userIdString.toLong()) + val channelId = ChatId(RawChatId(channelIdString.toLong())) + val userId = ChatId(RawChatId(userIdString.toLong())) val chatMember = getChatMember(channelId, userId) val asAdmin = chatMember.administratorChatMemberOrNull() val asMember = chatMember.memberChatMemberOrNull() diff --git a/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt b/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt index afcab3c..ddd9f00 100644 --- a/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt +++ b/StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin/StickerInfoBot.kt @@ -44,7 +44,7 @@ fun StickerSet?.buildInfo() = buildEntities { StickerType.Regular -> "Regular" is StickerType.Unknown -> "Unknown type \"${stickerType.type}\"" } - ) + " sticker set with title " + bold(title) + " and name " + bold(name) + ) + " sticker set with title " + bold(title) + " and name " + bold(name.string) } } diff --git a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt index 8e46614..8a9cf65 100644 --- a/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt +++ b/StickerSetHandler/src/main/kotlin/StickerSetHandlerBot.kt @@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticke import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile import dev.inmo.tgbotapi.requests.stickers.InputSticker +import dev.inmo.tgbotapi.types.StickerSetName import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.toChatId @@ -32,7 +33,7 @@ suspend fun main(args: Array) { } ) { val me = getMe() - fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username ?.usernameWithoutAt}" + fun Chat.stickerSetName() = StickerSetName("s${id.chatId}_by_${me.username ?.withoutAt}") onCommand("start") { reply(it) { botCommand("delete") + " - to clear stickers" @@ -82,7 +83,7 @@ suspend fun main(args: Array) { }.onFailure { _ -> createNewStickerSet( it.chat.id.toChatId(), - stickerSetName, + stickerSetName.string, "Sticker set by ${me.firstName}", it.content.media.stickerFormat, listOf( diff --git a/WebApp/src/jvmMain/kotlin/WebAppServer.kt b/WebApp/src/jvmMain/kotlin/WebAppServer.kt index d3cdf09..f603bf6 100644 --- a/WebApp/src/jvmMain/kotlin/WebAppServer.kt +++ b/WebApp/src/jvmMain/kotlin/WebAppServer.kt @@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent +import dev.inmo.tgbotapi.types.InlineQueryId import dev.inmo.tgbotapi.types.LinkPreviewOptions import dev.inmo.tgbotapi.types.webAppQueryIdField import dev.inmo.tgbotapi.types.webapps.WebAppInfo @@ -77,9 +78,9 @@ suspend fun main(vararg args: String) { } post("inline") { val requestBody = call.receiveText() - val queryId = call.parameters[webAppQueryIdField] ?: error("$webAppQueryIdField should be presented") + val queryId = call.parameters[webAppQueryIdField] ?.let(::InlineQueryId) ?: error("$webAppQueryIdField should be presented") - bot.answer(queryId, InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody))) + bot.answerInlineQuery(queryId, listOf(InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody)))) call.respond(HttpStatusCode.OK) } post("check") { diff --git a/gradle.properties b/gradle.properties index 7a7aa20..da91621 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2344m kotlin_version=1.9.23 -telegram_bot_api_version=11.0.0-branch_11.0.0-build2158 +telegram_bot_api_version=11.0.0 micro_utils_version=0.20.39 serialization_version=1.6.3 ktor_version=2.3.9