TelegramBotAPI-examples/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt

69 lines
2.6 KiB
Kotlin
Raw Normal View History

2024-01-08 09:46:23 +00:00
import dev.inmo.kslog.common.KSLog
import dev.inmo.kslog.common.LogLevel
import dev.inmo.kslog.common.defaultMessageFormatter
import dev.inmo.kslog.common.setDefaultKSLog
import dev.inmo.tgbotapi.bot.ktor.telegramBot
2024-01-09 07:55:35 +00:00
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
2024-01-08 09:46:23 +00:00
import dev.inmo.tgbotapi.extensions.api.send.reply
2024-01-08 13:23:06 +00:00
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
2024-01-08 09:46:23 +00:00
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated
2024-01-09 07:55:35 +00:00
import dev.inmo.tgbotapi.types.chat.ExtendedChat
2024-01-08 09:46:23 +00:00
import dev.inmo.tgbotapi.types.reactions.Reaction
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 {
2024-01-08 13:23:06 +00:00
setMessageReaction(
it.chat.id,
it.messageId,
""
)
val replyResult = reply(
2024-01-08 09:46:23 +00:00
it.chat.id,
it.messageId,
replyInChatId = it.reactedUser.id
2024-01-08 09:46:23 +00:00
) {
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}")
2024-08-14 17:33:43 +00:00
is Reaction.Paid -> regular("• Some paid reaction")
2024-01-08 09:46:23 +00:00
is Reaction.Unknown -> regular("• Unknown emoji ($it)")
}
regular("\n")
}
}
2024-01-08 13:23:06 +00:00
setMessageReaction(
it.chat.id,
it.messageId,
)
2024-01-08 09:46:23 +00:00
}
onChatMessageReactionsCountUpdated {
2024-01-09 07:55:35 +00:00
val extendedChat: ExtendedChat = getChat(it.chat)
println(extendedChat)
println(it)
}
2024-01-08 09:46:23 +00:00
}.join()
}