mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-12-22 08:37:18 +00:00
fixes and improvements
This commit is contained in:
parent
b660bf5f42
commit
c04a367375
@ -1,4 +1,5 @@
|
||||
import dev.inmo.micro_utils.coroutines.AccumulatorFlow
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.fsm.common.State
|
||||
import dev.inmo.tgbotapi.extensions.api.send.send
|
||||
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
||||
@ -8,6 +9,8 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.textContentOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||
@ -54,7 +57,8 @@ suspend fun main(args: Array<String>) {
|
||||
val content = contentMessage.content
|
||||
|
||||
when {
|
||||
content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context)
|
||||
content is TextContent && content.text == "/stop"
|
||||
|| content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context)
|
||||
else -> {
|
||||
execute(content.createResend(it.context))
|
||||
it
|
||||
@ -72,5 +76,17 @@ suspend fun main(args: Array<String>) {
|
||||
) {
|
||||
startChain(ExpectContentOrStopState(it.chat.id, it))
|
||||
}
|
||||
|
||||
onContentMessage(
|
||||
{
|
||||
it.content.textContentOrNull() ?.text == "/start"
|
||||
}
|
||||
) {
|
||||
startChain(ExpectContentOrStopState(it.chat.id, it.withContentOrNull() ?: return@onContentMessage))
|
||||
}
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
println(it)
|
||||
}
|
||||
}.second.join()
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.shortcuts.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.quoteEntitiesField
|
||||
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
|
||||
@ -22,6 +23,7 @@ suspend fun activateResenderBot(
|
||||
telegramBotWithBehaviourAndLongPolling(token, scope = CoroutineScope(currentCoroutineContext() + SupervisorJob())) {
|
||||
onContentMessage(
|
||||
subcontextUpdatesFilter = MessageFilterByChat,
|
||||
initialFilter = { it !is BusinessContentMessage<*> || !it.sentByBusinessConnectionOwner }
|
||||
) {
|
||||
val chat = it.chat
|
||||
|
||||
|
@ -83,7 +83,7 @@ suspend fun main(args: Array<String>) {
|
||||
getStickerSet(stickerSetName).stickers.last()
|
||||
)
|
||||
}
|
||||
}.onFailure { _ ->
|
||||
}.onFailure { exception ->
|
||||
createNewStickerSet(
|
||||
it.chat.id.toChatId(),
|
||||
stickerSetName.string,
|
||||
|
Loading…
Reference in New Issue
Block a user