From 33b14f320cd5ea04728c9ae8917d5e1caed99930 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 30 Oct 2022 19:57:11 +0600 Subject: [PATCH] update up to 3.3.1 --- ChatAvatarSetter/README.md | 9 +++++ ChatAvatarSetter/build.gradle | 21 +++++++++++ .../src/main/kotlin/ChatAvatarSetter.kt | 36 +++++++++++++++++++ gradle.properties | 4 +-- settings.gradle | 2 ++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 ChatAvatarSetter/README.md create mode 100644 ChatAvatarSetter/build.gradle create mode 100644 ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt diff --git a/ChatAvatarSetter/README.md b/ChatAvatarSetter/README.md new file mode 100644 index 0000000..a833ab2 --- /dev/null +++ b/ChatAvatarSetter/README.md @@ -0,0 +1,9 @@ +# ChatAvatarSetter + +This bot will set the chat avatar based on the image sent to bot + +## Launch + +```bash +../gradlew run --args="BOT_TOKEN" +``` diff --git a/ChatAvatarSetter/build.gradle b/ChatAvatarSetter/build.gradle new file mode 100644 index 0000000..c6928eb --- /dev/null +++ b/ChatAvatarSetter/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'application' + +mainClassName="ChatAvatarSetterKt" + + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" +} diff --git a/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt b/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt new file mode 100644 index 0000000..8fcf9dd --- /dev/null +++ b/ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt @@ -0,0 +1,36 @@ +import dev.inmo.micro_utils.coroutines.runCatchingSafely +import dev.inmo.tgbotapi.bot.ktor.telegramBot +import dev.inmo.tgbotapi.extensions.api.chat.modify.setChatPhoto +import dev.inmo.tgbotapi.extensions.api.files.downloadFile +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile +import kotlinx.coroutines.* + +suspend fun main(args: Array) { + val bot = telegramBot(args.first()) + + bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) { + onPhoto { + val bytes = downloadFile(it.content) + runCatchingSafely { + setChatPhoto( + it.chat.id, + bytes.asMultipartFile("sample.jpg") + ) + }.onSuccess { b -> + if (b) { + reply(it, "Done") + } else { + reply(it, "Something went wrong") + } + }.onFailure { e -> + e.printStackTrace() + + reply(it, "Something went wrong (see logs)") + } + } + }.join() +} diff --git a/gradle.properties b/gradle.properties index a6d41c4..4504520 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m kotlin_version=1.7.20 -telegram_bot_api_version=3.3.0 +telegram_bot_api_version=3.3.1 micro_utils_version=0.13.1 serialization_version=1.4.1 -ktor_version=2.1.2 +ktor_version=2.1.3 diff --git a/settings.gradle b/settings.gradle index 529e18e..4d94aff 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,6 +21,8 @@ include ":StickerInfoBot:jvm_launcher" include ":SlotMachineDetectorBot" +include ":ChatAvatarSetter" + include ":WebApp" include ":FSMBot"