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..c1e657d 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -16,14 +16,14 @@ 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" - 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,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 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 { 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..1240109 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.2 +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..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.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip