mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-27 16:39:12 +00:00
Compare commits
1 Commits
11.0.0
...
eedaf0da23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eedaf0da23 |
@@ -1,9 +0,0 @@
|
|||||||
# UserChatShared
|
|
||||||
|
|
||||||
Showing info about boosts
|
|
||||||
|
|
||||||
## Launch
|
|
||||||
|
|
||||||
```bash
|
|
||||||
../gradlew run --args="BOT_TOKEN"
|
|
||||||
```
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="BoostsInfoKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
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
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getUserChatBoosts
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatBoostUpdated
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
|
||||||
import dev.inmo.tgbotapi.utils.regular
|
|
||||||
import korlibs.time.DateFormat
|
|
||||||
import korlibs.time.format
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
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 requestChatId = RequestId(1)
|
|
||||||
|
|
||||||
val bot = telegramBot(args.first())
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
|
||||||
onChatBoostUpdated {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
onCommand("start") {
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
replyMarkup = flatReplyKeyboard {
|
|
||||||
requestChannelButton(
|
|
||||||
"Click me :)",
|
|
||||||
requestChatId,
|
|
||||||
botIsMember = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
regular("Select chat to get know about your boosts")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onChatShared(initialFilter = { it.chatEvent.requestId == requestChatId }) {
|
|
||||||
val boosts = getUserChatBoosts(it.chatEvent.chatId, it.chat.id)
|
|
||||||
reply(
|
|
||||||
it
|
|
||||||
) {
|
|
||||||
boosts.boosts.forEach {
|
|
||||||
regular("Boost added: ${DateFormat.FORMAT1.format(it.addDate.asDate)}; Boost expire: ${DateFormat.FORMAT1.format(it.expirationDate.asDate)}; Unformatted: $it") + "\n"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
@@ -54,7 +54,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
val content = contentMessage.content
|
val content = contentMessage.content
|
||||||
|
|
||||||
when {
|
when {
|
||||||
content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context)
|
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
||||||
else -> {
|
else -> {
|
||||||
execute(content.createResend(it.context))
|
execute(content.createResend(it.context))
|
||||||
it
|
it
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import dev.inmo.kslog.common.filter.filtered
|
|||||||
import dev.inmo.kslog.common.setDefaultKSLog
|
import dev.inmo.kslog.common.setDefaultKSLog
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,19 +12,13 @@ import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
|||||||
*/
|
*/
|
||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
val isDebug = args.getOrNull(1) == "debug"
|
|
||||||
|
|
||||||
if (isDebug) {
|
|
||||||
setDefaultKSLog(
|
setDefaultKSLog(
|
||||||
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
||||||
println(defaultMessageFormatter(level, tag, message, throwable))
|
println(defaultMessageFormatter(level, tag, message, throwable))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
val me = bot.getMe()
|
println(bot.getMe())
|
||||||
println(me)
|
|
||||||
println(bot.getChat(me))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLi
|
|||||||
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
|
||||||
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
|
||||||
@@ -32,9 +31,9 @@ suspend fun doInlineQueriesBot(token: String) {
|
|||||||
answer(
|
answer(
|
||||||
it,
|
it,
|
||||||
results = results.map { resultNumber ->
|
results = results.map { resultNumber ->
|
||||||
val inlineQueryId = InlineQueryId(resultNumber.toString())
|
val resultAsString = resultNumber.toString()
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
inlineQueryId,
|
resultAsString,
|
||||||
"Title $resultNumber",
|
"Title $resultNumber",
|
||||||
InputTextMessageContent(
|
InputTextMessageContent(
|
||||||
buildEntities {
|
buildEntities {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import dev.inmo.tgbotapi.extensions.utils.withContent
|
|||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@@ -138,7 +137,7 @@ suspend fun activateKeyboardsBot(
|
|||||||
it,
|
it,
|
||||||
results = listOf(
|
results = listOf(
|
||||||
InlineQueryResultArticle(
|
InlineQueryResultArticle(
|
||||||
InlineQueryId(it.query),
|
it.query,
|
||||||
"Send buttons",
|
"Send buttons",
|
||||||
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# ReactionsInfoBot
|
|
||||||
|
|
||||||
This bot will resend messages with links with all variants of `LinkPreviewOptions`
|
|
||||||
|
|
||||||
## Launch
|
|
||||||
|
|
||||||
```bash
|
|
||||||
../gradlew run --args="BOT_TOKEN"
|
|
||||||
```
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="LinkPreviewsBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
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
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.copyMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
|
||||||
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
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.textLinkTextSourceOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
|
||||||
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
|
||||||
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
|
||||||
import dev.inmo.tgbotapi.types.reactions.Reaction
|
|
||||||
import dev.inmo.tgbotapi.utils.customEmoji
|
|
||||||
import dev.inmo.tgbotapi.utils.regular
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This bot will reply with the same
|
|
||||||
*/
|
|
||||||
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 {
|
|
||||||
onContentMessage {
|
|
||||||
val url = it.withContentOrNull<TextedContent>() ?.let {
|
|
||||||
it.content.textSources.firstNotNullOfOrNull {
|
|
||||||
it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source
|
|
||||||
}
|
|
||||||
} ?: null.apply {
|
|
||||||
reply(it) {
|
|
||||||
regular("I am support only content with text contains url only")
|
|
||||||
}
|
|
||||||
} ?: return@onContentMessage
|
|
||||||
it.withContentOrNull<TextedContent>() ?.let {
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Disabled
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = true)
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = false)
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = true)
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = false)
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = true)
|
|
||||||
)
|
|
||||||
send(
|
|
||||||
it.chat,
|
|
||||||
it.content.textSources,
|
|
||||||
linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = false)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,9 @@ import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.PollIdentifier
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
import dev.inmo.tgbotapi.types.chat.*
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
@@ -41,7 +43,7 @@ suspend fun main(vararg args: String) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
|
|
||||||
val pollToChat = mutableMapOf<PollId, IdChatIdentifier>()
|
val pollToChat = mutableMapOf<PollIdentifier, IdChatIdentifier>()
|
||||||
val pollToChatMutex = Mutex()
|
val pollToChatMutex = Mutex()
|
||||||
|
|
||||||
onCommand("anonymous") {
|
onCommand("anonymous") {
|
||||||
@@ -52,7 +54,7 @@ suspend fun main(vararg args: String) {
|
|||||||
it.toString()
|
it.toString()
|
||||||
},
|
},
|
||||||
isAnonymous = true,
|
isAnonymous = true,
|
||||||
replyParameters = ReplyParameters(it)
|
replyToMessageId = it.messageId
|
||||||
)
|
)
|
||||||
pollToChatMutex.withLock {
|
pollToChatMutex.withLock {
|
||||||
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
@@ -67,7 +69,7 @@ suspend fun main(vararg args: String) {
|
|||||||
it.toString()
|
it.toString()
|
||||||
},
|
},
|
||||||
isAnonymous = false,
|
isAnonymous = false,
|
||||||
replyParameters = ReplyParameters(it)
|
replyToMessageId = it.messageId
|
||||||
)
|
)
|
||||||
pollToChatMutex.withLock {
|
pollToChatMutex.withLock {
|
||||||
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# ReactionsInfoBot
|
|
||||||
|
|
||||||
This bot will send info about user reactions in his PM with reply to message user reacted to
|
|
||||||
|
|
||||||
## Launch
|
|
||||||
|
|
||||||
```bash
|
|
||||||
../gradlew run --args="BOT_TOKEN"
|
|
||||||
```
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="ReactionsInfoBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
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
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.setMessageReactions
|
|
||||||
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
|
|
||||||
import dev.inmo.tgbotapi.types.chat.ExtendedChat
|
|
||||||
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 {
|
|
||||||
setMessageReaction(
|
|
||||||
it.chat.id,
|
|
||||||
it.messageId,
|
|
||||||
"✍"
|
|
||||||
)
|
|
||||||
val replyResult = reply(
|
|
||||||
it.chat.id,
|
|
||||||
it.messageId,
|
|
||||||
replyInChatId = it.reactedUser.id
|
|
||||||
) {
|
|
||||||
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}")
|
|
||||||
is Reaction.Unknown -> regular("• Unknown emoji ($it)")
|
|
||||||
}
|
|
||||||
regular("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setMessageReaction(
|
|
||||||
it.chat.id,
|
|
||||||
it.messageId,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onChatMessageReactionsCountUpdated {
|
|
||||||
val extendedChat: ExtendedChat = getChat(it.chat)
|
|
||||||
println(extendedChat)
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -8,10 +8,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
|
||||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
@@ -30,14 +26,7 @@ suspend fun activateResenderBot(
|
|||||||
it.content.createResend(
|
it.content.createResend(
|
||||||
chat.id,
|
chat.id,
|
||||||
messageThreadId = it.threadIdOrNull,
|
messageThreadId = it.threadIdOrNull,
|
||||||
replyParameters = it.replyInfo ?.messageMeta ?.let { meta ->
|
replyToMessageId = it.messageId
|
||||||
val quote = it.withContentOrNull<TextContent>() ?.content ?.quote
|
|
||||||
ReplyParameters(
|
|
||||||
meta,
|
|
||||||
entities = quote ?.textSources ?: emptyList(),
|
|
||||||
quotePosition = quote ?.position
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
it.forEach(print)
|
it.forEach(print)
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
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
|
||||||
@@ -29,7 +24,6 @@ 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
|
||||||
@@ -55,19 +49,9 @@ 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(RawChatId(args[1].toLong()))
|
val allowedAdmin = ChatId(args[1].toLong())
|
||||||
|
|
||||||
fun Boolean?.allowedSymbol() = when (this) {
|
fun Boolean?.allowedSymbol() = when (this) {
|
||||||
true -> "✅"
|
true -> "✅"
|
||||||
@@ -201,21 +185,14 @@ 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",
|
||||||
@@ -227,17 +204,11 @@ 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(
|
||||||
@@ -377,8 +348,8 @@ suspend fun main(args: Array<String>) {
|
|||||||
initialFilter = { it.user.id == allowedAdmin }
|
initialFilter = { it.user.id == allowedAdmin }
|
||||||
) {
|
) {
|
||||||
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
||||||
val channelId = ChatId(RawChatId(channelIdString.toLong()))
|
val channelId = ChatId(channelIdString.toLong())
|
||||||
val userId = ChatId(RawChatId(userIdString.toLong()))
|
val userId = ChatId(userIdString.toLong())
|
||||||
val chatMember = getChatMember(channelId, userId)
|
val chatMember = getChatMember(channelId, userId)
|
||||||
val asAdmin = chatMember.administratorChatMemberOrNull()
|
val asAdmin = chatMember.administratorChatMemberOrNull()
|
||||||
val asMember = chatMember.memberChatMemberOrNull()
|
val asMember = chatMember.memberChatMemberOrNull()
|
||||||
@@ -532,9 +503,5 @@ 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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ fun StickerSet?.buildInfo() = buildEntities {
|
|||||||
StickerType.Regular -> "Regular"
|
StickerType.Regular -> "Regular"
|
||||||
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
||||||
}
|
}
|
||||||
) + " sticker set with title " + bold(title) + " and name " + bold(name.string)
|
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticke
|
|||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||||
import dev.inmo.tgbotapi.types.StickerSetName
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
import dev.inmo.tgbotapi.types.toChatId
|
||||||
@@ -33,7 +32,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
val me = getMe()
|
val me = getMe()
|
||||||
fun Chat.stickerSetName() = StickerSetName("s${id.chatId}_by_${me.username ?.withoutAt}")
|
fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username ?.usernameWithoutAt}"
|
||||||
onCommand("start") {
|
onCommand("start") {
|
||||||
reply(it) {
|
reply(it) {
|
||||||
botCommand("delete") + " - to clear stickers"
|
botCommand("delete") + " - to clear stickers"
|
||||||
@@ -83,7 +82,7 @@ suspend fun main(args: Array<String>) {
|
|||||||
}.onFailure { _ ->
|
}.onFailure { _ ->
|
||||||
createNewStickerSet(
|
createNewStickerSet(
|
||||||
it.chat.id.toChatId(),
|
it.chat.id.toChatId(),
|
||||||
stickerSetName.string,
|
stickerSetName,
|
||||||
"Sticker set by ${me.firstName}",
|
"Sticker set by ${me.firstName}",
|
||||||
it.content.media.stickerFormat,
|
it.content.media.stickerFormat,
|
||||||
listOf(
|
listOf(
|
||||||
|
|||||||
@@ -7,11 +7,14 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPoll
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatShared
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUserShared
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUsersShared
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestBotButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestChatButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestGroupButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserButton
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.requestUserOrBotButton
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||||
import dev.inmo.tgbotapi.types.keyboardButtonRequestUserLimit
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.mention
|
import dev.inmo.tgbotapi.types.message.textsources.mention
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.utils.row
|
import dev.inmo.tgbotapi.utils.row
|
||||||
@@ -27,88 +30,50 @@ suspend fun main(args: Array<String>) {
|
|||||||
val requestIdUserPremium = RequestId(3)
|
val requestIdUserPremium = RequestId(3)
|
||||||
val requestIdBot = RequestId(4)
|
val requestIdBot = RequestId(4)
|
||||||
|
|
||||||
val requestIdUsersOrBots = RequestId(5)
|
val requestIdAnyChat = RequestId(5)
|
||||||
val requestIdUsersNonPremium = RequestId(6)
|
val requestIdChannel = RequestId(6)
|
||||||
val requestIdUsersAny = RequestId(7)
|
val requestIdPublicChannel = RequestId(7)
|
||||||
val requestIdUsersPremium = RequestId(8)
|
val requestIdPrivateChannel = RequestId(8)
|
||||||
val requestIdBots = RequestId(9)
|
val requestIdChannelUserOwner = RequestId(9)
|
||||||
|
|
||||||
val requestIdAnyChat = RequestId(10)
|
val requestIdGroup = RequestId(10)
|
||||||
val requestIdChannel = RequestId(11)
|
val requestIdPublicGroup = RequestId(11)
|
||||||
val requestIdPublicChannel = RequestId(12)
|
val requestIdPrivateGroup = RequestId(12)
|
||||||
val requestIdPrivateChannel = RequestId(13)
|
val requestIdGroupUserOwner = RequestId(13)
|
||||||
val requestIdChannelUserOwner = RequestId(14)
|
|
||||||
|
|
||||||
val requestIdGroup = RequestId(15)
|
val requestIdForum = RequestId(14)
|
||||||
val requestIdPublicGroup = RequestId(16)
|
val requestIdPublicForum = RequestId(15)
|
||||||
val requestIdPrivateGroup = RequestId(17)
|
val requestIdPrivateForum = RequestId(16)
|
||||||
val requestIdGroupUserOwner = RequestId(18)
|
val requestIdForumUserOwner = RequestId(17)
|
||||||
|
|
||||||
val requestIdForum = RequestId(19)
|
|
||||||
val requestIdPublicForum = RequestId(20)
|
|
||||||
val requestIdPrivateForum = RequestId(21)
|
|
||||||
val requestIdForumUserOwner = RequestId(22)
|
|
||||||
|
|
||||||
val keyboard = replyKeyboard(
|
val keyboard = replyKeyboard(
|
||||||
resizeKeyboard = true,
|
resizeKeyboard = true,
|
||||||
) {
|
) {
|
||||||
row {
|
row {
|
||||||
requestUserOrBotButton(
|
requestUserOrBotButton(
|
||||||
"\uD83D\uDC64/\uD83E\uDD16 (1)",
|
"\uD83D\uDC64/\uD83E\uDD16",
|
||||||
requestIdUserOrBot
|
requestIdUserOrBot
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
row {
|
row {
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64☆ (1)",
|
"\uD83D\uDC64☆",
|
||||||
requestIdUserNonPremium,
|
requestIdUserNonPremium,
|
||||||
premiumUser = false
|
premiumUser = false
|
||||||
)
|
)
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64 (1)",
|
"\uD83D\uDC64",
|
||||||
requestIdUserAny,
|
requestIdUserAny,
|
||||||
premiumUser = null
|
premiumUser = null
|
||||||
)
|
)
|
||||||
requestUserButton(
|
requestUserButton(
|
||||||
"\uD83D\uDC64★ (1)",
|
"\uD83D\uDC64★",
|
||||||
requestIdUserPremium,
|
requestIdUserPremium,
|
||||||
premiumUser = true
|
premiumUser = true
|
||||||
)
|
)
|
||||||
requestBotButton(
|
requestBotButton(
|
||||||
"\uD83E\uDD16 (1)",
|
|
||||||
requestIdBot
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestUsersOrBotsButton(
|
|
||||||
"\uD83D\uDC64/\uD83E\uDD16",
|
|
||||||
requestIdUsersOrBots,
|
|
||||||
maxCount = keyboardButtonRequestUserLimit.last
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestUsersButton(
|
|
||||||
"\uD83D\uDC64☆",
|
|
||||||
requestIdUsersNonPremium,
|
|
||||||
premiumUser = false,
|
|
||||||
maxCount = keyboardButtonRequestUserLimit.last
|
|
||||||
)
|
|
||||||
requestUsersButton(
|
|
||||||
"\uD83D\uDC64",
|
|
||||||
requestIdUsersAny,
|
|
||||||
premiumUser = null,
|
|
||||||
maxCount = keyboardButtonRequestUserLimit.last
|
|
||||||
)
|
|
||||||
requestUsersButton(
|
|
||||||
"\uD83D\uDC64★",
|
|
||||||
requestIdUsersPremium,
|
|
||||||
premiumUser = true,
|
|
||||||
maxCount = keyboardButtonRequestUserLimit.last
|
|
||||||
)
|
|
||||||
requestBotsButton(
|
|
||||||
"\uD83E\uDD16",
|
"\uD83E\uDD16",
|
||||||
requestIdBots,
|
requestIdBot
|
||||||
maxCount = keyboardButtonRequestUserLimit.last
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
row {
|
row {
|
||||||
@@ -199,8 +164,8 @@ suspend fun main(args: Array<String>) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onUsersShared {
|
onUserShared {
|
||||||
it.chatEvent.userIds.forEach { userId ->
|
val userId = it.chatEvent.userId
|
||||||
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
@@ -220,7 +185,6 @@ suspend fun main(args: Array<String>) {
|
|||||||
+" (user info: $userInfo; user id: $userId)"
|
+" (user info: $userInfo; user id: $userId)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
onChatShared {
|
onChatShared {
|
||||||
val chatId = it.chatEvent.chatId
|
val chatId = it.chatEvent.chatId
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
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.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
@@ -18,8 +14,6 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
|||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
|
||||||
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
@@ -49,16 +43,6 @@ suspend fun main(vararg args: String) {
|
|||||||
args.first(),
|
args.first(),
|
||||||
testServer = args.any { it == "testServer" }
|
testServer = args.any { it == "testServer" }
|
||||||
)
|
)
|
||||||
val isDebug = args.any { it == "debug" }
|
|
||||||
|
|
||||||
if (isDebug) {
|
|
||||||
setDefaultKSLog(
|
|
||||||
KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? ->
|
|
||||||
println(defaultMessageFormatter(level, tag, message, throwable))
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
||||||
createKtorServer(
|
createKtorServer(
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
@@ -78,9 +62,9 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
post("inline") {
|
post("inline") {
|
||||||
val requestBody = call.receiveText()
|
val requestBody = call.receiveText()
|
||||||
val queryId = call.parameters[webAppQueryIdField] ?.let(::InlineQueryId) ?: error("$webAppQueryIdField should be presented")
|
val queryId = call.parameters[webAppQueryIdField] ?: error("$webAppQueryIdField should be presented")
|
||||||
|
|
||||||
bot.answerInlineQuery(queryId, listOf(InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody))))
|
bot.answer(queryId, InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody)))
|
||||||
call.respond(HttpStatusCode.OK)
|
call.respond(HttpStatusCode.OK)
|
||||||
}
|
}
|
||||||
post("check") {
|
post("check") {
|
||||||
@@ -118,11 +102,8 @@ suspend fun main(vararg args: String) {
|
|||||||
row {
|
row {
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
linkPreviewOptions = LinkPreviewOptions.Small(
|
|
||||||
args[1],
|
|
||||||
showAboveText = false
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onCommand("attachment_menu") {
|
onCommand("attachment_menu") {
|
||||||
@@ -133,11 +114,8 @@ suspend fun main(vararg args: String) {
|
|||||||
row {
|
row {
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
linkPreviewOptions = LinkPreviewOptions.Large(
|
|
||||||
args[1],
|
|
||||||
showAboveText = true
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onBaseInlineQuery {
|
onBaseInlineQuery {
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maven { url "https://nexus.inmo.dev/repository/maven-releases/" }
|
maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
# Due to parallel compilation project require next amount of memory on full build
|
# Due to parallel compilation project require next amount of memory on full build
|
||||||
org.gradle.jvmargs=-Xmx2344m
|
org.gradle.jvmargs=-Xmx2g
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.9.23
|
kotlin_version=1.9.22
|
||||||
telegram_bot_api_version=11.0.0
|
telegram_bot_api_version=9.4.1
|
||||||
micro_utils_version=0.20.39
|
micro_utils_version=0.20.15
|
||||||
serialization_version=1.6.3
|
serialization_version=1.6.2
|
||||||
ktor_version=2.3.9
|
ktor_version=2.3.7
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||||
|
|||||||
@@ -41,9 +41,3 @@ include ":LiveLocationsBot"
|
|||||||
include ":StickerSetHandler"
|
include ":StickerSetHandler"
|
||||||
|
|
||||||
include ":InlineQueriesBot"
|
include ":InlineQueriesBot"
|
||||||
|
|
||||||
include ":ReactionsInfoBot"
|
|
||||||
|
|
||||||
include ":LinkPreviewsBot"
|
|
||||||
|
|
||||||
include ":BoostsInfoBot"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user