mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-27 16:39:12 +00:00
Compare commits
4 Commits
fda366d820
...
10.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 578d00cac6 | |||
| 13ecb3f0df | |||
| a008d861da | |||
| 6f3766dff6 |
@@ -42,7 +42,7 @@ suspend fun main(vararg args: String) {
|
|||||||
val replyResult = reply(
|
val replyResult = reply(
|
||||||
it.chat.id,
|
it.chat.id,
|
||||||
it.messageId,
|
it.messageId,
|
||||||
replyInChat = it.reactedUser.id
|
replyInChatId = it.reactedUser.id
|
||||||
) {
|
) {
|
||||||
regular("Current reactions for message in reply:\n")
|
regular("Current reactions for message in reply:\n")
|
||||||
it.new.forEach {
|
it.new.forEach {
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
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.micro_utils.coroutines.firstOf
|
import dev.inmo.micro_utils.coroutines.firstOf
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
@@ -24,6 +29,7 @@ import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
|||||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
import dev.inmo.tgbotapi.types.chat.member.*
|
import dev.inmo.tgbotapi.types.chat.member.*
|
||||||
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import dev.inmo.tgbotapi.utils.mention
|
import dev.inmo.tgbotapi.utils.mention
|
||||||
@@ -49,6 +55,16 @@ sealed interface UserRetrievingStep : State {
|
|||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
|
val isDebug = args.getOrNull(2) == "debug"
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
val allowedAdmin = ChatId(args[1].toLong())
|
val allowedAdmin = ChatId(args[1].toLong())
|
||||||
@@ -185,14 +201,21 @@ suspend fun main(args: Array<String>) {
|
|||||||
) {
|
) {
|
||||||
onCommand(
|
onCommand(
|
||||||
"simple",
|
"simple",
|
||||||
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }) {
|
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }
|
||||||
|
) {
|
||||||
val replyMessage = it.replyTo
|
val replyMessage = it.replyTo
|
||||||
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
if (replyMessage is AccessibleMessage) {
|
||||||
reply(
|
reply(
|
||||||
replyMessage,
|
replyMessage,
|
||||||
"Manage keyboard:",
|
"Manage keyboard:",
|
||||||
replyMarkup = buildCommonKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
replyMarkup = buildCommonKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
reply(it) {
|
||||||
|
regular("Reply to somebody's message to get hist/her rights keyboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onCommand(
|
onCommand(
|
||||||
"granular",
|
"granular",
|
||||||
@@ -204,11 +227,17 @@ suspend fun main(args: Array<String>) {
|
|||||||
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
||||||
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
||||||
|
|
||||||
|
if (replyMessage is AccessibleMessage) {
|
||||||
reply(
|
reply(
|
||||||
replyMessage,
|
replyMessage,
|
||||||
"Manage keyboard:",
|
"Manage keyboard:",
|
||||||
replyMarkup = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
replyMarkup = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
reply(it) {
|
||||||
|
regular("Reply to somebody's message to get hist/her rights keyboard")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessageDataCallbackQuery(
|
onMessageDataCallbackQuery(
|
||||||
@@ -503,5 +532,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
||||||
scope = BotCommandScope.AllGroupChats
|
scope = BotCommandScope.AllGroupChats
|
||||||
)
|
)
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
}.join()
|
}.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2344m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.9.22
|
kotlin_version=1.9.22
|
||||||
telegram_bot_api_version=10.0.0-branch_10.0.0-build2051
|
telegram_bot_api_version=10.1.0
|
||||||
micro_utils_version=0.20.25
|
micro_utils_version=0.20.34
|
||||||
serialization_version=1.6.2
|
serialization_version=1.6.2
|
||||||
ktor_version=2.3.7
|
ktor_version=2.3.8
|
||||||
|
|||||||
Reference in New Issue
Block a user