+ - bot enable
This commit is contained in:
@@ -22,5 +22,4 @@ class TelegramBotConfig {
|
||||
data class TelegramBotProperties(
|
||||
val username: String,
|
||||
val token: String,
|
||||
val enable:Int
|
||||
)
|
||||
|
||||
@@ -41,16 +41,10 @@ class BotService(
|
||||
private val logger = LoggerFactory.getLogger(javaClass)
|
||||
|
||||
private suspend fun constructCategoriesButtons(
|
||||
nlp: Boolean,
|
||||
text: String? = null,
|
||||
chatId: Long
|
||||
nlp: Boolean, text: String? = null, chatId: Long
|
||||
): InlineKeyboardMarkup {
|
||||
val categories =
|
||||
categoriesService.getCategories(
|
||||
"67af3c0f652da946a7dd9931",
|
||||
"EXPENSE",
|
||||
sortBy = "name",
|
||||
direction = "ASC"
|
||||
val categories = categoriesService.getCategories(
|
||||
"67af3c0f652da946a7dd9931", "EXPENSE", sortBy = "name", direction = "ASC"
|
||||
)
|
||||
|
||||
val keyboard = InlineKeyboardMarkup()
|
||||
@@ -135,18 +129,14 @@ class BotService(
|
||||
val chatId = update.callbackQuery.message.chatId.toString()
|
||||
val tgUserId = update.callbackQuery.from.id
|
||||
val user = userService.getUserByTelegramId(tgUserId) ?: throw TelegramBotException(
|
||||
"User ${update.callbackQuery.from.userName} not found",
|
||||
chatId = update.callbackQuery.message.chatId
|
||||
"User ${update.callbackQuery.from.userName} not found", chatId = update.callbackQuery.message.chatId
|
||||
)
|
||||
val state = getState(user.id!!)
|
||||
if (state != null) {
|
||||
when (state.data.first { it.chatId == chatId }.state) {
|
||||
BotStates.WAIT_CATEGORY ->
|
||||
if (update.callbackQuery.data.startsWith("category_")) {
|
||||
BotStates.WAIT_CATEGORY -> if (update.callbackQuery.data.startsWith("category_")) {
|
||||
confirmTransaction(
|
||||
chatId,
|
||||
user = userService.getUserByTelegramId(tgUserId)!!,
|
||||
update
|
||||
chatId, user = userService.getUserByTelegramId(tgUserId)!!, update
|
||||
)
|
||||
} else if (update.callbackQuery.data == "cancel") {
|
||||
finishState(chatId, user)
|
||||
@@ -172,8 +162,7 @@ class BotService(
|
||||
getState(user.id!!)?.data?.find { it.chatId == update.message.chatId.toString() }?.let {
|
||||
if (it.state == BotStates.WAIT_CATEGORY) {
|
||||
throw TelegramBotException(
|
||||
"Уже есть открытый выбор категории",
|
||||
update.message.chatId
|
||||
"Уже есть открытый выбор категории", update.message.chatId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -257,17 +246,12 @@ class BotService(
|
||||
}
|
||||
|
||||
val category = categoriesService.getCategories(
|
||||
"67af3c0f652da946a7dd9931",
|
||||
"EXPENSE",
|
||||
sortBy = "name",
|
||||
direction = "ASC"
|
||||
)
|
||||
.first { it.id == update.callbackQuery.data.split("_")[1] }
|
||||
"67af3c0f652da946a7dd9931", "EXPENSE", sortBy = "name", direction = "ASC"
|
||||
).first { it.id == update.callbackQuery.data.split("_")[1] }
|
||||
val space = spaceService.getSpace("67af3c0f652da946a7dd9931")
|
||||
val instantType = financialService.getTransactionTypes().first { it.code == "INSTANT" }
|
||||
val transaction = financialService.createTransaction(
|
||||
space,
|
||||
transaction = Transaction(
|
||||
space, transaction = Transaction(
|
||||
space = space,
|
||||
type = instantType,
|
||||
user = user,
|
||||
@@ -278,8 +262,7 @@ class BotService(
|
||||
isDone = true,
|
||||
parentId = null,
|
||||
createdAt = LocalDateTime.now()
|
||||
),
|
||||
user = user
|
||||
), user = user
|
||||
)
|
||||
val editMsg = EditMessageText()
|
||||
editMsg.chatId = chatId
|
||||
@@ -302,9 +285,7 @@ class BotService(
|
||||
val match = match(Criteria.where("userDetails._id").`is`(ObjectId(userId)))
|
||||
|
||||
val aggregation = newAggregation(lookup, unwind, match)
|
||||
return reactiveMongoTemplate.aggregate(aggregation, "bot-user-states", Document::class.java)
|
||||
.next()
|
||||
.map { doc ->
|
||||
return reactiveMongoTemplate.aggregate(aggregation, "bot-user-states", Document::class.java).next().map { doc ->
|
||||
val dataList = doc.getList("data", Document::class.java)
|
||||
BotUserState(
|
||||
id = doc.getObjectId("_id").toString(),
|
||||
@@ -318,14 +299,12 @@ class BotService(
|
||||
)
|
||||
}.toMutableList(),
|
||||
)
|
||||
}
|
||||
.awaitSingleOrNull()
|
||||
}.awaitSingleOrNull()
|
||||
}
|
||||
|
||||
private suspend fun setState(userState: BotUserState): BotUserState {
|
||||
val stateToSave = userState.user.id?.let { userId ->
|
||||
getState(userId)?.copy(data = userState.data)
|
||||
?: BotUserState(user = userState.user, data = userState.data)
|
||||
getState(userId)?.copy(data = userState.data) ?: BotUserState(user = userState.user, data = userState.data)
|
||||
} ?: BotUserState(user = userState.user, data = userState.data)
|
||||
|
||||
return botStatesRepo.save(stateToSave).awaitSingle()
|
||||
|
||||
Reference in New Issue
Block a user