|
|
|
|
@@ -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.subscribeSafelyWithoutExceptions
|
|
|
|
|
import dev.inmo.micro_utils.fsm.common.State
|
|
|
|
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
|
|
|
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.member.*
|
|
|
|
|
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.utils.*
|
|
|
|
|
import dev.inmo.tgbotapi.utils.mention
|
|
|
|
|
@@ -49,6 +55,16 @@ sealed interface UserRetrievingStep : State {
|
|
|
|
|
suspend fun main(args: Array<String>) {
|
|
|
|
|
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 allowedAdmin = ChatId(args[1].toLong())
|
|
|
|
|
@@ -185,14 +201,21 @@ suspend fun main(args: Array<String>) {
|
|
|
|
|
) {
|
|
|
|
|
onCommand(
|
|
|
|
|
"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 userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
|
|
|
|
reply(
|
|
|
|
|
replyMessage,
|
|
|
|
|
"Manage keyboard:",
|
|
|
|
|
replyMarkup = buildCommonKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
|
|
|
|
)
|
|
|
|
|
if (replyMessage is AccessibleMessage) {
|
|
|
|
|
reply(
|
|
|
|
|
replyMessage,
|
|
|
|
|
"Manage keyboard:",
|
|
|
|
|
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(
|
|
|
|
|
"granular",
|
|
|
|
|
@@ -204,11 +227,17 @@ suspend fun main(args: Array<String>) {
|
|
|
|
|
val usernameInText = it.content.textSources.firstNotNullOfOrNull { it.mentionTextSourceOrNull() } ?.username
|
|
|
|
|
val userInReply = replyMessage?.fromUserMessageOrNull()?.user?.id ?: return@onCommand
|
|
|
|
|
|
|
|
|
|
reply(
|
|
|
|
|
replyMessage,
|
|
|
|
|
"Manage keyboard:",
|
|
|
|
|
replyMarkup = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
|
|
|
|
)
|
|
|
|
|
if (replyMessage is AccessibleMessage) {
|
|
|
|
|
reply(
|
|
|
|
|
replyMessage,
|
|
|
|
|
"Manage keyboard:",
|
|
|
|
|
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(
|
|
|
|
|
@@ -503,5 +532,9 @@ suspend fun main(args: Array<String>) {
|
|
|
|
|
BotCommand("rights_in_channel", "Trigger granular keyboard. Use with reply to user"),
|
|
|
|
|
scope = BotCommandScope.AllGroupChats
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
|
|
|
println(it)
|
|
|
|
|
}
|
|
|
|
|
}.join()
|
|
|
|
|
}
|
|
|
|
|
|