From f515c7548bbde213ceeaba58814f6b1c4942a6fc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 13 Nov 2020 11:23:35 +0600 Subject: [PATCH 1/2] start 0.0.3 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0974c8f..4b1c67a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.0.3 + ## 0.0.2 * `Versions` diff --git a/gradle.properties b/gradle.properties index 0d387ec..ed7fdb7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,4 @@ gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 group=dev.inmo -version=0.0.2 +version=0.0.3 From b4106d771065980cda4c4be5198d93bf29d28556 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 13 Nov 2020 11:25:04 +0600 Subject: [PATCH 2/2] initPlaguBot --- CHANGELOG.md | 3 +++ bot/src/main/kotlin/dev/inmo/plagubot/App.kt | 27 ++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1c67a..1f5c375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.0.3 +* `Bot`: + * New function `initPlaguBot` which actually will launch the bot + ## 0.0.2 * `Versions` diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/App.kt b/bot/src/main/kotlin/dev/inmo/plagubot/App.kt index 6e45fbe..005d811 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/App.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/App.kt @@ -11,17 +11,10 @@ import kotlinx.coroutines.* import kotlinx.serialization.InternalSerializationApi import java.io.File -/** - * This method by default expects one argument in [args] field: path to config - */ -@InternalSerializationApi -suspend fun main(args: Array) { - val (configPath) = args - val file = File(configPath) - val config = configSerialFormat.decodeFromString(Config.serializer(), file.readText()) - - val scope = CoroutineScope(Dispatchers.Default) - +suspend inline fun initPlaguBot( + config: Config, + scope: CoroutineScope = CoroutineScope(Dispatchers.Default) +) { val bot = telegramBot(config.botToken) bot.startGettingFlowsUpdatesByLongPolling(scope = scope) { @@ -41,6 +34,18 @@ suspend fun main(args: Array) { } } } +} +/** + * This method by default expects one argument in [args] field: path to config + */ +@InternalSerializationApi +suspend fun main(args: Array) { + val (configPath) = args + val file = File(configPath) + val config = configSerialFormat.decodeFromString(Config.serializer(), file.readText()) + + val scope = CoroutineScope(Dispatchers.Default) + initPlaguBot(config, scope) scope.coroutineContext.job.join() }