Skip to content

Commit

Permalink
Bump dev.inmo:tgbotapi from 7.1.3 to 15.2.0
Browse files Browse the repository at this point in the history
Bumps [dev.inmo:tgbotapi](https://github.com/insanusmokrassar/TelegramBotAPI) from 7.1.3 to 15.2.0.
- [Release notes](https://github.com/insanusmokrassar/TelegramBotAPI/releases)
- [Changelog](https://github.com/InsanusMokrassar/ktgbotapi/blob/master/CHANGELOG.md)
- [Commits](InsanusMokrassar/ktgbotapi@v7.1.3...v15.2.0)

---
updated-dependencies:
- dependency-name: dev.inmo:tgbotapi
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
  • Loading branch information
dependabot[bot] authored and madhead committed Jul 17, 2024
1 parent 0645445 commit a98751d
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.madhead.tyzenhaus.core.service
import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.toChatId
import me.madhead.tyzenhaus.core.telegram.updates.expense.getChatMemberSafe
import me.madhead.tyzenhaus.entity.group.members.GroupMember
import me.madhead.tyzenhaus.entity.group.members.GroupMembers
Expand All @@ -20,16 +21,16 @@ class GroupMembersService(
*/
suspend fun groupMembers(group: Long): GroupMembers? {
val groupConfig = groupConfigRepository.get(group) ?: return null
val chatMembers = groupConfig.members.map { requestsExecutor.getChatMemberSafe(ChatId(groupConfig.id), UserId(it)) }
val chatMembers = groupConfig.members.map { requestsExecutor.getChatMemberSafe(groupConfig.id.toChatId(), it.toChatId()) }

return GroupMembers(
id = groupConfig.id,
members = chatMembers.map {
GroupMember(
id = it.user.id.chatId,
id = it.user.id.chatId.long,
firstName = it.user.firstName,
lastName = it.user.lastName,
username = it.user.username?.usernameWithoutAt,
username = it.user.username?.withoutAt
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update

val Update.groupId: Long
get() = when (this) {
is BaseMessageUpdate -> this.data.chat.id.chatId
is BaseMessageUpdate -> this.data.chat.id.chatId.long
is CallbackQueryUpdate -> {
when (val callbackQuery = this.data) {
is MessageCallbackQuery -> callbackQuery.message.chat.id.chatId
is MessageCallbackQuery -> callbackQuery.message.chat.id.chatId.long
else -> throw IllegalArgumentException("Unknown update type")
}
}

is MyChatMemberUpdatedUpdate -> this.data.chat.id.chatId
is MyChatMemberUpdatedUpdate -> this.data.chat.id.chatId.long
else -> throw IllegalArgumentException("Unknown update type")
}

val Update.userId: Long
get() = when (this) {
is BaseMessageUpdate -> {
when (val message = this.data) {
is FromUserMessage -> message.user.id.chatId
is FromUserMessage -> message.user.id.chatId.long
else -> throw IllegalArgumentException("Unknown update type")
}
}

is CallbackQueryUpdate -> this.data.user.id.chatId
is CallbackQueryUpdate -> this.data.user.id.chatId.long
else -> throw IllegalArgumentException("Unknown update type")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.madhead.tyzenhaus.core.telegram.updates.expense

import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.types.ReplyParameters
import dev.inmo.tgbotapi.types.buttons.ReplyForce
import dev.inmo.tgbotapi.types.buttons.SimpleKeyboardButton
import dev.inmo.tgbotapi.types.message.MarkdownV2
Expand Down Expand Up @@ -44,14 +45,14 @@ class AmountReplyUpdateProcessor(
@Suppress("NAME_SHADOWING")
val dialogState = dialogState as? WaitingForAmount ?: return null

if (dialogState.messageId != message.replyTo?.messageId) return null
if (dialogState.messageId != message.replyTo?.messageId?.long) return null

if (dialogState.userId != update.userId) return {
requestsExecutor.sendMessage(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.amount.wrongUser"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
)
}

Expand All @@ -62,27 +63,27 @@ class AmountReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.amount.numberPlease"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId))
dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId.long))
}

val amount = content.text.toBigDecimalOrNull() ?: return {
val amountRequestMessage = requestsExecutor.sendMessage(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.amount.numberPlease"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId))
dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId.long))
}

if (amount.compareTo(BigDecimal.ZERO) == 0) {
Expand All @@ -91,13 +92,13 @@ class AmountReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.amount.nonZeroNumberPlease"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId))
dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId.long))
}
}

Expand All @@ -108,7 +109,7 @@ class AmountReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.action.currency"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = dev.inmo.tgbotapi.types.buttons.ReplyKeyboardMarkup(
keyboard = (groupCurrenciesService.groupCurrencies(update.groupId) ?: listOf("USD", "EUR", "RUB"))
.map { listOf(SimpleKeyboardButton(it)) },
Expand All @@ -118,7 +119,7 @@ class AmountReplyUpdateProcessor(
)
)

dialogStateRepository.save(WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId, amount))
dialogStateRepository.save(WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId.long, amount))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.answers.answerCallbackQuery
import dev.inmo.tgbotapi.extensions.api.edit.text.editMessageText
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.RawChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery
import dev.inmo.tgbotapi.types.toChatId
import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
Expand Down Expand Up @@ -92,11 +94,11 @@ class ConfirmationOKCallbackQueryUpdateProcessor(
dialogStateRepository.delete(update.groupId, dialogState.userId)

val members = (transaction.recipients + transaction.payer).toSet()
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(ChatId(update.groupId), UserId(it)) }
val from = "[${chatMembers.first { it.user.id.chatId == transaction.payer }.displayName.escapeMarkdownV2Common()}]" +
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(update.groupId.toChatId(), it.toChatId()) }
val from = "[${chatMembers.first { it.user.id.chatId.long == transaction.payer }.displayName.escapeMarkdownV2Common()}]" +
"(tg://user?id=${transaction.payer})"
val to = transaction.recipients.joinToString(", ") { recipient ->
"[${chatMembers.first { it.user.id.chatId == recipient }.displayName.escapeMarkdownV2Common()}]" +
"[${chatMembers.first { it.user.id.chatId.long == recipient }.displayName.escapeMarkdownV2Common()}]" +
"(tg://user?id=$recipient)"
}
val amount = "${transaction.amount.setScale(2, RoundingMode.HALF_UP)} ${transaction.currency}".escapeMarkdownV2Common()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.madhead.tyzenhaus.core.telegram.updates.expense

import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.types.ReplyParameters
import dev.inmo.tgbotapi.types.buttons.ReplyForce
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
Expand Down Expand Up @@ -40,14 +41,14 @@ class CurrencyReplyUpdateProcessor(
@Suppress("NAME_SHADOWING")
val dialogState = dialogState as? WaitingForCurrency ?: return null

if (dialogState.messageId != message.replyTo?.messageId) return null
if (dialogState.messageId != message.replyTo?.messageId?.long) return null

if (dialogState.userId != update.userId) return {
requestsExecutor.sendMessage(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.currency.wrongUser"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
)
}

Expand All @@ -58,14 +59,14 @@ class CurrencyReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.currency.textPlease"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(
WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId, dialogState.amount)
WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId.long, dialogState.amount)
)
}

Expand All @@ -76,14 +77,14 @@ class CurrencyReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.currency.tooLong"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(
WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId, dialogState.amount)
WaitingForCurrency(update.groupId, update.userId, currencyRequestMessage.messageId.long, dialogState.amount)
)
}

Expand All @@ -94,14 +95,14 @@ class CurrencyReplyUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.action.title"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(
WaitingForTitle(update.groupId, update.userId, titleRequestMessage.messageId, dialogState.amount, currency)
WaitingForTitle(update.groupId, update.userId, titleRequestMessage.messageId.long, dialogState.amount, currency)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.types.toChatId
import dev.inmo.tgbotapi.types.update.MessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
Expand Down Expand Up @@ -79,14 +80,14 @@ class DebtsCommandUpdateProcessor(
}
}

