mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-25 19:48:49 +00:00
commit
c3dcb4d738
9
ChatAvatarSetter/README.md
Normal file
9
ChatAvatarSetter/README.md
Normal file
@ -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"
|
||||
```
|
21
ChatAvatarSetter/build.gradle
Normal file
21
ChatAvatarSetter/build.gradle
Normal file
@ -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"
|
||||
}
|
36
ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt
Normal file
36
ChatAvatarSetter/src/main/kotlin/ChatAvatarSetter.kt
Normal file
@ -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<String>) {
|
||||
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()
|
||||
}
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m
|
||||
|
||||
|
||||
kotlin_version=1.7.20
|
||||
telegram_bot_api_version=3.3.0
|
||||
micro_utils_version=0.13.1
|
||||
telegram_bot_api_version=3.3.1
|
||||
micro_utils_version=0.13.2
|
||||
serialization_version=1.4.1
|
||||
ktor_version=2.1.2
|
||||
ktor_version=2.1.3
|
||||
|
@ -21,6 +21,8 @@ include ":StickerInfoBot:jvm_launcher"
|
||||
|
||||
include ":SlotMachineDetectorBot"
|
||||
|
||||
include ":ChatAvatarSetter"
|
||||
|
||||
include ":WebApp"
|
||||
|
||||
include ":FSMBot"
|
||||
|
Loading…
Reference in New Issue
Block a user