From d547dce2ab9b4fc906af166b845bfe0fe56c19b6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 4 Aug 2022 21:41:55 +0600 Subject: [PATCH 1/5] update dependencies --- WebApp/src/jvmMain/kotlin/WebAppServer.kt | 1 - gradle.properties | 8 ++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/WebApp/src/jvmMain/kotlin/WebAppServer.kt b/WebApp/src/jvmMain/kotlin/WebAppServer.kt index ba39403..fed639e 100644 --- a/WebApp/src/jvmMain/kotlin/WebAppServer.kt +++ b/WebApp/src/jvmMain/kotlin/WebAppServer.kt @@ -1,5 +1,4 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.micro_utils.crypto.hmacSha256 import dev.inmo.micro_utils.ktor.server.createKtorServer import dev.inmo.tgbotapi.extensions.api.answers.answer import dev.inmo.tgbotapi.extensions.api.bot.getMe diff --git a/gradle.properties b/gradle.properties index 14b75d0..48b7286 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true org.gradle.jvmargs=-Xmx768m -kotlin_version=1.6.21 -telegram_bot_api_version=2.2.2 -micro_utils_version=0.11.13 -serialization_version=1.3.3 +kotlin_version=1.7.10 +telegram_bot_api_version=3.0.0 +micro_utils_version=0.12.0 +serialization_version=1.4.0-RC ktor_version=2.0.3 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0dfb4f8..0e9a610 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip From 21692d16ca5f5a8f9f3855e80a96a0f7755fac4a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 4 Aug 2022 22:32:36 +0600 Subject: [PATCH 2/5] fixes in forward chat info bot --- FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt | 8 ++++++-- .../src/main/kotlin/ForwardInfoSenderBot.kt | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt index 81183ba..193aa57 100644 --- a/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt +++ b/FilesLoaderBot/src/main/kotlin/FilesLoaderBot.kt @@ -14,14 +14,18 @@ import java.io.File */ suspend fun main(args: Array) { val botToken = args.first() - val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("") + val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("/tmp/") directoryOrFile.mkdirs() telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { onMedia(initialFilter = null) { val pathedFile = bot.getFileAdditionalInfo(it.content.media) val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl) - bot.downloadFile(it.content.media, outFile) + runCatching { + bot.downloadFile(it.content.media, outFile) + }.onFailure { + it.printStackTrace() + } reply(it, "Saved to ${outFile.absolutePath}") } onContentMessage { println(it) } diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt index 7a23ff3..1fa7001 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -16,7 +16,7 @@ suspend fun main(vararg args: String) { val botToken = args.first() telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { - onContentMessage(subcontextUpdatesFilter = { _, _ -> true }) { + onContentMessage { val toAnswer = buildEntities { when (val forwardInfo = it.forwardInfo) { null -> +"There is no forward info" @@ -37,8 +37,9 @@ suspend fun main(vararg args: String) { is ExtendedBot -> regular("Bot ") } + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})" } - is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")" - is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")" + is ForwardFromPublicChatInfo.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")" + is ForwardFromPublicChatInfo.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")" + is ForwardFromPublicChatInfo.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")" } } reply(it, toAnswer) From e039f90961538cb9caab4693baf9417f3150ce69 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 5 Aug 2022 19:45:52 +0600 Subject: [PATCH 3/5] updates according to 3.0.0 --- .../src/main/kotlin/ForwardInfoSenderBot.kt | 10 +++++----- .../src/commonMain/kotlin/KeyboardsBot.kt | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt index 1fa7001..c1e657d 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -20,10 +20,10 @@ suspend fun main(vararg args: String) { val toAnswer = buildEntities { when (val forwardInfo = it.forwardInfo) { null -> +"There is no forward info" - is AnonymousForwardInfo -> { + is ForwardInfo.ByAnonymous -> { regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\"" } - is UserForwardInfo -> { + is ForwardInfo.ByUser -> { val user = forwardInfo.from when (user) { is CommonUser -> { @@ -37,9 +37,9 @@ suspend fun main(vararg args: String) { is ExtendedBot -> regular("Bot ") } + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})" } - is ForwardFromPublicChatInfo.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")" - is ForwardFromPublicChatInfo.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")" - is ForwardFromPublicChatInfo.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")" + is ForwardInfo.PublicChat.FromChannel -> regular("Channel (") + code(forwardInfo.channelChat.title) + ")" + is ForwardInfo.PublicChat.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")" + is ForwardInfo.PublicChat.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")" } } reply(it, toAnswer) diff --git a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt index d285eae..d87f757 100644 --- a/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt +++ b/KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin/KeyboardsBot.kt @@ -100,6 +100,7 @@ suspend fun activateKeyboardsBot( } } ) + answer(it) } onUnhandledCommand { From 19a713a3e342448c79cdcbdb9772eaff8817d831 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 Aug 2022 08:18:55 +0600 Subject: [PATCH 4/5] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 48b7286..1240109 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m kotlin_version=1.7.10 -telegram_bot_api_version=3.0.0 +telegram_bot_api_version=3.0.2 micro_utils_version=0.12.0 serialization_version=1.4.0-RC ktor_version=2.0.3 From bca2ae905bafa0527a749f4cc44b45b10ff45ab7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 6 Aug 2022 08:19:13 +0600 Subject: [PATCH 5/5] Update gradle-wrapper.properties --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0e9a610..c50b3c8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip