mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-17 13:53:53 +00:00
add reactions info bot
This commit is contained in:
parent
753d686fab
commit
05e289975a
@ -5,6 +5,7 @@ import dev.inmo.kslog.common.filter.filtered
|
||||
import dev.inmo.kslog.common.setDefaultKSLog
|
||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||
|
||||
/**
|
||||
@ -12,13 +13,19 @@ import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||
*/
|
||||
suspend fun main(vararg args: String) {
|
||||
val botToken = args.first()
|
||||
val isDebug = args.getOrNull(1) == "debug"
|
||||
|
||||
if (isDebug) {
|
||||
setDefaultKSLog(
|
||||
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
setDefaultKSLog(
|
||||
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||
}
|
||||
)
|
||||
val bot = telegramBot(botToken)
|
||||
|
||||
println(bot.getMe())
|
||||
val me = bot.getMe()
|
||||
println(me)
|
||||
println(bot.getChat(me))
|
||||
}
|
||||
|
9
ReactionsInfoBot/README.md
Normal file
9
ReactionsInfoBot/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# ReactionsInfoBot
|
||||
|
||||
This bot will send info about user reactions in his PM with reply to message user reacted to
|
||||
|
||||
## Launch
|
||||
|
||||
```bash
|
||||
../gradlew run --args="BOT_TOKEN"
|
||||
```
|
21
ReactionsInfoBot/build.gradle
Normal file
21
ReactionsInfoBot/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="ReactionsInfoBotKt"
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||
}
|
54
ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt
Normal file
54
ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt
Normal file
@ -0,0 +1,54 @@
|
||||
import dev.inmo.kslog.common.KSLog
|
||||
import dev.inmo.kslog.common.LogLevel
|
||||
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||
import dev.inmo.kslog.common.filter.filtered
|
||||
import dev.inmo.kslog.common.setDefaultKSLog
|
||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||
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.onChatMessageReactionUpdatedByUser
|
||||
import dev.inmo.tgbotapi.types.reactions.Reaction
|
||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||
import dev.inmo.tgbotapi.utils.customEmoji
|
||||
import dev.inmo.tgbotapi.utils.regular
|
||||
|
||||
/**
|
||||
* This bot will send info about user reactions in his PM with reply to message user reacted to
|
||||
*/
|
||||
suspend fun main(vararg args: String) {
|
||||
val botToken = args.first()
|
||||
val isDebug = args.getOrNull(1) == "debug"
|
||||
|
||||
if (isDebug) {
|
||||
setDefaultKSLog(
|
||||
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val bot = telegramBot(botToken)
|
||||
|
||||
bot.buildBehaviourWithLongPolling {
|
||||
onChatMessageReactionUpdatedByUser {
|
||||
val result = reply(
|
||||
it.chat.id,
|
||||
it.messageId,
|
||||
replyInChat = it.reactedUser.id
|
||||
) {
|
||||
regular("Current reactions for message in reply:\n")
|
||||
it.new.forEach {
|
||||
when (it) {
|
||||
is Reaction.CustomEmoji -> regular("• ") + customEmoji(it.customEmojiId) + regular("(customEmojiId: ${it.customEmojiId})")
|
||||
is Reaction.Emoji -> regular("• ${it.emoji}")
|
||||
is Reaction.Unknown -> regular("• Unknown emoji ($it)")
|
||||
}
|
||||
regular("\n")
|
||||
}
|
||||
}
|
||||
println(result)
|
||||
}
|
||||
}.join()
|
||||
}
|
@ -8,6 +8,10 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@ -26,7 +30,14 @@ suspend fun activateResenderBot(
|
||||
it.content.createResend(
|
||||
chat.id,
|
||||
messageThreadId = it.threadIdOrNull,
|
||||
replyToMessageId = it.messageId
|
||||
replyParameters = it.replyInfo ?.messageMeta ?.let { meta ->
|
||||
val quote = it.withContentOrNull<TextContent>() ?.content ?.quote
|
||||
ReplyParameters(
|
||||
meta,
|
||||
entities = quote ?.textSources ?: emptyList(),
|
||||
quotePosition = quote ?.position
|
||||
)
|
||||
}
|
||||
)
|
||||
) {
|
||||
it.forEach(print)
|
||||
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2344m
|
||||
|
||||
|
||||
kotlin_version=1.9.22
|
||||
telegram_bot_api_version=10.0.0-branch_10.0.0-build2030
|
||||
telegram_bot_api_version=10.0.0
|
||||
micro_utils_version=0.20.25
|
||||
serialization_version=1.6.2
|
||||
ktor_version=2.3.7
|
||||
|
@ -41,3 +41,5 @@ include ":LiveLocationsBot"
|
||||
include ":StickerSetHandler"
|
||||
|
||||
include ":InlineQueriesBot"
|
||||
|
||||
include ":ReactionsInfoBot"
|
||||
|
Loading…
Reference in New Issue
Block a user