mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-04-19 16:32:25 +00:00
Compare commits
1 Commits
7.1.0
...
526105b70b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
526105b70b |
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,5 +1,16 @@
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.chat.forum.closeForumTopic
|
||||||
|
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.reopenForumTopic
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviour
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onForumTopicClosed
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.types.CustomEmojiId
|
||||||
|
import dev.inmo.tgbotapi.types.ForumTopic
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is one of the most easiest bot - it will just print information about itself
|
* This is one of the most easiest bot - it will just print information about itself
|
||||||
|
|||||||
@@ -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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,17 +4,12 @@ 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.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.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.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 dev.inmo.tgbotapi.utils.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@@ -60,16 +55,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(
|
||||||
@@ -86,7 +71,9 @@ suspend fun activateKeyboardsBot(
|
|||||||
reply(
|
reply(
|
||||||
message,
|
message,
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
includePageButtons(1, numberOfPages)
|
row {
|
||||||
|
includePageButtons(1, numberOfPages)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
regular("Your inline keyboard with $numberOfPages pages")
|
regular("Your inline keyboard with $numberOfPages pages")
|
||||||
@@ -105,48 +92,15 @@ suspend fun activateKeyboardsBot(
|
|||||||
return@onMessageDataCallbackQuery
|
return@onMessageDataCallbackQuery
|
||||||
},
|
},
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
includePageButtons(page, count)
|
row {
|
||||||
|
includePageButtons(page, count)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
regular("This is $page of $count")
|
regular("This is $page of $count")
|
||||||
}
|
}
|
||||||
answer(it)
|
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(
|
||||||
|
|||||||
@@ -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,25 +1,23 @@
|
|||||||
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
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.media.sendDocument
|
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.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
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
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.files.DocumentFile
|
||||||
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) {
|
||||||
@@ -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 {
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ 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,
|
subcontextUpdatesFilter = MessageFilterByChat,
|
||||||
) {
|
) {
|
||||||
@@ -39,6 +43,5 @@ suspend fun activateResenderBot(
|
|||||||
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,16 +1,13 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
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.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
|
||||||
@@ -46,13 +43,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 +74,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 +98,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 +107,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"),
|
||||||
|
|||||||
@@ -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=-Xmx1g
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.8.20
|
kotlin_version=1.8.10
|
||||||
telegram_bot_api_version=7.1.0
|
telegram_bot_api_version=7.0.1
|
||||||
micro_utils_version=0.17.8
|
micro_utils_version=0.17.8
|
||||||
serialization_version=1.5.0
|
serialization_version=1.5.0
|
||||||
ktor_version=2.3.0
|
ktor_version=2.2.4
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ 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"
|
||||||
@@ -37,5 +36,3 @@ include ":RightsChangerBot"
|
|||||||
include ":LiveLocationsBot"
|
include ":LiveLocationsBot"
|
||||||
|
|
||||||
include ":StickerSetHandler"
|
include ":StickerSetHandler"
|
||||||
|
|
||||||
include ":InlineQueriesBot"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user