mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-17 11:45:36 +00:00
Compare commits
1 Commits
7.1.1
...
5fb1239d63
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fb1239d63 |
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -8,9 +8,6 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
sudo apt install -y libcurl4-openssl-dev
|
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 11
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# ChatAvatarSetter
|
|
||||||
|
|
||||||
This bot will set the chat avatar based on the image sent to bot
|
|
||||||
|
|
||||||
## 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="ChatAvatarSetterKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.modify.setChatPhoto
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onPhoto
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
val bot = telegramBot(args.first())
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(scope = CoroutineScope(Dispatchers.IO)) {
|
|
||||||
onPhoto {
|
|
||||||
val bytes = downloadFile(it.content)
|
|
||||||
runCatchingSafely {
|
|
||||||
setChatPhoto(
|
|
||||||
it.chat.id,
|
|
||||||
bytes.asMultipartFile("sample.jpg")
|
|
||||||
)
|
|
||||||
}.onSuccess { b ->
|
|
||||||
if (b) {
|
|
||||||
reply(it, "Done")
|
|
||||||
} else {
|
|
||||||
reply(it, "Something went wrong")
|
|
||||||
}
|
|
||||||
}.onFailure { e ->
|
|
||||||
e.printStackTrace()
|
|
||||||
|
|
||||||
reply(it, "Something went wrong (see logs)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# DeepLinksBot
|
|
||||||
|
|
||||||
This bot will send you deeplink to this bot when you send some text message and react on the `start` button
|
|
||||||
|
|
||||||
## 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="DeepLinksBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelySkippingExceptions
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramDeepLink
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This bot will send you deeplink to this bot when you send some text message and react on the `start` button
|
|
||||||
*/
|
|
||||||
suspend fun main(vararg args: String) {
|
|
||||||
val botToken = args.first()
|
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken) {
|
|
||||||
val me = bot.getMe()
|
|
||||||
println(me)
|
|
||||||
|
|
||||||
onText(
|
|
||||||
initialFilter = { it.content.textSources.none { it is BotCommandTextSource } } // excluding messages with commands
|
|
||||||
) {
|
|
||||||
reply(it, makeTelegramDeepLink(me.username, it.content.text))
|
|
||||||
}
|
|
||||||
|
|
||||||
onCommand("start", requireOnlyCommandInMessage = true) { // handling of `start` without args
|
|
||||||
reply(it, "Hi :) Send me any text and I will try hard to create deeplink for you")
|
|
||||||
}
|
|
||||||
onDeepLink { (it, deepLink) ->
|
|
||||||
reply(it, "Ok, I got deep link \"${deepLink}\" in trigger")
|
|
||||||
}
|
|
||||||
waitDeepLinks().subscribeSafelyWithoutExceptions(this) { (it, deepLink) ->
|
|
||||||
reply(it, "Ok, I got deep link \"${deepLink}\" in waiter")
|
|
||||||
println(triggersHolder.handleableCommandsHolder.handleable)
|
|
||||||
}
|
|
||||||
}.second.join()
|
|
||||||
}
|
|
||||||
@@ -1,26 +1,20 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
||||||
import dev.inmo.micro_utils.fsm.common.State
|
import dev.inmo.micro_utils.fsm.common.State
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
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.parseCommandsWithParams
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||||
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.ChatId
|
||||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.botCommand
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
sealed interface BotState : State
|
sealed interface BotState : State
|
||||||
data class ExpectContentOrStopState(override val context: IdChatIdentifier, val sourceMessage: CommonMessage<TextContent>) : BotState
|
data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage<TextContent>) : BotState
|
||||||
data class StopState(override val context: IdChatIdentifier) : BotState
|
data class StopState(override val context: ChatId) : BotState
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
@@ -42,15 +36,14 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
strictlyOn<ExpectContentOrStopState> {
|
strictlyOn<ExpectContentOrStopState> {
|
||||||
send(
|
sendMessage(
|
||||||
it.context,
|
it.context,
|
||||||
) {
|
buildEntities {
|
||||||
+"Send me some content or " + botCommand("stop") + " if you want to stop sending"
|
+"Send me some content or " + botCommand("stop") + " if you want to stop sending"
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
val contentMessage = waitAnyContentMessage().filter { message ->
|
val contentMessage = waitContentMessage().first()
|
||||||
message.sameThread(it.sourceMessage)
|
|
||||||
}.first()
|
|
||||||
val content = contentMessage.content
|
val content = contentMessage.content
|
||||||
|
|
||||||
when {
|
when {
|
||||||
@@ -62,14 +55,12 @@ suspend fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
strictlyOn<StopState> {
|
strictlyOn<StopState> {
|
||||||
send(it.context) { +"You have stopped sending of content" }
|
sendMessage(it.context, "You have stopped sending of content")
|
||||||
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
command(
|
command("start") {
|
||||||
"start"
|
|
||||||
) {
|
|
||||||
startChain(ExpectContentOrStopState(it.chat.id, it))
|
startChain(ExpectContentOrStopState(it.chat.id, it))
|
||||||
}
|
}
|
||||||
}.second.join()
|
}.second.join()
|
||||||
|
|||||||
@@ -1,39 +1,9 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithAnimation
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithAudio
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithDocument
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithMediaGroup
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithPhoto
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithSticker
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideo
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVideoNote
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.replyWithVoice
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.withAction
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
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.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMedia
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
|
||||||
import dev.inmo.tgbotapi.requests.send.SendAction
|
|
||||||
import dev.inmo.tgbotapi.types.actions.BotAction
|
|
||||||
import dev.inmo.tgbotapi.types.actions.TypingAction
|
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
|
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaPhoto
|
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.AnimationContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.AudioContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.DocumentContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.StickerContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VideoContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VideoNoteContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.VoiceContent
|
|
||||||
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
import dev.inmo.tgbotapi.utils.filenameFromUrl
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -44,80 +14,18 @@ import java.io.File
|
|||||||
*/
|
*/
|
||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("/tmp/")
|
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("")
|
||||||
directoryOrFile.mkdirs()
|
directoryOrFile.mkdirs()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onCommand("start") {
|
|
||||||
reply(it, "Send me any media (like photo or video) to download it")
|
|
||||||
}
|
|
||||||
onMedia(initialFilter = null) {
|
onMedia(initialFilter = null) {
|
||||||
val content = it.content
|
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
||||||
val pathedFile = bot.getFileAdditionalInfo(content.media)
|
val file = File(directoryOrFile, pathedFile.filePath.filenameFromUrl).apply {
|
||||||
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
createNewFile()
|
||||||
runCatching {
|
writeBytes(bot.downloadFile(pathedFile))
|
||||||
bot.downloadFile(content.media, outFile)
|
|
||||||
}.onFailure {
|
|
||||||
it.printStackTrace()
|
|
||||||
}.onSuccess { _ ->
|
|
||||||
reply(it, "Saved to ${outFile.absolutePath}")
|
|
||||||
withAction(it.chat.id, TypingAction) {
|
|
||||||
when (content) {
|
|
||||||
is PhotoContent -> replyWithPhoto(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is AnimationContent -> replyWithAnimation(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is VideoContent -> replyWithVideo(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is StickerContent -> replyWithSticker(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is MediaGroupContent<*> -> replyWithMediaGroup(
|
|
||||||
it,
|
|
||||||
content.group.map {
|
|
||||||
when (val innerContent = it.content) {
|
|
||||||
is AudioContent -> TelegramMediaAudio(
|
|
||||||
downloadFileToTemp(innerContent.media).asMultipartFile()
|
|
||||||
)
|
|
||||||
is DocumentContent -> TelegramMediaDocument(
|
|
||||||
downloadFileToTemp(innerContent.media).asMultipartFile()
|
|
||||||
)
|
|
||||||
is PhotoContent -> TelegramMediaPhoto(
|
|
||||||
downloadFileToTemp(innerContent.media).asMultipartFile()
|
|
||||||
)
|
|
||||||
is VideoContent -> TelegramMediaVideo(
|
|
||||||
downloadFileToTemp(innerContent.media).asMultipartFile()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
is AudioContent -> replyWithAudio(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is DocumentContent -> replyWithDocument(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is VoiceContent -> replyWithVoice(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
is VideoNoteContent -> replyWithVideoNote(
|
|
||||||
it,
|
|
||||||
outFile.asMultipartFile()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
reply(it, "Saved to ${file.absolutePath}")
|
||||||
}
|
}
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
onContentMessage { println(it) }
|
||||||
}.second.join()
|
}.second.join()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeLink
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.types.chat.CommonBot
|
import dev.inmo.tgbotapi.types.chat.CommonBot
|
||||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||||
import dev.inmo.tgbotapi.types.chat.ExtendedBot
|
import dev.inmo.tgbotapi.types.chat.ExtendedBot
|
||||||
import dev.inmo.tgbotapi.types.message.*
|
import dev.inmo.tgbotapi.types.message.*
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
|
||||||
import dev.inmo.tgbotapi.utils.code
|
|
||||||
import dev.inmo.tgbotapi.utils.link
|
|
||||||
import dev.inmo.tgbotapi.utils.regular
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,38 +16,23 @@ suspend fun main(vararg args: String) {
|
|||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage {
|
onContentMessage(subcontextUpdatesFilter = { _, _ -> true }) {
|
||||||
val toAnswer = buildEntities {
|
val toAnswer = buildEntities {
|
||||||
when (val forwardInfo = it.forwardInfo) {
|
when (val forwardInfo = it.forwardInfo) {
|
||||||
null -> +"There is no forward info"
|
null -> +"There is no forward info"
|
||||||
is ForwardInfo.ByAnonymous -> {
|
is AnonymousForwardInfo -> {
|
||||||
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
regular("Anonymous user which signed as \"") + code(forwardInfo.senderName) + "\""
|
||||||
}
|
}
|
||||||
is ForwardInfo.ByUser -> {
|
is UserForwardInfo -> {
|
||||||
val user = forwardInfo.from
|
val user = forwardInfo.from
|
||||||
when (user) {
|
when (user) {
|
||||||
is CommonUser -> {
|
is CommonUser -> regular("User ")
|
||||||
if (user.isPremium) {
|
|
||||||
regular("Premium user ")
|
|
||||||
} else {
|
|
||||||
regular("User ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is CommonBot,
|
is CommonBot,
|
||||||
is ExtendedBot -> regular("Bot ")
|
is ExtendedBot -> regular("Bot ")
|
||||||
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username?.username ?: "Without username"})"
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
||||||
}
|
}
|
||||||
is ForwardInfo.PublicChat.FromChannel -> {
|
is ForwardFromChannelInfo -> regular("Channel (") + code((forwardInfo.channelChat).title) + ")"
|
||||||
regular("Channel (") + (forwardInfo.channelChat.username ?.let {
|
is ForwardFromSupergroupInfo -> regular("Supergroup (") + code((forwardInfo.group).title) + ")"
|
||||||
link(
|
|
||||||
forwardInfo.channelChat.title,
|
|
||||||
makeLink(it)
|
|
||||||
)
|
|
||||||
} ?: code(forwardInfo.channelChat.title)) + ")"
|
|
||||||
}
|
|
||||||
is ForwardInfo.PublicChat.FromSupergroup -> regular("Supergroup (") + code(forwardInfo.group.title) + ")"
|
|
||||||
is ForwardInfo.PublicChat.SentByChannel -> regular("Sent by channel (") + code(forwardInfo.channelChat.title) + ")"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply(it, toAnswer)
|
reply(it, toAnswer)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ buildscript {
|
|||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
mainClassName="GetMeBotKt"
|
mainClassName="HelloBotKt"
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
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.ifFromChannelGroupContentMessage
|
|
||||||
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
|
||||||
@@ -27,35 +25,21 @@ suspend fun main(vararg args: String) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage { message ->
|
onContentMessage { message ->
|
||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
|
if (chat is ChannelChat) {
|
||||||
val answerText = when (val chat = message.chat) {
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
is ChannelChat -> {
|
sendTextMessage(chat, answer, MarkdownV2)
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
return@onContentMessage
|
||||||
reply(message, answer, MarkdownV2)
|
}
|
||||||
return@onContentMessage
|
val answerText = "Oh, hi, " + when (chat) {
|
||||||
}
|
is User -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
||||||
is PrivateChat -> {
|
is PrivateChat -> "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id)
|
||||||
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
||||||
return@onContentMessage
|
chat.title.linkMarkdownV2(it)
|
||||||
}
|
} ?: chat.title
|
||||||
is GroupChat -> {
|
is GroupChat -> bot.getChat(chat).inviteLink ?.let {
|
||||||
message.ifFromChannelGroupContentMessage {
|
chat.title.linkMarkdownV2(it)
|
||||||
val answer = "Hi, ${it.senderChat.title}"
|
} ?: chat.title
|
||||||
reply(message, answer, MarkdownV2)
|
else -> "Unknown :(".escapeMarkdownV2Common()
|
||||||
return@onContentMessage
|
|
||||||
}
|
|
||||||
"Oh, hi, " + when (chat) {
|
|
||||||
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
|
||||||
chat.title.linkMarkdownV2(it)
|
|
||||||
} ?: chat.title
|
|
||||||
else -> bot.getChat(chat).inviteLink ?.let {
|
|
||||||
chat.title.linkMarkdownV2(it)
|
|
||||||
} ?: chat.title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UnknownExtendedChat,
|
|
||||||
is UnknownChatType -> "Unknown :(".escapeMarkdownV2Common()
|
|
||||||
else -> error("Something went wrong: unknown type of chat $chat")
|
|
||||||
}
|
}
|
||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# InlineQueriesBot
|
|
||||||
|
|
||||||
This bot will form the inline queries for you. For that feature you should explicitly enable inline queries in bot settings
|
|
||||||
|
|
||||||
## Launch
|
|
||||||
|
|
||||||
```bash
|
|
||||||
../gradlew run --args="BOT_TOKEN"
|
|
||||||
```
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="InlineQueriesBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
def hostOs = System.getProperty("os.name")
|
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
jvm()
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'io.ktor:ktor-client-logging-jvm:2.3.0'
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLink
|
|
||||||
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
|
||||||
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thi bot will create inline query answers. You
|
|
||||||
* should enable inline queries in bot settings
|
|
||||||
*/
|
|
||||||
suspend fun doInlineQueriesBot(token: String) {
|
|
||||||
val bot = telegramBot(token)
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(
|
|
||||||
defaultExceptionsHandler = { it.printStackTrace() },
|
|
||||||
) {
|
|
||||||
onBaseInlineQuery {
|
|
||||||
val page = it.offset.toIntOrNull() ?: 0
|
|
||||||
val results = (0 until inlineQueryAnswerResultsLimit.last).map {
|
|
||||||
(page * inlineQueryAnswerResultsLimit.last) + it
|
|
||||||
}
|
|
||||||
|
|
||||||
answer(
|
|
||||||
it,
|
|
||||||
results = results.map { resultNumber ->
|
|
||||||
val resultAsString = resultNumber.toString()
|
|
||||||
InlineQueryResultArticle(
|
|
||||||
resultAsString,
|
|
||||||
"Title $resultNumber",
|
|
||||||
InputTextMessageContent(
|
|
||||||
buildEntities {
|
|
||||||
+"Result text of " + resultNumber.toString() + " result:\n"
|
|
||||||
+it.query
|
|
||||||
}
|
|
||||||
),
|
|
||||||
description = "Description of $resultNumber result"
|
|
||||||
)
|
|
||||||
},
|
|
||||||
cachedTime = 0,
|
|
||||||
isPersonal = true,
|
|
||||||
button = InlineQueryResultsButton.Start(
|
|
||||||
"Text of button with page $page",
|
|
||||||
"deep_link_for_page_$page"
|
|
||||||
),
|
|
||||||
nextOffset = (page + 1).toString()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onDeepLink { (message, deepLink) ->
|
|
||||||
reply(message, deepLink)
|
|
||||||
}
|
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
println(getMe())
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
doInlineQueriesBot(args.first())
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
runBlocking {
|
|
||||||
doInlineQueriesBot(args.first())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,20 +3,16 @@ import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.editMessageText
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.botCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
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.InputMessageContent.InputTextMessageContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import dev.inmo.tgbotapi.utils.*
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
private const val nextPageData = "next"
|
private const val nextPageData = "next"
|
||||||
@@ -60,16 +56,6 @@ fun InlineKeyboardBuilder.includePageButtons(page: Int, count: Int) {
|
|||||||
dataButton(">>", "$count $count")
|
dataButton(">>", "$count $count")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
row {
|
|
||||||
inlineQueryInChosenChatButton(
|
|
||||||
"Send somebody page",
|
|
||||||
query = "$page $count",
|
|
||||||
allowUsers = true,
|
|
||||||
allowBots = true,
|
|
||||||
allowGroups = true,
|
|
||||||
allowChannels = true,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun activateKeyboardsBot(
|
suspend fun activateKeyboardsBot(
|
||||||
@@ -85,12 +71,13 @@ suspend fun activateKeyboardsBot(
|
|||||||
val numberOfPages = args.firstOrNull() ?.toIntOrNull() ?: 10
|
val numberOfPages = args.firstOrNull() ?.toIntOrNull() ?: 10
|
||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
|
"Your inline keyboard with $numberOfPages pages",
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
includePageButtons(1, numberOfPages)
|
row {
|
||||||
|
includePageButtons(1, numberOfPages)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
)
|
||||||
regular("Your inline keyboard with $numberOfPages pages")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessageDataCallbackQuery {
|
onMessageDataCallbackQuery {
|
||||||
@@ -99,66 +86,34 @@ suspend fun activateKeyboardsBot(
|
|||||||
return@onMessageDataCallbackQuery
|
return@onMessageDataCallbackQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(
|
val text = "This is $page of $count"
|
||||||
|
|
||||||
|
editMessageText(
|
||||||
it.message.withContent<TextContent>() ?: it.let {
|
it.message.withContent<TextContent>() ?: it.let {
|
||||||
answer(it, "Unsupported message type :(")
|
answer(it, "Unsupported message type :(")
|
||||||
return@onMessageDataCallbackQuery
|
return@onMessageDataCallbackQuery
|
||||||
},
|
},
|
||||||
|
text,
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
includePageButtons(page, count)
|
row {
|
||||||
|
includePageButtons(page, count)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
|
||||||
regular("This is $page of $count")
|
|
||||||
}
|
|
||||||
answer(it)
|
|
||||||
}
|
|
||||||
onInlineMessageIdDataCallbackQuery {
|
|
||||||
val (page, count) = it.data.parsePageAndCount() ?: it.let {
|
|
||||||
answer(it, "Unsupported data :(")
|
|
||||||
return@onInlineMessageIdDataCallbackQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
editMessageText(
|
|
||||||
it.inlineMessageId,
|
|
||||||
replyMarkup = inlineKeyboard {
|
|
||||||
includePageButtons(page, count)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
regular("This is $page of $count")
|
|
||||||
}
|
|
||||||
answer(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
onBaseInlineQuery {
|
|
||||||
val page = it.query.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
|
||||||
val count = it.query.removePrefix(page.toString()).dropWhile { !it.isDigit() }.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
|
||||||
|
|
||||||
answer(
|
|
||||||
it,
|
|
||||||
results = listOf(
|
|
||||||
InlineQueryResultArticle(
|
|
||||||
it.query,
|
|
||||||
"Send buttons",
|
|
||||||
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
|
||||||
replyMarkup = inlineKeyboard {
|
|
||||||
includePageButtons(page, count)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onUnhandledCommand {
|
onUnhandledCommand {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
|
buildEntities {
|
||||||
|
+"Use " + botCommand("inline") + " to get pagination inline keyboard"
|
||||||
|
},
|
||||||
replyMarkup = replyKeyboard(resizeKeyboard = true, oneTimeKeyboard = true) {
|
replyMarkup = replyKeyboard(resizeKeyboard = true, oneTimeKeyboard = true) {
|
||||||
row {
|
row {
|
||||||
simpleButton("/inline")
|
simpleButton("/inline")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
)
|
||||||
+"Use " + botCommand("inline") + " to get pagination inline keyboard"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setMyCommands(BotCommand("inline", "Creates message with pagination inline keyboard"))
|
setMyCommands(BotCommand("inline", "Creates message with pagination inline keyboard"))
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
# LiveLocationsBot
|
|
||||||
|
|
||||||
This bot will send you live location and update it from time to time
|
|
||||||
|
|
||||||
## 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="LiveLocationsBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.EditLiveLocationInfo
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.handleLiveLocation
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.oneOf
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.parallel
|
|
||||||
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.utils.extensions.sameMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard
|
|
||||||
import dev.inmo.tgbotapi.types.chat.*
|
|
||||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
|
||||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
|
||||||
import dev.inmo.tgbotapi.types.chat.SupergroupChat
|
|
||||||
import dev.inmo.tgbotapi.types.location.LiveLocation
|
|
||||||
import dev.inmo.tgbotapi.types.message.MarkdownV2
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.LiveLocationContent
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.LocationContent
|
|
||||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
|
||||||
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.filter
|
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This bot will send you live location and update it from time to time
|
|
||||||
*/
|
|
||||||
suspend fun main(vararg args: String) {
|
|
||||||
val botToken = args.first()
|
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
|
||||||
val locationsFlow = flow {
|
|
||||||
var i = 0
|
|
||||||
while (isActive) {
|
|
||||||
val newInfo = EditLiveLocationInfo(
|
|
||||||
latitude = i.toDouble(),
|
|
||||||
longitude = i.toDouble(),
|
|
||||||
replyMarkup = flatInlineKeyboard {
|
|
||||||
dataButton("Cancel", "cancel")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
emit(newInfo)
|
|
||||||
i++
|
|
||||||
delay(3000L) // 3 seconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onCommand("start") {
|
|
||||||
// in this flow will be actual message with live location
|
|
||||||
val currentMessageState = MutableStateFlow<ContentMessage<LocationContent>?>(null)
|
|
||||||
val sendingJob = launch {
|
|
||||||
handleLiveLocation(
|
|
||||||
it.chat.id,
|
|
||||||
locationsFlow,
|
|
||||||
sentMessageFlow = FlowCollector { currentMessageState.emit(it) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
waitMessageDataCallbackQuery().filter {
|
|
||||||
it.message.sameMessage(
|
|
||||||
currentMessageState.value ?: return@filter false
|
|
||||||
) && it.data == "cancel"
|
|
||||||
}.first()
|
|
||||||
|
|
||||||
sendingJob.cancel() // ends live location
|
|
||||||
currentMessageState.value ?.let {
|
|
||||||
edit(it, replyMarkup = null) // removing reply keyboard
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
|
||||||
}.second.join()
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -4,8 +4,6 @@ This repository contains several examples of simple bots which are using Telegra
|
|||||||
|
|
||||||
## How to use this repository
|
## How to use this repository
|
||||||
|
|
||||||
***TO RUN NATIVE TARGETS ON LINUX YOU SHOULD INSTALL CURL LIBRARY. FOR EXAMPLE: `sudo apt install libcurl4-gnutls-dev`***
|
|
||||||
|
|
||||||
This repository contains several important things:
|
This repository contains several important things:
|
||||||
|
|
||||||
* Example subprojects
|
* Example subprojects
|
||||||
|
|||||||
@@ -8,45 +8,14 @@ buildscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
apply plugin: 'kotlin'
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'application'
|
apply plugin: 'application'
|
||||||
|
|
||||||
mainClassName="RandomFileSenderBotKt"
|
mainClassName="RandomFileSenderBotKt"
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
dependencies {
|
||||||
def hostOs = System.getProperty("os.name")
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
jvm()
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
actual fun pickFile(currentRoot: MPPFile): File? {
|
|
||||||
if (currentRoot.isFile) {
|
|
||||||
return currentRoot
|
|
||||||
} else {
|
|
||||||
return pickFile(currentRoot.listFiles() ?.takeIf { it.isNotEmpty() } ?.random() ?: return null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
doRandomFileSenderBot(args.first(), MPPFile(args.getOrNull(1) ?: ""))
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
import dev.inmo.micro_utils.common.filesize
|
import dev.inmo.micro_utils.common.filesize
|
||||||
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
@@ -7,7 +7,6 @@ import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument
|
|||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocumentsGroup
|
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocumentsGroup
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.withUploadDocumentAction
|
import dev.inmo.tgbotapi.extensions.api.send.withUploadDocumentAction
|
||||||
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommandWithArgs
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||||
@@ -15,11 +14,10 @@ import dev.inmo.tgbotapi.types.BotCommand
|
|||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
import dev.inmo.tgbotapi.types.chat.Chat
|
||||||
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
import dev.inmo.tgbotapi.types.media.TelegramMediaDocument
|
||||||
import dev.inmo.tgbotapi.types.mediaCountInMediaGroup
|
import dev.inmo.tgbotapi.types.mediaCountInMediaGroup
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
private const val command = "send_file"
|
private const val command = "send_file"
|
||||||
|
|
||||||
expect fun pickFile(currentRoot: MPPFile): MPPFile?
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This bot will send files inside of working directory OR from directory in the second argument.
|
* This bot will send files inside of working directory OR from directory in the second argument.
|
||||||
* You may send /send_file command to this bot to get random file from the directory OR
|
* You may send /send_file command to this bot to get random file from the directory OR
|
||||||
@@ -27,10 +25,19 @@ expect fun pickFile(currentRoot: MPPFile): MPPFile?
|
|||||||
* /send_file and `/send_file 1` will have the same effect - bot will send one random file.
|
* /send_file and `/send_file 1` will have the same effect - bot will send one random file.
|
||||||
* But if you will send `/send_file 5` it will choose 5 random files and send them as group
|
* But if you will send `/send_file 5` it will choose 5 random files and send them as group
|
||||||
*/
|
*/
|
||||||
suspend fun doRandomFileSenderBot(token: String, folder: MPPFile) {
|
suspend fun main(args: Array<String>) {
|
||||||
val bot = telegramBot(token)
|
val botToken = args.first()
|
||||||
|
val directoryOrFile = args.getOrNull(1) ?.let { File(it) } ?: File("")
|
||||||
|
|
||||||
suspend fun TelegramBot.sendFiles(chat: Chat, files: List<MPPFile>) {
|
fun pickFile(currentRoot: File = directoryOrFile): File? {
|
||||||
|
if (currentRoot.isFile) {
|
||||||
|
return currentRoot
|
||||||
|
} else {
|
||||||
|
return pickFile(currentRoot.listFiles() ?.takeIf { it.isNotEmpty() } ?.random() ?: return null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun TelegramBot.sendFiles(chat: Chat, files: List<File>) {
|
||||||
when (files.size) {
|
when (files.size) {
|
||||||
1 -> sendDocument(
|
1 -> sendDocument(
|
||||||
chat.id,
|
chat.id,
|
||||||
@@ -45,6 +52,8 @@ suspend fun doRandomFileSenderBot(token: String, folder: MPPFile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val bot = telegramBot(botToken)
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
||||||
onCommandWithArgs(command) { message, args ->
|
onCommandWithArgs(command) { message, args ->
|
||||||
|
|
||||||
@@ -53,10 +62,10 @@ suspend fun doRandomFileSenderBot(token: String, folder: MPPFile) {
|
|||||||
var sent = false
|
var sent = false
|
||||||
|
|
||||||
var left = count
|
var left = count
|
||||||
val chosen = mutableListOf<MPPFile>()
|
val chosen = mutableListOf<File>()
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
val picked = pickFile(folder) ?.takeIf { it.filesize > 0 } ?: continue
|
val picked = pickFile() ?.takeIf { it.filesize > 0 } ?: continue
|
||||||
chosen.add(picked)
|
chosen.add(picked)
|
||||||
left--
|
left--
|
||||||
if (chosen.size >= mediaCountInMediaGroup.last) {
|
if (chosen.size >= mediaCountInMediaGroup.last) {
|
||||||
@@ -72,7 +81,7 @@ suspend fun doRandomFileSenderBot(token: String, folder: MPPFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
reply(message, "Nothing selected :(")
|
bot.reply(message, "Nothing selected :(")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.common.MPPFile
|
|
||||||
import okio.FileSystem
|
|
||||||
|
|
||||||
actual fun pickFile(currentRoot: MPPFile): MPPFile? {
|
|
||||||
if (FileSystem.SYSTEM.exists(currentRoot) && FileSystem.SYSTEM.listOrNull(currentRoot) == null) {
|
|
||||||
return currentRoot
|
|
||||||
} else {
|
|
||||||
return pickFile(FileSystem.SYSTEM.list(currentRoot).takeIf { it.isNotEmpty() } ?.random() ?: return null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import okio.Path.Companion.toPath
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
runBlocking {
|
|
||||||
doRandomFileSenderBot(args.first(), args.getOrNull(1) ?.toPath() ?: "".toPath())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,8 +20,6 @@ kotlin {
|
|||||||
browser()
|
browser()
|
||||||
binaries.executable()
|
binaries.executable()
|
||||||
}
|
}
|
||||||
linuxX64()
|
|
||||||
mingwX64()
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
|
|||||||
@@ -8,37 +8,47 @@ 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.utils.extensions.threadIdOrNull
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
suspend fun activateResenderBot(
|
suspend fun activateResenderBot(
|
||||||
token: String,
|
token: String,
|
||||||
print: (Any) -> Unit
|
print: (Any) -> Unit
|
||||||
) {
|
) {
|
||||||
telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
val bot = telegramBot(token)
|
||||||
|
|
||||||
|
print(bot.getMe())
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||||
onContentMessage(
|
onContentMessage(
|
||||||
subcontextUpdatesFilter = MessageFilterByChat,
|
initialFilter = CommonMessageFilterExcludeMediaGroups,
|
||||||
|
subcontextUpdatesFilter = MessageFilterByChat
|
||||||
) {
|
) {
|
||||||
val chat = it.chat
|
val chat = it.chat
|
||||||
|
withTypingAction(chat) {
|
||||||
val answer = withTypingAction(chat) {
|
executeUnsafe(it.content.createResend(chat.id, replyToMessageId = it.messageId))
|
||||||
executeUnsafe(
|
}
|
||||||
it.content.createResend(
|
}
|
||||||
chat.id,
|
onVisualGallery {
|
||||||
messageThreadId = it.threadIdOrNull,
|
val chat = it.chat ?: return@onVisualGallery
|
||||||
replyToMessageId = it.messageId
|
withUploadPhotoAction(chat) {
|
||||||
)
|
sendVisualMediaGroup(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
) {
|
}
|
||||||
it.forEach(print)
|
}
|
||||||
}
|
onPlaylist {
|
||||||
|
val chat = it.chat ?: return@onPlaylist
|
||||||
|
withUploadDocumentAction(chat) {
|
||||||
|
sendPlaylist(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onDocumentsGroup {
|
||||||
|
val chat = it.chat ?: return@onDocumentsGroup
|
||||||
|
withUploadDocumentAction(chat) {
|
||||||
|
sendDocumentsGroup(chat, it.map { it.content.toMediaGroupMemberTelegramMedia() })
|
||||||
}
|
}
|
||||||
|
|
||||||
println("Answer info: $answer")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||||
println(it)
|
println(it)
|
||||||
}
|
}
|
||||||
print(bot.getMe())
|
}.join()
|
||||||
}.second.join()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
def hostOs = System.getProperty("os.name")
|
|
||||||
def isMingwX64 = hostOs.startsWith("Windows")
|
|
||||||
def nativeTarget
|
|
||||||
if (hostOs == "Linux") nativeTarget = linuxX64("native") { binaries { executable() } }
|
|
||||||
else if (isMingwX64) nativeTarget = mingwX64("native") { binaries { executable() } }
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api project(":ResenderBot:ResenderBotLib")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeMain {
|
|
||||||
dependencies {
|
|
||||||
def engine
|
|
||||||
|
|
||||||
if (hostOs == "Linux") engine = "curl"
|
|
||||||
else if (isMingwX64) engine = "winhttp"
|
|
||||||
else throw new GradleException("Host OS is not supported in Kotlin/Native.")
|
|
||||||
|
|
||||||
api "io.ktor:ktor-client-$engine:$ktor_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
|
|
||||||
fun main(vararg args: String) {
|
|
||||||
runBlocking {
|
|
||||||
activateResenderBot(args.first()) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# RightsChanger
|
|
||||||
|
|
||||||
All the commands should be called with reply to some common user.
|
|
||||||
|
|
||||||
* Use `/simple` with bot to get request buttons for non-independent permissions change
|
|
||||||
* Use `/granular` with bot to get request buttons for independent permissions change
|
|
||||||
|
|
||||||
## Launch
|
|
||||||
|
|
||||||
```bash
|
|
||||||
../gradlew run --args="BOT_TOKEN allowed_user_id_long"
|
|
||||||
```
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="RightsChangerKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.members.getChatMember
|
|
||||||
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.behaviour_builder.BehaviourContext
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMessageDataCallbackQuery
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asPossiblyReplyMessage
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.commonMessageOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.contentMessageOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extendedGroupChatOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.fromUserMessageOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.restrictedChatMemberOrNull
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.whenMemberChatMember
|
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
|
||||||
import dev.inmo.tgbotapi.types.ChatId
|
|
||||||
import dev.inmo.tgbotapi.types.UserId
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
|
||||||
import dev.inmo.tgbotapi.types.chat.ChatPermissions
|
|
||||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
|
||||||
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
|
||||||
import dev.inmo.tgbotapi.utils.row
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
val botToken = args.first()
|
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
|
||||||
|
|
||||||
val allowedAdmin = ChatId(args[1].toLong())
|
|
||||||
|
|
||||||
fun Boolean?.allowedSymbol() = when (this) {
|
|
||||||
true -> "✅"
|
|
||||||
false -> "❌"
|
|
||||||
null -> ""
|
|
||||||
}
|
|
||||||
|
|
||||||
val granularDataPrefix = "granular"
|
|
||||||
val messagesToggleGranularData = "$granularDataPrefix messages"
|
|
||||||
val otherMessagesToggleGranularData = "$granularDataPrefix other messages"
|
|
||||||
val audiosToggleGranularData = "$granularDataPrefix audios"
|
|
||||||
val voicesToggleGranularData = "$granularDataPrefix voices"
|
|
||||||
val videosToggleGranularData = "$granularDataPrefix videos"
|
|
||||||
val videoNotesToggleGranularData = "$granularDataPrefix video notes"
|
|
||||||
val photosToggleGranularData = "$granularDataPrefix photos"
|
|
||||||
val webPagePreviewToggleGranularData = "$granularDataPrefix web page preview"
|
|
||||||
val pollsToggleGranularData = "$granularDataPrefix polls"
|
|
||||||
val documentsToggleGranularData = "$granularDataPrefix documents"
|
|
||||||
|
|
||||||
val commonDataPrefix = "common"
|
|
||||||
val pollsToggleCommonData = "$commonDataPrefix polls"
|
|
||||||
val otherMessagesToggleCommonData = "$commonDataPrefix other messages"
|
|
||||||
val webPagePreviewToggleCommonData = "$commonDataPrefix web page preview"
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.getUserChatPermissions(chatId: ChatId, userId: UserId): ChatPermissions? {
|
|
||||||
val chatMember = getChatMember(chatId, userId)
|
|
||||||
return chatMember.restrictedChatMemberOrNull() ?: chatMember.whenMemberChatMember {
|
|
||||||
getChat(chatId).extendedGroupChatOrNull() ?.permissions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.buildGranularKeyboard(chatId: ChatId, userId: UserId): InlineKeyboardMarkup? {
|
|
||||||
val permissions = getUserChatPermissions(chatId, userId) ?: return null
|
|
||||||
|
|
||||||
return inlineKeyboard {
|
|
||||||
row {
|
|
||||||
dataButton("Send messages${permissions.canSendMessages.allowedSymbol()}", messagesToggleGranularData)
|
|
||||||
dataButton("Send other messages${permissions.canSendOtherMessages.allowedSymbol()}", otherMessagesToggleGranularData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Send audios${permissions.canSendAudios.allowedSymbol()}", audiosToggleGranularData)
|
|
||||||
dataButton("Send voices${permissions.canSendVoiceNotes.allowedSymbol()}", voicesToggleGranularData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Send videos${permissions.canSendVideos.allowedSymbol()}", videosToggleGranularData)
|
|
||||||
dataButton("Send video notes${permissions.canSendVideoNotes.allowedSymbol()}", videoNotesToggleGranularData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Send photos${permissions.canSendPhotos.allowedSymbol()}", photosToggleGranularData)
|
|
||||||
dataButton("Add web preview${permissions.canAddWebPagePreviews.allowedSymbol()}", webPagePreviewToggleGranularData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Send polls${permissions.canSendPolls.allowedSymbol()}", pollsToggleGranularData)
|
|
||||||
dataButton("Send documents${permissions.canSendDocuments.allowedSymbol()}", documentsToggleGranularData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.buildCommonKeyboard(chatId: ChatId, userId: UserId): InlineKeyboardMarkup? {
|
|
||||||
val permissions = getUserChatPermissions(chatId, userId) ?: return null
|
|
||||||
|
|
||||||
return inlineKeyboard {
|
|
||||||
row {
|
|
||||||
dataButton("Send polls${permissions.canSendPolls.allowedSymbol()}", pollsToggleCommonData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Send other messages${permissions.canSendOtherMessages.allowedSymbol()}", otherMessagesToggleCommonData)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
dataButton("Add web preview${permissions.canAddWebPagePreviews.allowedSymbol()}", webPagePreviewToggleCommonData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(
|
|
||||||
defaultExceptionsHandler = {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
onCommand("simple", 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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onCommand("granular", 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 = buildGranularKeyboard(it.chat.id.toChatId(), userInReply) ?: return@onCommand
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessageDataCallbackQuery(
|
|
||||||
Regex("^${granularDataPrefix}.*"),
|
|
||||||
initialFilter = { it.user.id == allowedAdmin }
|
|
||||||
) {
|
|
||||||
val messageReply = it.message.commonMessageOrNull() ?.replyTo ?.fromUserMessageOrNull() ?: return@onMessageDataCallbackQuery
|
|
||||||
val userId = messageReply.user.id
|
|
||||||
val permissions = getUserChatPermissions(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
|
||||||
val newPermission = when (it.data) {
|
|
||||||
messagesToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendMessages = permissions.canSendMessages ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
otherMessagesToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendOtherMessages = permissions.canSendOtherMessages ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
audiosToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendAudios = permissions.canSendAudios ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
voicesToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendVoiceNotes = permissions.canSendVoiceNotes ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
videosToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendVideos = permissions.canSendVideos ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
videoNotesToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendVideoNotes = permissions.canSendVideoNotes ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
photosToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendPhotos = permissions.canSendPhotos ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
webPagePreviewToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canAddWebPagePreviews = permissions.canAddWebPagePreviews ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
pollsToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendPolls = permissions.canSendPolls ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
documentsToggleGranularData -> {
|
|
||||||
permissions.copyGranular(
|
|
||||||
canSendDocuments = permissions.canSendDocuments ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else -> permissions.copyGranular()
|
|
||||||
}
|
|
||||||
|
|
||||||
restrictChatMember(
|
|
||||||
it.message.chat.id,
|
|
||||||
userId,
|
|
||||||
permissions = newPermission,
|
|
||||||
useIndependentChatPermissions = true
|
|
||||||
)
|
|
||||||
|
|
||||||
edit(
|
|
||||||
it.message,
|
|
||||||
replyMarkup = buildGranularKeyboard(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMessageDataCallbackQuery(
|
|
||||||
Regex("^${commonDataPrefix}.*"),
|
|
||||||
initialFilter = { it.user.id == allowedAdmin }
|
|
||||||
) {
|
|
||||||
val messageReply = it.message.commonMessageOrNull() ?.replyTo ?.fromUserMessageOrNull() ?: return@onMessageDataCallbackQuery
|
|
||||||
val userId = messageReply.user.id
|
|
||||||
val permissions = getUserChatPermissions(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
|
||||||
val newPermission = when (it.data) {
|
|
||||||
pollsToggleCommonData -> {
|
|
||||||
permissions.copyCommon(
|
|
||||||
canSendPolls = permissions.canSendPolls ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
otherMessagesToggleCommonData -> {
|
|
||||||
permissions.copyCommon(
|
|
||||||
canSendOtherMessages = permissions.canSendOtherMessages ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
webPagePreviewToggleCommonData -> {
|
|
||||||
permissions.copyCommon(
|
|
||||||
canAddWebPagePreviews = permissions.canAddWebPagePreviews ?.let { !it } ?: false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else -> permissions.copyCommon()
|
|
||||||
}
|
|
||||||
|
|
||||||
restrictChatMember(
|
|
||||||
it.message.chat.id,
|
|
||||||
userId,
|
|
||||||
permissions = newPermission,
|
|
||||||
useIndependentChatPermissions = false
|
|
||||||
)
|
|
||||||
|
|
||||||
edit(
|
|
||||||
it.message,
|
|
||||||
replyMarkup = buildCommonKeyboard(it.message.chat.id.toChatId(), userId) ?: return@onMessageDataCallbackQuery
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
setMyCommands(
|
|
||||||
BotCommand("simple", "Trigger simple keyboard. Use with reply to user"),
|
|
||||||
BotCommand("granular", "Trigger granular keyboard. Use with reply to user"),
|
|
||||||
scope = BotCommandScope.AllGroupChats
|
|
||||||
)
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -17,9 +17,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
|
|
||||||
if (diceType == SlotMachineDiceAnimationType) {
|
if (diceType == SlotMachineDiceAnimationType) {
|
||||||
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
val result = dice.calculateSlotMachineResult() ?: return@onDice
|
||||||
reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
bot.reply(it, "${result.leftReel}|${result.centerReel}|${result.rightReel}")
|
||||||
} else {
|
} else {
|
||||||
reply(it, "There is no slot machine dice in message")
|
bot.reply(it, "There is no slot machine dice in message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.join()
|
}.join()
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
jvm()
|
|
||||||
// js(LEGACY) {
|
|
||||||
js(IR) {
|
|
||||||
browser()
|
|
||||||
binaries.executable()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
commonMain {
|
|
||||||
dependencies {
|
|
||||||
implementation kotlin('stdlib')
|
|
||||||
|
|
||||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
|
||||||
import dev.inmo.tgbotapi.types.StickerFormat
|
|
||||||
import dev.inmo.tgbotapi.types.StickerType
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.*
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.AnimatedStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.CustomEmojiSimpleStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.CustomEmojiStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.CustomEmojiVideoStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.MaskSimpleStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.MaskStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.MaskVideoStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.RegularSimpleStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.RegularStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.RegularVideoStickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
|
||||||
import dev.inmo.tgbotapi.types.stickers.UnknownStickerSet
|
|
||||||
import dev.inmo.tgbotapi.utils.bold
|
|
||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
|
|
||||||
fun StickerSet?.buildInfo() = buildEntities {
|
|
||||||
if (this@buildInfo == null) {
|
|
||||||
bold("Looks like this stickerset has been removed")
|
|
||||||
} else {
|
|
||||||
bold("StickerSet name: ") + "${name}\n"
|
|
||||||
bold("StickerSet title: ") + "${title}\n"
|
|
||||||
bold("Sticker format: ") + when (stickerFormat) {
|
|
||||||
StickerFormat.Animated -> "Animated"
|
|
||||||
StickerFormat.Static -> "Static"
|
|
||||||
is StickerFormat.Unknown -> stickerFormat.type
|
|
||||||
StickerFormat.Video -> "Video"
|
|
||||||
} + "\n"
|
|
||||||
bold(
|
|
||||||
when (stickerType) {
|
|
||||||
StickerType.CustomEmoji -> "Custom emoji"
|
|
||||||
StickerType.Mask -> "Mask"
|
|
||||||
StickerType.Regular -> "Regular"
|
|
||||||
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
|
||||||
}
|
|
||||||
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun activateStickerInfoBot(
|
|
||||||
token: String,
|
|
||||||
print: (Any) -> Unit
|
|
||||||
) {
|
|
||||||
val bot = telegramBot(token)
|
|
||||||
|
|
||||||
print(bot.getMe())
|
|
||||||
|
|
||||||
defaultSafelyWithoutExceptionHandler = {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling(CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
|
||||||
onText {
|
|
||||||
withTypingAction(it.chat) {
|
|
||||||
it.content.textSources.mapNotNull {
|
|
||||||
if (it is CustomEmojiTextSource) {
|
|
||||||
getCustomEmojiStickerOrNull(it.customEmojiId) ?.stickerSetName
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}.distinct().map {
|
|
||||||
getStickerSet(it)
|
|
||||||
}.distinct().flatMap {
|
|
||||||
it.buildInfo() + regular("\n")
|
|
||||||
}.separateForText().map { entities ->
|
|
||||||
reply(it, entities)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onSticker {
|
|
||||||
val stickerSetInfo = getStickerSetOrNull(it.content.media)
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
stickerSetInfo.buildInfo()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import kotlinx.browser.document
|
|
||||||
import kotlinx.coroutines.*
|
|
||||||
import org.w3c.dom.*
|
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.Default)
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
document.addEventListener(
|
|
||||||
"DOMContentLoaded",
|
|
||||||
{
|
|
||||||
val botsContainer = document.getElementById("bots_container") ?: return@addEventListener
|
|
||||||
|
|
||||||
(document.getElementById("bot_token_form") as? HTMLFormElement) ?.onsubmit = {
|
|
||||||
(document.getElementById("bot_token") as? HTMLInputElement) ?.value ?.let { token ->
|
|
||||||
val botContainer = document.createElement("div") as HTMLDivElement
|
|
||||||
botsContainer.append(botContainer)
|
|
||||||
|
|
||||||
val infoDiv = document.createElement("div") as HTMLDivElement
|
|
||||||
botContainer.append(infoDiv)
|
|
||||||
|
|
||||||
scope.launch {
|
|
||||||
activateStickerInfoBot(token) {
|
|
||||||
infoDiv.innerHTML = it.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Resender bot</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<form id="bot_token_form">
|
|
||||||
<input type="text" id="bot_token">
|
|
||||||
<input type="submit" value="Start bot">
|
|
||||||
</form>
|
|
||||||
<div id="start_offer">Type your bot token to the input above to start its work</div>
|
|
||||||
<script type="text/javascript" src="StickerInfoBotLib.js"></script>
|
|
||||||
<div id="bots_container"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
apply plugin: 'application'
|
|
||||||
|
|
||||||
mainClassName="StickerInfoBotJvmKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation project(":StickerInfoBot:StickerInfoBotLib")
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
suspend fun main(args: Array<String>) {
|
|
||||||
activateStickerInfoBot(args.first()) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# StickerSetHandler
|
|
||||||
|
|
||||||
Send sticker to this bot to form your own stickers set. Send /delete to delete this sticker set
|
|
||||||
|
|
||||||
## How to run
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./gradlew run --args="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="StickerSetHandlerBotKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.files.downloadFileToTemp
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getStickerSet
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.stickers.addStickerToSet
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.stickers.createNewStickerSet
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.stickers.deleteStickerSet
|
|
||||||
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.onSticker
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
|
||||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
|
||||||
import dev.inmo.tgbotapi.types.chat.Chat
|
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
|
||||||
import dev.inmo.tgbotapi.types.toChatId
|
|
||||||
import dev.inmo.tgbotapi.utils.botCommand
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send sticker to this bot to form your own stickers set. Send /delete to delete this sticker set
|
|
||||||
*/
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
telegramBotWithBehaviourAndLongPolling(
|
|
||||||
args.first(),
|
|
||||||
scope = CoroutineScope(Dispatchers.IO),
|
|
||||||
defaultExceptionsHandler = {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
val me = getMe()
|
|
||||||
fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username.usernameWithoutAt}"
|
|
||||||
onCommand("start") {
|
|
||||||
reply(it) {
|
|
||||||
botCommand("delete") + " - to clear stickers"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onCommand("delete") {
|
|
||||||
val deleted = runCatchingSafely {
|
|
||||||
deleteStickerSet(it.chat.stickerSetName())
|
|
||||||
}.getOrElse { false }
|
|
||||||
|
|
||||||
if (deleted) {
|
|
||||||
reply(it, "Deleted")
|
|
||||||
} else {
|
|
||||||
reply(it, "Can't delete for some of reason")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onSticker {
|
|
||||||
val stickerSetName = it.chat.stickerSetName()
|
|
||||||
val sticker = it.content.media
|
|
||||||
val newSticker = when (sticker) {
|
|
||||||
is CustomEmojiSticker -> InputSticker.WithKeywords.CustomEmoji(
|
|
||||||
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
|
||||||
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
|
||||||
emptyList()
|
|
||||||
)
|
|
||||||
is MaskSticker -> InputSticker.Mask(
|
|
||||||
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
|
||||||
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
|
||||||
sticker.maskPosition
|
|
||||||
)
|
|
||||||
is RegularSticker -> InputSticker.WithKeywords.Regular(
|
|
||||||
downloadFileToTemp(sticker.fileId).asMultipartFile(),
|
|
||||||
listOf(sticker.emoji ?: "\uD83D\uDE0A"),
|
|
||||||
emptyList()
|
|
||||||
)
|
|
||||||
is UnknownSticker -> return@onSticker
|
|
||||||
}
|
|
||||||
runCatchingSafely {
|
|
||||||
getStickerSet(stickerSetName)
|
|
||||||
}.onSuccess { stickerSet ->
|
|
||||||
addStickerToSet(it.chat.id.toChatId(), stickerSet.name, newSticker).also { _ ->
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
getStickerSet(stickerSetName).stickers.last()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.onFailure { _ ->
|
|
||||||
createNewStickerSet(
|
|
||||||
it.chat.id.toChatId(),
|
|
||||||
stickerSetName,
|
|
||||||
"Sticker set by ${me.firstName}",
|
|
||||||
it.content.media.stickerFormat,
|
|
||||||
listOf(
|
|
||||||
newSticker
|
|
||||||
),
|
|
||||||
(sticker as? CustomEmojiSticker) ?.needsRepainting ?: false
|
|
||||||
).also { _ ->
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
getStickerSet(stickerSetName).stickers.first()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.second.join()
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# HelloBot
|
|
||||||
|
|
||||||
The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
|
||||||
|
|
||||||
## 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="TopicsHandlingKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import dev.inmo.micro_utils.common.repeatOnFailure
|
|
||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.createForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.deleteForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.editForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.editGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.hideGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.reopenGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.forum.unhideGeneralForumTopic
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.flushAccumulatedUpdates
|
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
|
||||||
import dev.inmo.tgbotapi.types.ForumTopic
|
|
||||||
import dev.inmo.tgbotapi.types.commands.BotCommandScope
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
|
|
||||||
suspend fun main(vararg args: String) {
|
|
||||||
telegramBotWithBehaviourAndLongPolling(
|
|
||||||
args.first(),
|
|
||||||
CoroutineScope(Dispatchers.Default),
|
|
||||||
defaultExceptionsHandler = {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
flushAccumulatedUpdates()
|
|
||||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
onCommand("start_test_topics") {
|
|
||||||
val forumTopic = createForumTopic(
|
|
||||||
it.chat,
|
|
||||||
"Test",
|
|
||||||
ForumTopic.GREEN
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "Test topic has been created")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
editForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
forumTopic.messageThreadId,
|
|
||||||
"Test 01"
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "Test topic has changed its name to Test 01")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
closeForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
forumTopic.messageThreadId,
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "Test topic has been closed")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
reopenForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
forumTopic.messageThreadId,
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "Test topic has been reopened")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
deleteForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
forumTopic.messageThreadId,
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "Test topic has been deleted")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
hideGeneralForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "General topic has been hidden")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
unhideGeneralForumTopic(
|
|
||||||
it.chat.id
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "General topic has been shown")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
runCatchingSafely(
|
|
||||||
{ _ ->
|
|
||||||
reopenGeneralForumTopic(
|
|
||||||
it.chat.id
|
|
||||||
)
|
|
||||||
|
|
||||||
closeGeneralForumTopic(
|
|
||||||
it.chat.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
closeGeneralForumTopic(
|
|
||||||
it.chat.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
reply(it, "General topic has been closed")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
reopenGeneralForumTopic(
|
|
||||||
it.chat.id
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "General topic has been opened")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
editGeneralForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
uuid4().toString().take(10)
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "General topic has been renamed")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
editGeneralForumTopic(
|
|
||||||
it.chat.id,
|
|
||||||
"Main topic"
|
|
||||||
)
|
|
||||||
|
|
||||||
reply(it, "General topic has been renamed")
|
|
||||||
|
|
||||||
delay(1000L)
|
|
||||||
}
|
|
||||||
|
|
||||||
setMyCommands(
|
|
||||||
BotCommand("start_test_topics", "start test topics"),
|
|
||||||
scope = BotCommandScope.AllGroupChats
|
|
||||||
)
|
|
||||||
}.second.join()
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# UserChatShared
|
|
||||||
|
|
||||||
Use `/start` with bot to get request buttons. Bot will ask you to choose user/chat from your list and send it to him.
|
|
||||||
|
|
||||||
## 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="UserChatSharedKt"
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
|
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
|
||||||
}
|
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.runCatchingSafely
|
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
|
||||||
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.onUserShared
|
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard
|
|
||||||
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.chat.PrivateChat
|
|
||||||
import dev.inmo.tgbotapi.types.message.textsources.mention
|
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
|
||||||
import dev.inmo.tgbotapi.utils.row
|
|
||||||
|
|
||||||
suspend fun main(args: Array<String>) {
|
|
||||||
val botToken = args.first()
|
|
||||||
|
|
||||||
val bot = telegramBot(botToken)
|
|
||||||
|
|
||||||
val requestIdUserOrBot = RequestId(0)
|
|
||||||
val requestIdUserNonPremium = RequestId(1)
|
|
||||||
val requestIdUserAny = RequestId(2)
|
|
||||||
val requestIdUserPremium = RequestId(3)
|
|
||||||
val requestIdBot = RequestId(4)
|
|
||||||
|
|
||||||
val requestIdAnyChat = RequestId(5)
|
|
||||||
val requestIdChannel = RequestId(6)
|
|
||||||
val requestIdPublicChannel = RequestId(7)
|
|
||||||
val requestIdPrivateChannel = RequestId(8)
|
|
||||||
val requestIdChannelUserOwner = RequestId(9)
|
|
||||||
|
|
||||||
val requestIdGroup = RequestId(10)
|
|
||||||
val requestIdPublicGroup = RequestId(11)
|
|
||||||
val requestIdPrivateGroup = RequestId(12)
|
|
||||||
val requestIdGroupUserOwner = RequestId(13)
|
|
||||||
|
|
||||||
val requestIdForum = RequestId(14)
|
|
||||||
val requestIdPublicForum = RequestId(15)
|
|
||||||
val requestIdPrivateForum = RequestId(16)
|
|
||||||
val requestIdForumUserOwner = RequestId(17)
|
|
||||||
|
|
||||||
val keyboard = replyKeyboard(
|
|
||||||
resizeKeyboard = true,
|
|
||||||
) {
|
|
||||||
row {
|
|
||||||
requestUserOrBotButton(
|
|
||||||
"\uD83D\uDC64/\uD83E\uDD16",
|
|
||||||
requestIdUserOrBot
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestUserButton(
|
|
||||||
"\uD83D\uDC64☆",
|
|
||||||
requestIdUserNonPremium,
|
|
||||||
premiumUser = false
|
|
||||||
)
|
|
||||||
requestUserButton(
|
|
||||||
"\uD83D\uDC64",
|
|
||||||
requestIdUserAny,
|
|
||||||
premiumUser = null
|
|
||||||
)
|
|
||||||
requestUserButton(
|
|
||||||
"\uD83D\uDC64★",
|
|
||||||
requestIdUserPremium,
|
|
||||||
premiumUser = true
|
|
||||||
)
|
|
||||||
requestBotButton(
|
|
||||||
"\uD83E\uDD16",
|
|
||||||
requestIdBot
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestChatButton(
|
|
||||||
"\uD83D\uDDE3/\uD83D\uDC65",
|
|
||||||
requestIdAnyChat
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestChatButton(
|
|
||||||
"\uD83D\uDDE3",
|
|
||||||
requestIdChannel,
|
|
||||||
isChannel = true
|
|
||||||
)
|
|
||||||
requestChatButton(
|
|
||||||
"\uD83D\uDDE3\uD83D\uDD17",
|
|
||||||
requestIdPublicChannel,
|
|
||||||
isChannel = true,
|
|
||||||
isPublic = true
|
|
||||||
)
|
|
||||||
requestChatButton(
|
|
||||||
"\uD83D\uDDE3❌\uD83D\uDD17",
|
|
||||||
requestIdPrivateChannel,
|
|
||||||
isChannel = true,
|
|
||||||
isPublic = false
|
|
||||||
)
|
|
||||||
requestChatButton(
|
|
||||||
"\uD83D\uDDE3\uD83D\uDC6E",
|
|
||||||
requestIdChannelUserOwner,
|
|
||||||
isChannel = true,
|
|
||||||
isOwnedBy = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestGroupButton(
|
|
||||||
"👥",
|
|
||||||
requestIdGroup
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"👥\uD83D\uDD17",
|
|
||||||
requestIdPublicGroup,
|
|
||||||
isPublic = true
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"👥❌\uD83D\uDD17",
|
|
||||||
requestIdPrivateGroup,
|
|
||||||
isPublic = false
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"👥\uD83D\uDC6E",
|
|
||||||
requestIdGroupUserOwner,
|
|
||||||
isOwnedBy = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
row {
|
|
||||||
requestGroupButton(
|
|
||||||
"🏛",
|
|
||||||
requestIdForum,
|
|
||||||
isForum = true
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"🏛\uD83D\uDD17",
|
|
||||||
requestIdPublicForum,
|
|
||||||
isPublic = true,
|
|
||||||
isForum = true
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"🏛❌\uD83D\uDD17",
|
|
||||||
requestIdPrivateForum,
|
|
||||||
isPublic = false,
|
|
||||||
isForum = true
|
|
||||||
)
|
|
||||||
requestGroupButton(
|
|
||||||
"🏛\uD83D\uDC6E",
|
|
||||||
requestIdForumUserOwner,
|
|
||||||
isOwnedBy = true,
|
|
||||||
isForum = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.buildBehaviourWithLongPolling (defaultExceptionsHandler = { it.printStackTrace() }) {
|
|
||||||
onCommand("start", initialFilter = { it.chat is PrivateChat }) {
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
"Here possible requests buttons:",
|
|
||||||
replyMarkup = keyboard
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onUserShared {
|
|
||||||
val userId = it.chatEvent.userId
|
|
||||||
val userInfo = runCatchingSafely { getChat(userId) }.getOrNull()
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
) {
|
|
||||||
+"You have shared "
|
|
||||||
+mention(
|
|
||||||
when (it.chatEvent.requestId) {
|
|
||||||
requestIdUserOrBot -> "user or bot"
|
|
||||||
requestIdUserNonPremium -> "non premium user"
|
|
||||||
requestIdUserAny -> "any user"
|
|
||||||
requestIdUserPremium -> "premium user"
|
|
||||||
requestIdBot -> "bot"
|
|
||||||
else -> "somebody O.o"
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
+" (user info: $userInfo; user id: $userId)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onChatShared {
|
|
||||||
val chatId = it.chatEvent.chatId
|
|
||||||
val chatInfo = runCatchingSafely { getChat(chatId) }.getOrNull()
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
) {
|
|
||||||
+"You have shared "
|
|
||||||
+when (it.chatEvent.requestId) {
|
|
||||||
requestIdAnyChat -> "some chat"
|
|
||||||
requestIdChannel -> "any channel"
|
|
||||||
requestIdPublicChannel -> "public channel"
|
|
||||||
requestIdPrivateChannel -> "private channel"
|
|
||||||
requestIdChannelUserOwner -> "channel owned by you"
|
|
||||||
requestIdGroup -> "any group"
|
|
||||||
requestIdPublicGroup -> "public group"
|
|
||||||
requestIdPrivateGroup -> "private group"
|
|
||||||
requestIdGroupUserOwner -> "group owned by you"
|
|
||||||
requestIdForum -> "any forum"
|
|
||||||
requestIdPublicForum -> "public forum"
|
|
||||||
requestIdPrivateForum -> "private forum"
|
|
||||||
requestIdForumUserOwner -> "forum owned by you"
|
|
||||||
else -> "some chat O.o"
|
|
||||||
}
|
|
||||||
+" (chat info: $chatInfo; chat id: $chatId)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setMyCommands(BotCommand("start", "Trigger buttons"))
|
|
||||||
}.join()
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,6 @@ What is there in this module:
|
|||||||
|
|
||||||
## How to run
|
## How to run
|
||||||
|
|
||||||
```bash
|
```kotlin
|
||||||
./gradlew run --args="TOKEN WEB_APP_ADDRESS"
|
./gradlew run --args="TOKEN WEB_APP_ADDRESS"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.webapps.*
|
import dev.inmo.tgbotapi.webapps.*
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackStyle
|
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackType
|
|
||||||
import dev.inmo.tgbotapi.webapps.popup.*
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
@@ -18,8 +15,8 @@ import kotlinx.serialization.json.Json
|
|||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
|
|
||||||
fun HTMLElement.log(text: String) {
|
fun HTMLElement.log(text: String) {
|
||||||
appendText(text)
|
|
||||||
appendElement("p", {})
|
appendElement("p", {})
|
||||||
|
appendText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
@@ -42,17 +39,13 @@ fun main() {
|
|||||||
}
|
}
|
||||||
val dataIsSafe = response.bodyAsText().toBoolean()
|
val dataIsSafe = response.bodyAsText().toBoolean()
|
||||||
|
|
||||||
document.body ?.log(
|
document.body ?.appendElement("div") {
|
||||||
if (dataIsSafe) {
|
textContent = if (dataIsSafe) {
|
||||||
"Data is safe"
|
"Data is safe"
|
||||||
} else {
|
} else {
|
||||||
"Data is unsafe"
|
"Data is unsafe"
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
document.body ?.log(
|
|
||||||
webApp.initDataUnsafe.chat.toString()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
document.body ?.appendElement("button") {
|
||||||
@@ -69,79 +62,6 @@ fun main() {
|
|||||||
})
|
})
|
||||||
appendText("Example button")
|
appendText("Example button")
|
||||||
} ?: window.alert("Unable to load body")
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
document.body ?.appendText("Alerts:")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showPopup(
|
|
||||||
PopupParams(
|
|
||||||
"It is sample title of default button",
|
|
||||||
"It is sample message of default button",
|
|
||||||
DefaultPopupButton("default", "Default button"),
|
|
||||||
OkPopupButton("ok"),
|
|
||||||
DestructivePopupButton("destructive", "Destructive button")
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
when (it) {
|
|
||||||
"default" -> "You have clicked default button in popup"
|
|
||||||
"ok" -> "You have clicked ok button in popup"
|
|
||||||
"destructive" -> "You have clicked destructive button in popup"
|
|
||||||
else -> "I can't imagine where you take button with id $it"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Popup")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showAlert(
|
|
||||||
"This is alert message"
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
"You have closed alert"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Alert")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.showConfirm(
|
|
||||||
"This is confirm message"
|
|
||||||
) {
|
|
||||||
document.body ?.log(
|
|
||||||
"You have pressed \"${if (it) "Ok" else "Cancel"}\" in confirm"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
appendText("Confirm")
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
|
||||||
fun updateText() {
|
|
||||||
textContent = if (webApp.isClosingConfirmationEnabled) {
|
|
||||||
"Disable closing confirmation"
|
|
||||||
} else {
|
|
||||||
"Enable closing confirmation"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addEventListener("click", {
|
|
||||||
webApp.toggleClosingConfirmation()
|
|
||||||
updateText()
|
|
||||||
})
|
|
||||||
updateText()
|
|
||||||
} ?: window.alert("Unable to load body")
|
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
|
|
||||||
webApp.apply {
|
webApp.apply {
|
||||||
onThemeChanged {
|
onThemeChanged {
|
||||||
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
||||||
@@ -149,28 +69,6 @@ fun main() {
|
|||||||
onViewportChanged {
|
onViewportChanged {
|
||||||
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
||||||
}
|
}
|
||||||
backButton.apply {
|
|
||||||
onClick {
|
|
||||||
document.body ?.log("Back button clicked")
|
|
||||||
hapticFeedback.impactOccurred(
|
|
||||||
HapticFeedbackStyle.Heavy
|
|
||||||
)
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
mainButton.apply {
|
|
||||||
setText("Main button")
|
|
||||||
onClick {
|
|
||||||
document.body ?.log("Main button clicked")
|
|
||||||
hapticFeedback.notificationOccurred(
|
|
||||||
HapticFeedbackType.Success
|
|
||||||
)
|
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
onSettingsButtonClicked {
|
|
||||||
document.body ?.log("Settings button clicked")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
webApp.ready()
|
webApp.ready()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.micro_utils.crypto.hmacSha256
|
||||||
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
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach
|
import dev.inmo.tgbotapi.extensions.utils.formatting.botCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.buildEntities
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
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.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.PreviewFeature
|
||||||
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.call
|
import io.ktor.server.application.call
|
||||||
import io.ktor.server.http.content.*
|
import io.ktor.server.http.content.*
|
||||||
@@ -46,13 +47,14 @@ suspend fun main(vararg args: String) {
|
|||||||
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
val bot = telegramBot(telegramBotAPIUrlsKeeper)
|
||||||
createKtorServer(
|
createKtorServer(
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
args.getOrNull(2) ?.toIntOrNull() ?: 8080,
|
8080,
|
||||||
additionalEngineEnvironmentConfigurator = {
|
additionalEngineEnvironmentConfigurator = {
|
||||||
parentCoroutineContext += Dispatchers.IO
|
parentCoroutineContext += Dispatchers.IO
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
routing {
|
routing {
|
||||||
staticFiles("", File("WebApp/build/distributions")) {
|
static {
|
||||||
|
files(File("WebApp/build/distributions"))
|
||||||
default("WebApp/build/distributions/index.html")
|
default("WebApp/build/distributions/index.html")
|
||||||
}
|
}
|
||||||
post("inline") {
|
post("inline") {
|
||||||
@@ -76,7 +78,6 @@ suspend fun main(vararg args: String) {
|
|||||||
bot.buildBehaviourWithLongPolling(
|
bot.buildBehaviourWithLongPolling(
|
||||||
defaultExceptionsHandler = { it.printStackTrace() }
|
defaultExceptionsHandler = { it.printStackTrace() }
|
||||||
) {
|
) {
|
||||||
val me = getMe()
|
|
||||||
onCommand("reply_markup") {
|
onCommand("reply_markup") {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
@@ -101,27 +102,6 @@ suspend fun main(vararg args: String) {
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onCommand("attachment_menu") {
|
|
||||||
reply(
|
|
||||||
it,
|
|
||||||
"Button",
|
|
||||||
replyMarkup = inlineKeyboard {
|
|
||||||
row {
|
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onBaseInlineQuery {
|
|
||||||
answerInlineQuery(
|
|
||||||
it,
|
|
||||||
button = InlineQueryResultsButton.invoke(
|
|
||||||
"Open webApp",
|
|
||||||
WebAppInfo(args[1])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onUnhandledCommand {
|
onUnhandledCommand {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
@@ -131,9 +111,6 @@ suspend fun main(vararg args: String) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onWriteAccessAllowed(initialFilter = { it.chatEvent.webAppName != null }) {
|
|
||||||
send(it.chat, "Thanks for adding ${it.chatEvent.webAppName} to the attachment menu")
|
|
||||||
}
|
|
||||||
setMyCommands(
|
setMyCommands(
|
||||||
BotCommand("reply_markup", "Use to get reply markup keyboard with web app trigger"),
|
BotCommand("reply_markup", "Use to get reply markup keyboard with web app trigger"),
|
||||||
BotCommand("inline", "Use to get inline keyboard with web app trigger"),
|
BotCommand("inline", "Use to get inline keyboard with web app trigger"),
|
||||||
|
|||||||
@@ -22,7 +22,5 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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=-Xmx2g
|
org.gradle.jvmargs=-Xmx768m
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.8.21
|
kotlin_version=1.7.0
|
||||||
telegram_bot_api_version=7.1.1
|
telegram_bot_api_version=2.0.3
|
||||||
micro_utils_version=0.18.0
|
micro_utils_version=0.11.0
|
||||||
serialization_version=1.5.0
|
serialization_version=1.3.3
|
||||||
ktor_version=2.3.0
|
ktor_version=2.0.2
|
||||||
|
|||||||
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-7.6.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
|
|||||||
@@ -6,36 +6,16 @@ include ":HelloBot"
|
|||||||
|
|
||||||
include ":GetMeBot"
|
include ":GetMeBot"
|
||||||
|
|
||||||
include ":DeepLinksBot"
|
|
||||||
|
|
||||||
include ":FilesLoaderBot"
|
include ":FilesLoaderBot"
|
||||||
|
|
||||||
include ":ResenderBot:ResenderBotLib"
|
include ":ResenderBot:ResenderBotLib"
|
||||||
include ":ResenderBot:jvm_launcher"
|
include ":ResenderBot:jvm_launcher"
|
||||||
include ":ResenderBot:native_launcher"
|
|
||||||
|
|
||||||
include ":KeyboardsBot:KeyboardsBotLib"
|
include ":KeyboardsBot:KeyboardsBotLib"
|
||||||
include ":KeyboardsBot:jvm_launcher"
|
include ":KeyboardsBot:jvm_launcher"
|
||||||
|
|
||||||
include ":StickerInfoBot:StickerInfoBotLib"
|
|
||||||
include ":StickerInfoBot:jvm_launcher"
|
|
||||||
|
|
||||||
include ":SlotMachineDetectorBot"
|
include ":SlotMachineDetectorBot"
|
||||||
|
|
||||||
include ":ChatAvatarSetter"
|
|
||||||
|
|
||||||
include ":WebApp"
|
include ":WebApp"
|
||||||
|
|
||||||
include ":FSMBot"
|
include ":FSMBot"
|
||||||
|
|
||||||
include ":TopicsHandling"
|
|
||||||
|
|
||||||
include ":UserChatShared"
|
|
||||||
|
|
||||||
include ":RightsChangerBot"
|
|
||||||
|
|
||||||
include ":LiveLocationsBot"
|
|
||||||
|
|
||||||
include ":StickerSetHandler"
|
|
||||||
|
|
||||||
include ":InlineQueriesBot"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user