From 6f74e6b4cbe97f9f16c6904eb171e635feb25065 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 13 Aug 2022 20:37:17 +0600 Subject: [PATCH] fill readme + rename fallback state handler --- README.md | 25 +++++++++++++++++++ .../main/kotlin/dev/inmo/plagubot/PlaguBot.kt | 2 +- .../plagubot/config/FallbackStateHandler.kt | 3 --- .../config/StateHandlingErrorHandler.kt | 3 +++ 4 files changed, 29 insertions(+), 4 deletions(-) delete mode 100644 bot/src/main/kotlin/dev/inmo/plagubot/config/FallbackStateHandler.kt create mode 100644 bot/src/main/kotlin/dev/inmo/plagubot/config/StateHandlingErrorHandler.kt diff --git a/README.md b/README.md index b867809..4386187 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,28 @@ You can create your bot using That is a set of libraries for plagubots. Look at the [PlaguBot Plugin template](https://insanusmokrassar.github.io/PlaguBotPluginTemplate/) to find how to create your bot. + +### Technical help + +In this bot has been used variant with FSM. That means that you may use all the [Behaviour Builder with FSM](https://bookstack.inmo.dev/books/telegrambotapi/page/behaviour-builder-with-fsm) functionality. In case you wish to setup states repo, you should use the next code in the `setupDI` of your plugin: + +```kotlin +single> { + // setup your manager and return here + // Default is: + DefaultStatesManager( + InMemoryDefaultStatesManagerRepo() + ) +} +``` + +Besides, you may setup handling errors lambda in the same function: + +```kotlin +single> { + { state, e -> + logger.eS(e) { "Unable to handle state $state" } // logging by default + null // you should return new state or null, default callback will return null + } +} +``` diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt b/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt index 8f721bf..8fcdb1f 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt @@ -104,7 +104,7 @@ data class PlaguBot( statesManager = koinApp.koin.getOrNull>() ?: DefaultStatesManager( InMemoryDefaultStatesManagerRepo() ), - onStateHandlingErrorHandler = koinApp.koin.getOrNull>() ?: { state, e -> + onStateHandlingErrorHandler = koinApp.koin.getOrNull>() ?: { state, e -> logger.eS(e) { "Unable to handle state $state" } null } diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/config/FallbackStateHandler.kt b/bot/src/main/kotlin/dev/inmo/plagubot/config/FallbackStateHandler.kt deleted file mode 100644 index 05d944f..0000000 --- a/bot/src/main/kotlin/dev/inmo/plagubot/config/FallbackStateHandler.kt +++ /dev/null @@ -1,3 +0,0 @@ -package dev.inmo.plagubot.config - -typealias FallbackStateHandler = suspend (T, Throwable) -> T? diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/config/StateHandlingErrorHandler.kt b/bot/src/main/kotlin/dev/inmo/plagubot/config/StateHandlingErrorHandler.kt new file mode 100644 index 0000000..14b136d --- /dev/null +++ b/bot/src/main/kotlin/dev/inmo/plagubot/config/StateHandlingErrorHandler.kt @@ -0,0 +1,3 @@ +package dev.inmo.plagubot.config + +typealias StateHandlingErrorHandler = suspend (T, Throwable) -> T?