diff --git a/CustomBot/README.md b/CustomBot/README.md new file mode 100644 index 0000000..13b72ef --- /dev/null +++ b/CustomBot/README.md @@ -0,0 +1,9 @@ +# CustomBot + +This bot basically have no any useful behaviour, but you may customize it as a playground + +## Launch + +```bash +../gradlew run --args="BOT_TOKEN" +``` diff --git a/CustomBot/build.gradle b/CustomBot/build.gradle new file mode 100644 index 0000000..fdbd23c --- /dev/null +++ b/CustomBot/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'application' + +mainClassName="CustomBotKt" + + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" +} diff --git a/CustomBot/src/main/kotlin/CustomBot.kt b/CustomBot/src/main/kotlin/CustomBot.kt new file mode 100644 index 0000000..45d3861 --- /dev/null +++ b/CustomBot/src/main/kotlin/CustomBot.kt @@ -0,0 +1,33 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling +import dev.inmo.tgbotapi.utils.PreviewFeature +import kotlinx.coroutines.* + +/** + * The main purpose of this bot is just to answer "Oh, hi, " and add user mention here + */ +@OptIn(PreviewFeature::class) +suspend fun main(vararg args: String) { + val botToken = args.first() + + val isDebug = args.any { it == "debug" } + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + + telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) { + val me = getMe() + + allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) } + }.second.join() +} diff --git a/settings.gradle b/settings.gradle index 57b91bf..ba16eb9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -49,3 +49,5 @@ include ":LinkPreviewsBot" include ":BoostsInfoBot" include ":BusinessConnectionsBot" + +include ":CustomBot"