mirror of
https://github.com/InsanusMokrassar/TelegramBotTutorial.git
synced 2024-12-22 14:17:12 +00:00
small refactor of welcome plugin
This commit is contained in:
parent
47a762c8ba
commit
c6dad9105e
@ -10,10 +10,9 @@ import dev.inmo.tgbotapi.extensions.api.answers.answer
|
|||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators
|
||||||
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
import dev.inmo.tgbotapi.extensions.api.edit.edit
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitMessageDataCallbackQuery
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.oneOf
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.*
|
import dev.inmo.tgbotapi.extensions.utils.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
@ -93,34 +92,31 @@ class WelcomePlugin : Plugin {
|
|||||||
)
|
)
|
||||||
|
|
||||||
oneOf(
|
oneOf(
|
||||||
async {
|
parallel {
|
||||||
val query = waitMessageDataCallbackQuery().filter {
|
val query = waitMessageDataCallbackQuery().filter {
|
||||||
it.data == unsetData
|
it.data == unsetData
|
||||||
&& it.message.chat.id == sentMessage.chat.id
|
&& it.message.chat.id == sentMessage.chat.id
|
||||||
&& it.message.messageId == sentMessage.messageId
|
&& it.message.messageId == sentMessage.messageId
|
||||||
}.first()
|
}.first()
|
||||||
|
|
||||||
|
val answerEntities = buildEntities {
|
||||||
if (welcomeTable.unset(groupMessage.chat.id)) {
|
if (welcomeTable.unset(groupMessage.chat.id)) {
|
||||||
edit(
|
|
||||||
sentMessage,
|
|
||||||
buildEntities {
|
|
||||||
regular("Welcome message has been removed for chat ")
|
regular("Welcome message has been removed for chat ")
|
||||||
underline(groupMessage.chat.title)
|
underline(groupMessage.chat.title)
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
edit(
|
|
||||||
sentMessage,
|
|
||||||
buildEntities {
|
|
||||||
regular("Something went wrong on welcome message unsetting for chat ")
|
regular("Something went wrong on welcome message unsetting for chat ")
|
||||||
underline(groupMessage.chat.title)
|
underline(groupMessage.chat.title)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edit(
|
||||||
|
sentMessage,
|
||||||
|
answerEntities
|
||||||
|
)
|
||||||
|
|
||||||
answer(query)
|
answer(query)
|
||||||
},
|
},
|
||||||
async {
|
parallel {
|
||||||
val query = waitMessageDataCallbackQuery().filter {
|
val query = waitMessageDataCallbackQuery().filter {
|
||||||
it.data == cancelData
|
it.data == cancelData
|
||||||
&& it.message.chat.id == sentMessage.chat.id
|
&& it.message.chat.id == sentMessage.chat.id
|
||||||
@ -137,7 +133,7 @@ class WelcomePlugin : Plugin {
|
|||||||
|
|
||||||
answer(query)
|
answer(query)
|
||||||
},
|
},
|
||||||
async {
|
parallel {
|
||||||
val message = waitContentMessage().filter {
|
val message = waitContentMessage().filter {
|
||||||
it.chat.id == sentMessage.chat.id
|
it.chat.id == sentMessage.chat.id
|
||||||
}.first()
|
}.first()
|
||||||
@ -150,27 +146,23 @@ class WelcomePlugin : Plugin {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val entities = buildEntities {
|
||||||
if (success) {
|
if (success) {
|
||||||
reply(
|
|
||||||
message,
|
|
||||||
buildEntities {
|
|
||||||
regular("Welcome message has been changed for chat ")
|
regular("Welcome message has been changed for chat ")
|
||||||
underline(groupMessage.chat.title)
|
underline(groupMessage.chat.title)
|
||||||
regular(".\n\n")
|
regular(".\n\n")
|
||||||
bold("Please, do not delete this message if you want it to work and don't stop this bot to keep welcome message works right")
|
bold("Please, do not delete this message if you want it to work and don't stop this bot to keep welcome message works right")
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
reply(
|
|
||||||
message,
|
|
||||||
buildEntities {
|
|
||||||
regular("Something went wrong on welcome message changing for chat ")
|
regular("Something went wrong on welcome message changing for chat ")
|
||||||
underline(groupMessage.chat.title)
|
underline(groupMessage.chat.title)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
reply(
|
||||||
|
message,
|
||||||
|
entities
|
||||||
|
)
|
||||||
},
|
},
|
||||||
async {
|
parallel {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(config.recheckOfAdmin)
|
delay(config.recheckOfAdmin)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user