mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-03-03 17:42:21 +00:00
21
TagsBot/build.gradle
Normal file
21
TagsBot/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="TagsBotKt"
|
||||||
|
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
}
|
||||||
101
TagsBot/src/main/kotlin/TagsBot.kt
Normal file
101
TagsBot/src/main/kotlin/TagsBot.kt
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
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.subscribeLoggingDropExceptions
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.business.getBusinessAccountGiftsFlow
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.promoteChatAdministrator
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.promoteChatMember
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.members.setChatMemberTag
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.gifts.getChatGiftsFlow
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.gifts.getUserGiftsFlow
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.withTypingAction
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayCompleted
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayContent
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayCreated
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayWinners
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_tag
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.fromUserOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.groupContentMessageOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.idChatIdentifierOrNull
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.potentiallyFromUserGroupContentMessageOrNull
|
||||||
|
import dev.inmo.tgbotapi.types.UserTag
|
||||||
|
import dev.inmo.tgbotapi.types.chat.BusinessChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.UnknownChatType
|
||||||
|
import dev.inmo.tgbotapi.types.gifts.OwnedGift
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.OptionallyFromUserMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.textsources.splitForText
|
||||||
|
import dev.inmo.tgbotapi.utils.bold
|
||||||
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
||||||
|
suspend fun main(vararg args: String) {
|
||||||
|
val botToken = args.first()
|
||||||
|
|
||||||
|
val isDebug = args.any { it == "debug" }
|
||||||
|
val isTestServer = args.any { it == "testServer" }
|
||||||
|
|
||||||
|
if (isDebug) {
|
||||||
|
setDefaultKSLog(
|
||||||
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
telegramBotWithBehaviourAndLongPolling(botToken, testServer = isTestServer) {
|
||||||
|
// start here!!
|
||||||
|
val me = getMe()
|
||||||
|
println(me)
|
||||||
|
|
||||||
|
onCommand("setChatMemberTag", requireOnlyCommandInMessage = false) {
|
||||||
|
val reply = it.replyTo ?.groupContentMessageOrNull() ?: return@onCommand
|
||||||
|
val title = it.content.text.removePrefix("/setChatMemberTag").removePrefix(" ")
|
||||||
|
setChatMemberTag(
|
||||||
|
chatId = reply.chat.id,
|
||||||
|
userId = reply.fromUserOrNull() ?.user ?.id ?: return@onCommand,
|
||||||
|
tag = UserTag(title)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("setCanManageTags", requireOnlyCommandInMessage = false) {
|
||||||
|
val reply = it.replyTo ?.groupContentMessageOrNull() ?: return@onCommand
|
||||||
|
val setOrUnset = it.content.text.removePrefix("/setCanManageTags").removePrefix(" ") == "true"
|
||||||
|
promoteChatAdministrator(
|
||||||
|
it.chat.id,
|
||||||
|
reply.fromUserOrNull() ?.user ?.id ?: return@onCommand,
|
||||||
|
canManageTags = setOrUnset
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommand("removeChatMemberTag") {
|
||||||
|
val reply = it.replyTo ?.groupContentMessageOrNull() ?: return@onCommand
|
||||||
|
setChatMemberTag(
|
||||||
|
chatId = reply.chat.id,
|
||||||
|
userId = reply.fromUserOrNull() ?.user ?.id ?: return@onCommand,
|
||||||
|
tag = null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onContentMessage {
|
||||||
|
val groupContentMessage = it.potentiallyFromUserGroupContentMessageOrNull() ?: return@onContentMessage
|
||||||
|
reply(it, "Tag after casting: ${groupContentMessage.senderTag}")
|
||||||
|
reply(it, "Tag by getting via risk API: ${it.sender_tag}")
|
||||||
|
}
|
||||||
|
|
||||||
|
allUpdatesFlow.subscribeLoggingDropExceptions(this) {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
|
}.second.join()
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
|
import dev.inmo.tgbotapi.types.CustomEmojiId
|
||||||
import dev.inmo.tgbotapi.types.userIdField
|
import dev.inmo.tgbotapi.types.userIdField
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.webapps.*
|
import dev.inmo.tgbotapi.webapps.*
|
||||||
@@ -395,6 +396,11 @@ fun main() {
|
|||||||
}
|
}
|
||||||
mainButton.apply {
|
mainButton.apply {
|
||||||
setText("Main button")
|
setText("Main button")
|
||||||
|
setParams(
|
||||||
|
BottomButtonParams(
|
||||||
|
iconCustomEmojiId = CustomEmojiId("5370976574969486150") // 😏
|
||||||
|
)
|
||||||
|
)
|
||||||
onClick {
|
onClick {
|
||||||
logsState.add("Main button clicked")
|
logsState.add("Main button clicked")
|
||||||
hapticFeedback.notificationOccurred(
|
hapticFeedback.notificationOccurred(
|
||||||
@@ -405,6 +411,11 @@ fun main() {
|
|||||||
}
|
}
|
||||||
secondaryButton.apply {
|
secondaryButton.apply {
|
||||||
setText("Secondary button")
|
setText("Secondary button")
|
||||||
|
setParams(
|
||||||
|
BottomButtonParams(
|
||||||
|
iconCustomEmojiId = CustomEmojiId("5370763368497944736") // 😒
|
||||||
|
)
|
||||||
|
)
|
||||||
onClick {
|
onClick {
|
||||||
logsState.add("Secondary button clicked")
|
logsState.add("Secondary button clicked")
|
||||||
hapticFeedback.notificationOccurred(
|
hapticFeedback.notificationOccurred(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ kotlin.daemon.jvmargs=-Xmx3g -Xms500m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=2.2.21
|
kotlin_version=2.2.21
|
||||||
telegram_bot_api_version=31.0.0
|
telegram_bot_api_version=31.1.0
|
||||||
micro_utils_version=0.26.9
|
micro_utils_version=0.26.9
|
||||||
serialization_version=1.9.0
|
serialization_version=1.9.0
|
||||||
ktor_version=3.3.2
|
ktor_version=3.3.2
|
||||||
|
|||||||
@@ -67,3 +67,5 @@ include ":ChecklistsBot"
|
|||||||
include ":DraftsBot"
|
include ":DraftsBot"
|
||||||
|
|
||||||
include ":GiftsBot"
|
include ":GiftsBot"
|
||||||
|
|
||||||
|
include ":TagsBot"
|
||||||
|
|||||||
Reference in New Issue
Block a user