update examples for ktgbotapi 38.0.0

This commit is contained in:
InsanusMokrassar committed 2026-11-26 12:28:56 +06:00
1 parent d0da6c851b
commit 97b4391495
86 files changed
+888 -370

No files matched your search

+10 -1
View File
@@ -1,9 +1,18 @@
# RightsChangerBot
A long-polling/FSM example for changing a member's chat permissions and a channel administrator's rights with inline keyboards. The bot registers its commands in the all-group-chats scope and prints every received update to standard output.
A long-polling/FSM example for changing a member's chat permissions and a channel administrator's rights with inline keyboards. The group command menu lists `/simple`, `/granular`, and `/rights_in_channel`. The bot prints every received update to standard output.
## Commands and callbacks
### Linked verification descriptions
An approved third-party verifier bot can attach a text link to its verification description. Type
`/verify <user_or_chat_id> <https_record_url>` in the allowed user's private chat with the bot.
Use the numeric ID of a user or chat the bot can look up. The example calls `verifyChat` with the
chat and a formatted description. For a private chat the library calls `verifyUser`. Telegram displays
**Verification record** as a link to the supplied URL. The verifier needs permission to set a custom
description. [Telegram verification API](https://core.telegram.org/bots/api#verifychat)
### Member permissions
Run these commands in a group or supergroup as a reply to a non-administrator's message:
+2 -2
View File
@@ -11,12 +11,12 @@ buildscript {
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName="RightsChangerKt"
application.mainClass = "RightsChangerKt"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
implementation 'io.ktor:ktor-client-logging-jvm:3.2.3'
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
}
@@ -15,12 +15,14 @@ import dev.inmo.tgbotapi.extensions.api.chat.members.restrictChatMember
import dev.inmo.tgbotapi.extensions.api.edit.edit
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.api.send.send
import dev.inmo.tgbotapi.extensions.api.verifications.verifyChat
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithFSMAndStartLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitChatSharedEventsMessages
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitCommandMessage
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitUserSharedEventsMessages
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.from
@@ -30,6 +32,7 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.ChannelChat
import dev.inmo.tgbotapi.types.chat.ChatPermissions
import dev.inmo.tgbotapi.types.chat.PrivateChat
import dev.inmo.tgbotapi.types.chat.PublicChat
import dev.inmo.tgbotapi.types.chat.member.AdministratorChatMember
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
@@ -224,6 +227,23 @@ suspend fun main(args: Array<String>) {
it.printStackTrace()
},
) {
onCommandWithArgs(
"verify",
initialFilter = { it.chat is PrivateChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }
) { message, arguments ->
val targetId = arguments.getOrNull(0)?.toLongOrNull()
val recordUrl = arguments.getOrNull(1)
if (arguments.size != 2 || targetId == null || recordUrl == null || !recordUrl.startsWith("https://")) {
reply(message, "Usage: /verify <user_or_chat_id> <https_record_url>")
return@onCommandWithArgs
}
val target = getChat(ChatId(RawChatId(targetId)))
verifyChat(target, buildEntities {
link("Verification record", recordUrl)
})
reply(message, "Verified ${target.id}.")
}
onCommand(
"simple",
initialFilter = { it.chat is PublicChat && it.fromUserMessageOrNull()?.user?.id == allowedAdmin }