val chatMembers = members.map { requestsExecutor.getChatMemberSafe(ChatId(update.groupId), UserId(it)) }
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(update.groupId.toChatId(), it.toChatId()) }
val debtsMessage = debts
.joinToString(
prefix = I18N(groupConfig.language)["debts.response.title"],
separator = "\n"
) { debt ->
val from = chatMembers.first { it.user.id.chatId == debt.from }
val to = chatMembers.first { it.user.id.chatId == debt.to }
val from = chatMembers.first { it.user.id.chatId.long == debt.from }
val to = chatMembers.first { it.user.id.chatId.long == debt.to }
val amount = "${debt.amount.setScale(2, RoundingMode.HALF_UP)} ${debt.currency}".escapeMarkdownV2Common()

I18N(groupConfig.language)[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineK
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery
import dev.inmo.tgbotapi.types.toChatId
import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common
Expand Down Expand Up @@ -49,7 +50,7 @@ class DoneCallbackQueryUpdateProcessor(

if (callbackQuery.data != CALLBACK) return null

if ((dialogState.userId != update.userId) || (dialogState.messageId != callbackQuery.message.messageId)) return {
if ((dialogState.userId != update.userId) || (dialogState.messageId != callbackQuery.message.messageId.long)) return {
requestsExecutor.answerCallbackQuery(
callbackQuery = callbackQuery,
text = I18N(groupConfig?.language)["expense.response.participants.wrongUser"],
Expand All @@ -67,11 +68,11 @@ class DoneCallbackQueryUpdateProcessor(
timestamp = Instant.now(),
)
val members = (transaction.recipients + transaction.payer).toSet()
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(ChatId(update.groupId), UserId(it)) }
val from = "[${chatMembers.first { it.user.id.chatId == transaction.payer }.displayName.escapeMarkdownV2Common()}]" +
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(update.groupId.toChatId(), it.toChatId()) }
val from = "[${chatMembers.first { it.user.id.chatId.long == transaction.payer }.displayName.escapeMarkdownV2Common()}]" +
"(tg://user?id=${transaction.payer})"
val to = transaction.recipients.joinToString(", ") { recipient ->
"[${chatMembers.first { it.user.id.chatId == recipient }.displayName.escapeMarkdownV2Common()}]" +
"[${chatMembers.first { it.user.id.chatId.long == recipient }.displayName.escapeMarkdownV2Common()}]" +
"(tg://user?id=$recipient)"
}
val amount = "${transaction.amount.setScale(2, RoundingMode.HALF_UP)} ${transaction.currency}".escapeMarkdownV2Common()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.madhead.tyzenhaus.core.telegram.updates.expense

import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.types.ReplyParameters
import dev.inmo.tgbotapi.types.buttons.ReplyForce
import dev.inmo.tgbotapi.types.message.MarkdownV2
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
Expand Down Expand Up @@ -46,7 +47,7 @@ class ExpenseCommandUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.response.participants.empty"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
)
}

Expand All @@ -55,7 +56,7 @@ class ExpenseCommandUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig.language)["expense.response.participants.unknown"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
)
}

Expand All @@ -66,13 +67,13 @@ class ExpenseCommandUpdateProcessor(
chatId = update.data.chat.id,
text = I18N(groupConfig?.language)["expense.action.amount"],
parseMode = MarkdownV2,
replyToMessageId = message.messageId,
replyParameters = ReplyParameters(message),
replyMarkup = ReplyForce(
selective = true,
),
)

dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId))
dialogStateRepository.save(WaitingForAmount(update.groupId, update.userId, amountRequestMessage.messageId.long))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.extensions.api.edit.reply_markup.editMessageReplyMarkup
import dev.inmo.tgbotapi.types.ChatId
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.queries.callback.MessageDataCallbackQuery
import dev.inmo.tgbotapi.types.toChatId
import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import me.madhead.tyzenhaus.core.telegram.updates.UpdateProcessor
Expand Down Expand Up @@ -43,7 +44,7 @@ class ParticipantCallbackQueryUpdateProcessor(

if (!callbackQuery.data.startsWith(CALLBACK_PREFIX)) return null

if ((dialogState.userId != update.userId) || (dialogState.messageId != callbackQuery.message.messageId)) return {
if ((dialogState.userId != update.userId) || (dialogState.messageId != callbackQuery.message.messageId.long)) return {
requestsExecutor.answerCallbackQuery(
callbackQuery = callbackQuery,
text = I18N(groupConfig.language)["expense.response.participants.wrongUser"],
Expand All @@ -58,7 +59,7 @@ class ParticipantCallbackQueryUpdateProcessor(
val participant = rawParticipant.toLongOrNull()

if (participant != null) {
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(ChatId(update.groupId), UserId(it)) }
val chatMembers = members.map { requestsExecutor.getChatMemberSafe(update.groupId.toChatId(), it.toChatId()) }
val state = dialogState.copy(
participants = if (dialogState.participants.contains(participant)) {
dialogState.participants - participant
Expand Down
Loading

0 comments on commit a98751d

Please sign in to comment.