diff --git a/CHANGELOG.md b/CHANGELOG.md index 0183104d59..77173223ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 5.0.0 + ## 4.2.4 * `Core`: diff --git a/gradle.properties b/gradle.properties index 1d5a01cbe2..e4b457c7fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=4.2.4 +library_version=5.0.0 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/CloseGeneralForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/CloseGeneralForumTopic.kt new file mode 100644 index 0000000000..f472ed6ecd --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/CloseGeneralForumTopic.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.extensions.api.chat.forum + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ForumTopic +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.chat.Chat + +suspend fun TelegramBot.closeGeneralForumTopic( + chatId: ChatIdentifier +) = execute( + CloseGeneralForumTopic(chatId) +) + +suspend fun TelegramBot.closeGeneralForumTopic( + chat: Chat +) = closeGeneralForumTopic(chat.id) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditForumTopic.kt index 3039a884bf..7676246e31 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditForumTopic.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditForumTopic.kt @@ -11,8 +11,8 @@ import dev.inmo.tgbotapi.types.chat.Chat suspend fun TelegramBot.editForumTopic( chatId: ChatIdentifier, messageThreadId: MessageThreadId, - name: String, - iconEmojiId: CustomEmojiId + name: String? = null, + iconEmojiId: CustomEmojiId? = null ) = execute( EditForumTopic( chatId, @@ -25,12 +25,12 @@ suspend fun TelegramBot.editForumTopic( suspend fun TelegramBot.editForumTopic( chat: Chat, messageThreadId: MessageThreadId, - name: String, - iconEmojiId: CustomEmojiId + name: String? = null, + iconEmojiId: CustomEmojiId? = null ) = editForumTopic(chat.id, messageThreadId, name, iconEmojiId) suspend fun TelegramBot.editForumTopic( chatIdentifier: ChatIdentifier, forumTopic: ForumTopic, - iconEmojiId: CustomEmojiId = forumTopic.iconEmojiId ?: error("Icon emoji id in forum topic should be presented when edit forum topic basing on other forum topic object") + iconEmojiId: CustomEmojiId? = forumTopic.iconEmojiId ) = editForumTopic(chatIdentifier, forumTopic.messageThreadId, forumTopic.name, iconEmojiId) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditGeneralForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditGeneralForumTopic.kt new file mode 100644 index 0000000000..0f71e50e2b --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/EditGeneralForumTopic.kt @@ -0,0 +1,30 @@ +package dev.inmo.tgbotapi.extensions.api.chat.forum + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.forum.EditForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.EditGeneralForumTopic +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.CustomEmojiId +import dev.inmo.tgbotapi.types.ForumTopic +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.chat.Chat + +suspend fun TelegramBot.editGeneralForumTopic( + chatId: ChatIdentifier, + name: String +) = execute( + EditGeneralForumTopic( + chatId, + name + ) +) + +suspend fun TelegramBot.editGeneralForumTopic( + chat: Chat, + name: String +) = editGeneralForumTopic(chat.id, name) + +suspend fun TelegramBot.editGeneralForumTopic( + chatIdentifier: ChatIdentifier, + forumTopic: ForumTopic, +) = editGeneralForumTopic(chatIdentifier, forumTopic.name) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/HideGeneralForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/HideGeneralForumTopic.kt new file mode 100644 index 0000000000..3bd76b8b7d --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/HideGeneralForumTopic.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.extensions.api.chat.forum + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ForumTopic +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.chat.Chat + +suspend fun TelegramBot.hideGeneralForumTopic( + chatId: ChatIdentifier +) = execute( + HideGeneralForumTopic(chatId) +) + +suspend fun TelegramBot.hideGeneralForumTopic( + chat: Chat +) = hideGeneralForumTopic(chat.id) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/ReopenGeneralForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/ReopenGeneralForumTopic.kt new file mode 100644 index 0000000000..4492c5b599 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/ReopenGeneralForumTopic.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.extensions.api.chat.forum + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.forum.ReopenForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.ReopenGeneralForumTopic +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ForumTopic +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.chat.Chat + +suspend fun TelegramBot.reopenGeneralForumTopic( + chatId: ChatIdentifier +) = execute( + ReopenGeneralForumTopic(chatId) +) + +suspend fun TelegramBot.reopenGeneralForumTopic( + chat: Chat +) = reopenGeneralForumTopic(chat.id) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/UnhideGeneralForumTopic.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/UnhideGeneralForumTopic.kt new file mode 100644 index 0000000000..1f6ef3c5cb --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/forum/UnhideGeneralForumTopic.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.extensions.api.chat.forum + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.forum.CloseForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.CloseGeneralForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.HideGeneralForumTopic +import dev.inmo.tgbotapi.requests.chat.forum.UnhideGeneralForumTopic +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ForumTopic +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.chat.Chat + +suspend fun TelegramBot.unhideGeneralForumTopic( + chatId: ChatIdentifier +) = execute( + UnhideGeneralForumTopic(chatId) +) + +suspend fun TelegramBot.unhideGeneralForumTopic( + chat: Chat +) = unhideGeneralForumTopic(chat.id) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index 0290897343..e22e4d39e1 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -379,6 +379,7 @@ suspend inline fun TelegramBot.replyWithAnimation( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -392,6 +393,7 @@ suspend inline fun TelegramBot.replyWithAnimation( thumb, text, parseMode, + spoilered, duration, width, height, @@ -408,6 +410,7 @@ suspend inline fun TelegramBot.reply( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -415,12 +418,13 @@ suspend inline fun TelegramBot.reply( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, text, parseMode, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(to.chat, animation, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAnimation( to: Message, animation: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, thumb: InputFile? = null, duration: Long? = null, width: Int? = null, @@ -434,6 +438,7 @@ suspend inline fun TelegramBot.replyWithAnimation( animation, thumb, entities, + spoilered, duration, width, height, @@ -449,6 +454,7 @@ suspend inline fun TelegramBot.reply( to: Message, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -456,7 +462,7 @@ suspend inline fun TelegramBot.reply( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(to.chat, animation, entities, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(to.chat, animation, entities, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) // Audio @@ -608,64 +614,70 @@ suspend inline fun TelegramBot.replyWithPhoto( fileId: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, fileId, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, photo, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photoSize, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, photoSize, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( to: Message, fileId: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, fileId, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, fileId, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photo, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, photo, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(to.chat, photoSize, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(to.chat, photoSize, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) // Sticker @@ -697,6 +709,7 @@ suspend inline fun TelegramBot.replyWithVideo( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -704,24 +717,26 @@ suspend inline fun TelegramBot.replyWithVideo( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, text, parseMode, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(to.chat, video, thumb, text, parseMode, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, text, parseMode, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(to.chat, video, text, parseMode, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( to: Message, video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -729,17 +744,18 @@ suspend inline fun TelegramBot.replyWithVideo( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, thumb, entities, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(to.chat, video, thumb, entities, spoilered, duration, width, height, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( to: Message, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(to.chat, video, entities, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(to.chat, video, entities, spoilered, to.threadIdOrNull, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) // VideoNotes diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt index d81c42fbc3..6547d1db14 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/RepliesWithChatsAndMessages.kt @@ -410,6 +410,7 @@ suspend inline fun TelegramBot.replyWithAnimation( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -424,6 +425,7 @@ suspend inline fun TelegramBot.replyWithAnimation( thumb, text, parseMode, + spoilered, duration, width, height, @@ -441,6 +443,7 @@ suspend inline fun TelegramBot.reply( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -449,13 +452,14 @@ suspend inline fun TelegramBot.reply( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(toChatId, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(toChatId, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithAnimation( toChatId: IdChatIdentifier, toMessageId: MessageId, animation: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, thumb: InputFile? = null, duration: Long? = null, width: Int? = null, @@ -470,6 +474,7 @@ suspend inline fun TelegramBot.replyWithAnimation( animation, thumb, entities, + spoilered, duration, width, height, @@ -486,6 +491,7 @@ suspend inline fun TelegramBot.reply( toMessageId: MessageId, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -494,7 +500,7 @@ suspend inline fun TelegramBot.reply( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(toChatId, animation, entities, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(toChatId, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) // Audio @@ -671,12 +677,13 @@ suspend inline fun TelegramBot.replyWithPhoto( fileId: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, fileId, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, @@ -684,12 +691,13 @@ suspend inline fun TelegramBot.reply( photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, photo, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, @@ -697,12 +705,13 @@ suspend inline fun TelegramBot.reply( photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, photoSize, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithPhoto( @@ -710,36 +719,39 @@ suspend inline fun TelegramBot.replyWithPhoto( toMessageId: MessageId, fileId: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, fileId, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, fileId, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, toMessageId: MessageId, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, photo, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, photo, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, toMessageId: MessageId, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(toChatId, photoSize, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(toChatId, photoSize, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) // Sticker @@ -776,6 +788,7 @@ suspend inline fun TelegramBot.replyWithVideo( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -784,7 +797,7 @@ suspend inline fun TelegramBot.replyWithVideo( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(toChatId, video, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(toChatId, video, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, @@ -792,12 +805,13 @@ suspend inline fun TelegramBot.reply( video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(toChatId, video, text, parseMode, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(toChatId, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.replyWithVideo( toChatId: IdChatIdentifier, @@ -805,6 +819,7 @@ suspend inline fun TelegramBot.replyWithVideo( video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -813,19 +828,20 @@ suspend inline fun TelegramBot.replyWithVideo( protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(toChatId, video, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(toChatId, video, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) suspend inline fun TelegramBot.reply( toChatId: IdChatIdentifier, toMessageId: MessageId, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = toChatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(toChatId, video, entities, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(toChatId, video, entities, spoilered, threadId, disableNotification, protectContent, toMessageId, allowSendingWithoutReply, replyMarkup) // VideoNotes diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt index d7ad4ec7cc..2f876bdacd 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendAction.kt @@ -3,104 +3,129 @@ package dev.inmo.tgbotapi.extensions.api.send import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.send.SendAction import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.chat.Chat +import dev.inmo.tgbotapi.types.threadId suspend fun TelegramBot.sendBotAction( chatId: ChatIdentifier, - action: BotAction + action: BotAction, + threadId: MessageThreadId? = chatId.threadId ) = execute( - SendAction(chatId, action) + SendAction(chatId, action, threadId) ) suspend fun TelegramBot.sendBotAction( chat: Chat, - action: BotAction -) = sendBotAction(chat.id, action) + action: BotAction, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat.id, action, threadId) suspend fun TelegramBot.sendActionTyping( - chatId: ChatIdentifier -) = sendBotAction(chatId, TypingAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, TypingAction, threadId) suspend fun TelegramBot.sendActionUploadPhoto( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadPhotoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadPhotoAction, threadId) suspend fun TelegramBot.sendActionRecordVideo( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVideoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVideoAction, threadId) suspend fun TelegramBot.sendActionUploadVideo( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVideoAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVideoAction, threadId) suspend fun TelegramBot.sendActionRecordVoice( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVoiceAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadVoice( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVoiceAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadDocument( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadDocumentAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadDocumentAction, threadId) suspend fun TelegramBot.sendActionFindLocation( - chatId: ChatIdentifier -) = sendBotAction(chatId, FindLocationAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, FindLocationAction, threadId) suspend fun TelegramBot.sendActionRecordVideoNote( - chatId: ChatIdentifier -) = sendBotAction(chatId, RecordVideoNoteAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, RecordVideoNoteAction, threadId) suspend fun TelegramBot.sendActionUploadVideoNote( - chatId: ChatIdentifier -) = sendBotAction(chatId, UploadVideoNoteAction) + chatId: ChatIdentifier, + threadId: MessageThreadId? = chatId.threadId +) = sendBotAction(chatId, UploadVideoNoteAction, threadId) suspend fun TelegramBot.sendActionTyping( - chat: Chat -) = sendBotAction(chat, TypingAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, TypingAction, threadId) suspend fun TelegramBot.sendActionUploadPhoto( - chat: Chat -) = sendBotAction(chat, UploadPhotoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadPhotoAction, threadId) suspend fun TelegramBot.sendActionRecordVideo( - chat: Chat -) = sendBotAction(chat, RecordVideoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVideoAction, threadId) suspend fun TelegramBot.sendActionUploadVideo( - chat: Chat -) = sendBotAction(chat, UploadVideoAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVideoAction, threadId) suspend fun TelegramBot.sendActionRecordVoice( - chat: Chat -) = sendBotAction(chat, RecordVoiceAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadVoice( - chat: Chat -) = sendBotAction(chat, UploadVoiceAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVoiceAction, threadId) suspend fun TelegramBot.sendActionUploadDocument( - chat: Chat -) = sendBotAction(chat, UploadDocumentAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadDocumentAction, threadId) suspend fun TelegramBot.sendActionFindLocation( - chat: Chat -) = sendBotAction(chat, FindLocationAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, FindLocationAction, threadId) suspend fun TelegramBot.sendActionRecordVideoNote( - chat: Chat -) = sendBotAction(chat, RecordVideoNoteAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, RecordVideoNoteAction, threadId) suspend fun TelegramBot.sendActionUploadVideoNote( - chat: Chat -) = sendBotAction(chat, UploadVideoNoteAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, UploadVideoNoteAction, threadId) suspend fun TelegramBot.sendActionChooseStickerAction( - chat: Chat -) = sendBotAction(chat, ChooseStickerAction) + chat: Chat, + threadId: MessageThreadId? = chat.id.threadId +) = sendBotAction(chat, ChooseStickerAction, threadId) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt index 3a9db0be3a..c182898837 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt @@ -38,13 +38,14 @@ suspend fun TelegramBot.withAction( suspend fun TelegramBot.withAction( chatId: IdChatIdentifier, action: BotAction, + threadId: MessageThreadId? = chatId.threadId, block: TelegramBotActionCallback ): T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return withAction( - SendAction(chatId, action), + SendAction(chatId, action, threadId), block ) } @@ -53,6 +54,7 @@ suspend fun TelegramBot.withAction( suspend fun TelegramBot.withAction( chat: Chat, action: BotAction, + threadId: MessageThreadId? = chat.id.threadId, block: TelegramBotActionCallback ): T { contract { @@ -61,163 +63,164 @@ suspend fun TelegramBot.withAction( return withAction( chat.id, action, + threadId, block ) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withTypingAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withTypingAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, TypingAction, block) + return withAction(chatId, TypingAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadPhotoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadPhotoAction, block) + return withAction(chatId, UploadPhotoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVideoAction, block) + return withAction(chatId, RecordVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVideoAction, block) + return withAction(chatId, UploadVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVoiceAction, block) + return withAction(chatId, RecordVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVoiceAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVoiceAction, block) + return withAction(chatId, UploadVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadDocumentAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadDocumentAction, block) + return withAction(chatId, UploadDocumentAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withFindLocationAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, FindLocationAction, block) + return withAction(chatId, FindLocationAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, RecordVideoNoteAction, block) + return withAction(chatId, RecordVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoNoteAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, UploadVideoNoteAction, block) + return withAction(chatId, UploadVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withChooseStickerAction(chatId: IdChatIdentifier, threadId: MessageThreadId? = chatId.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chatId, ChooseStickerAction, block) + return withAction(chatId, ChooseStickerAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withTypingAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, TypingAction, block) + return withAction(chat, TypingAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadPhotoAction, block) + return withAction(chat, UploadPhotoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVideoAction, block) + return withAction(chat, RecordVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVideoAction, block) + return withAction(chat, UploadVideoAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVoiceAction, block) + return withAction(chat, RecordVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVoiceAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVoiceAction, block) + return withAction(chat, UploadVoiceAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadDocumentAction, block) + return withAction(chat, UploadDocumentAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withFindLocationAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, FindLocationAction, block) + return withAction(chat, FindLocationAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, RecordVideoNoteAction, block) + return withAction(chat, RecordVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, UploadVideoNoteAction, block) + return withAction(chat, UploadVideoNoteAction, threadId, block) } @OptIn(ExperimentalContracts::class) -suspend fun TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback) : T { +suspend fun TelegramBot.withChooseStickerAction(chat: Chat, threadId: MessageThreadId? = chat.id.threadId,block: TelegramBotActionCallback) : T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } - return withAction(chat, ChooseStickerAction, block) + return withAction(chat, ChooseStickerAction, threadId, block) } diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt index 45cdac1c67..70455fc405 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Sends.kt @@ -56,6 +56,7 @@ suspend fun TelegramBot.send( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -65,7 +66,7 @@ suspend fun TelegramBot.send( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chatId, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chatId, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendAnimation] request @@ -77,6 +78,7 @@ suspend fun TelegramBot.send( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -86,7 +88,7 @@ suspend fun TelegramBot.send( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendAnimation] request @@ -97,6 +99,7 @@ suspend fun TelegramBot.send( chatId: ChatIdentifier, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -106,7 +109,7 @@ suspend fun TelegramBot.send( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chatId, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chatId, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendAnimation] request @@ -117,6 +120,7 @@ suspend fun TelegramBot.send( chat: Chat, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -126,7 +130,7 @@ suspend fun TelegramBot.send( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendAudio] request @@ -688,13 +692,14 @@ suspend fun TelegramBot.send( photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -706,13 +711,14 @@ suspend fun TelegramBot.send( photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -724,13 +730,14 @@ suspend fun TelegramBot.send( photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -742,13 +749,14 @@ suspend fun TelegramBot.send( photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -759,13 +767,14 @@ suspend inline fun TelegramBot.send( chatId: ChatIdentifier, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -776,13 +785,14 @@ suspend inline fun TelegramBot.send( chat: Chat, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -793,13 +803,14 @@ suspend inline fun TelegramBot.send( chatId: ChatIdentifier, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendPhoto] request @@ -810,13 +821,14 @@ suspend inline fun TelegramBot.send( chat: Chat, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendRegularPoll] request @@ -1357,13 +1369,14 @@ suspend fun TelegramBot.send( video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chatId, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendVideo] request @@ -1375,13 +1388,14 @@ suspend fun TelegramBot.send( video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendVideo] request @@ -1392,13 +1406,14 @@ suspend inline fun TelegramBot.send( chatId: ChatIdentifier, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chatId, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendVideo] request @@ -1409,13 +1424,14 @@ suspend inline fun TelegramBot.send( chat: Chat, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * Will execute [sendVideoNote] request diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt index edfb5dfb29..623e44ccf2 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendAnimation.kt @@ -23,6 +23,7 @@ suspend fun TelegramBot.sendAnimation( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -39,6 +40,7 @@ suspend fun TelegramBot.sendAnimation( thumb, text, parseMode, + spoilered, duration, width, height, @@ -60,6 +62,7 @@ suspend fun TelegramBot.sendAnimation( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -70,7 +73,7 @@ suspend fun TelegramBot.sendAnimation( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( - chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId, animation.fileId, animation.thumb ?.fileId, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup ) /** @@ -83,6 +86,7 @@ suspend fun TelegramBot.sendAnimation( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -92,7 +96,7 @@ suspend fun TelegramBot.sendAnimation( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat.id, animation, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -103,6 +107,7 @@ suspend fun TelegramBot.sendAnimation( animation: AnimationFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -112,7 +117,7 @@ suspend fun TelegramBot.sendAnimation( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat.id, animation, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** @@ -124,6 +129,7 @@ suspend fun TelegramBot.sendAnimation( animation: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -139,6 +145,7 @@ suspend fun TelegramBot.sendAnimation( animation, thumb, entities, + spoilered, duration, width, height, @@ -159,6 +166,7 @@ suspend fun TelegramBot.sendAnimation( chatId: ChatIdentifier, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -169,7 +177,7 @@ suspend fun TelegramBot.sendAnimation( allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ) = sendAnimation( - chatId, animation.fileId, animation.thumb ?.fileId, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup + chatId, animation.fileId, animation.thumb ?.fileId, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup ) /** @@ -181,6 +189,7 @@ suspend fun TelegramBot.sendAnimation( animation: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -190,7 +199,7 @@ suspend fun TelegramBot.sendAnimation( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat.id, animation, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -200,6 +209,7 @@ suspend fun TelegramBot.sendAnimation( chat: Chat, animation: AnimationFile, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -209,4 +219,4 @@ suspend fun TelegramBot.sendAnimation( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendAnimation(chat.id, animation, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendAnimation(chat.id, animation, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt index c091231391..3626bb8f66 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendPhoto.kt @@ -22,6 +22,7 @@ suspend fun TelegramBot.sendPhoto( fileId: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -34,6 +35,7 @@ suspend fun TelegramBot.sendPhoto( fileId, text, parseMode, + spoilered, threadId, disableNotification, protectContent, @@ -52,13 +54,14 @@ suspend fun TelegramBot.sendPhoto( fileId: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, fileId, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -69,13 +72,14 @@ suspend fun TelegramBot.sendPhoto( photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -86,13 +90,14 @@ suspend fun TelegramBot.sendPhoto( photo: Photo, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photo, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, photo, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -103,13 +108,14 @@ suspend fun TelegramBot.sendPhoto( photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photoSize.fileId, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photoSize.fileId, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -120,13 +126,14 @@ suspend fun TelegramBot.sendPhoto( photoSize: PhotoSize, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photoSize, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, photoSize, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** @@ -137,6 +144,7 @@ suspend inline fun TelegramBot.sendPhoto( chatId: ChatIdentifier, fileId: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -148,6 +156,7 @@ suspend inline fun TelegramBot.sendPhoto( chatId, fileId, entities, + spoilered, threadId, disableNotification, protectContent, @@ -165,13 +174,14 @@ suspend inline fun TelegramBot.sendPhoto( chat: Chat, fileId: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, fileId, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, fileId, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -181,13 +191,14 @@ suspend inline fun TelegramBot.sendPhoto( chatId: ChatIdentifier, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photo.biggest() ?.fileId ?: error("Photo content must not be empty"), entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -197,13 +208,14 @@ suspend inline fun TelegramBot.sendPhoto( chat: Chat, photo: Photo, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photo, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, photo, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -213,13 +225,14 @@ suspend inline fun TelegramBot.sendPhoto( chatId: ChatIdentifier, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chatId, photoSize.fileId, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chatId, photoSize.fileId, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -229,10 +242,11 @@ suspend inline fun TelegramBot.sendPhoto( chat: Chat, photoSize: PhotoSize, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendPhoto(chat.id, photoSize, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendPhoto(chat.id, photoSize, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt index c9123bab69..3b1b6c7481 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendVideo.kt @@ -23,6 +23,7 @@ suspend fun TelegramBot.sendVideo( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -39,6 +40,7 @@ suspend fun TelegramBot.sendVideo( thumb, text, parseMode, + spoilered, duration, width, height, @@ -61,13 +63,14 @@ suspend fun TelegramBot.sendVideo( video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, text, parseMode, spoilered, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -79,6 +82,7 @@ suspend fun TelegramBot.sendVideo( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -88,7 +92,7 @@ suspend fun TelegramBot.sendVideo( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, thumb, text, parseMode, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat.id, video, thumb, text, parseMode, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** @@ -100,13 +104,14 @@ suspend fun TelegramBot.sendVideo( video: VideoFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, text, parseMode, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat.id, video, text, parseMode, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -117,6 +122,7 @@ suspend inline fun TelegramBot.sendVideo( video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -132,6 +138,7 @@ suspend inline fun TelegramBot.sendVideo( video, thumb, entities, + spoilered, duration, width, height, @@ -153,13 +160,14 @@ suspend inline fun TelegramBot.sendVideo( chatId: ChatIdentifier, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chatId, video.fileId, video.thumb ?.fileId, entities, spoilered, video.duration, video.width, video.height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or @@ -170,6 +178,7 @@ suspend inline fun TelegramBot.sendVideo( video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -179,7 +188,7 @@ suspend inline fun TelegramBot.sendVideo( replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, thumb, entities, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat.id, video, thumb, entities, spoilered, duration, width, height, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) /** @@ -190,10 +199,11 @@ suspend inline fun TelegramBot.sendVideo( chat: Chat, video: VideoFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chat.id.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, replyToMessageId: MessageId? = null, allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null -) = sendVideo(chat.id, video, entities, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) +) = sendVideo(chat.id, video, entities, spoilered, threadId, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 4bdc582d43..ec6e5f8572 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -9,7 +9,11 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent @@ -151,3 +155,19 @@ suspend fun BehaviourContext.waitForumTopicReopened( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEvents(initRequest, errorFactory) +suspend fun BehaviourContext.waitForumTopicEdited( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) +suspend fun BehaviourContext.waitGeneralForumTopicHidden( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) +suspend fun BehaviourContext.waitGeneralForumTopicUnhidden( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) +suspend fun BehaviourContext.waitWriteAccessAllowed( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 69e4f87929..06662e8a59 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -13,7 +13,11 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage @@ -575,3 +579,81 @@ suspend fun BC.onForumTopicReopened( markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onForumTopicEdited( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onGeneralForumTopicHidden( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onGeneralForumTopicUnhidden( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onWriteAccessAllowed( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/SpoilerableData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/SpoilerableData.kt new file mode 100644 index 0000000000..e14d072b48 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/abstracts/SpoilerableData.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.abstracts + +interface SpoilerableData { + val spoilered: Boolean +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseGeneralForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseGeneralForumTopic.kt new file mode 100644 index 0000000000..8217a3848e --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseGeneralForumTopic.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class CloseGeneralForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ModifyForumRequest, GeneralForumRequest { + override fun method(): String = "closeGeneralForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt index 6a1c8dc768..df11c5e404 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt @@ -1,11 +1,7 @@ package dev.inmo.tgbotapi.requests.chat.forum -import dev.inmo.tgbotapi.abstracts.types.ChatRequest -import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.utils.RGBColor import kotlinx.serialization.* -import kotlinx.serialization.builtins.serializer @Serializable data class EditForumTopic ( @@ -14,12 +10,12 @@ data class EditForumTopic ( @SerialName(messageThreadIdField) val messageThreadId: MessageThreadId, @SerialName(nameField) - val name: String, + val name: String? = null, @SerialName(iconCustomEmojiIdField) - val iconEmojiId: CustomEmojiId, + val iconEmojiId: CustomEmojiId? = null, ): ModifyForumRequest { init { - if (name.length !in threadNameLength) { + if (name != null && name.length !in threadNameLength) { throw IllegalArgumentException("Thread name must be in $threadNameLength range") } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditGeneralForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditGeneralForumTopic.kt new file mode 100644 index 0000000000..bdbc0c08d3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditGeneralForumTopic.kt @@ -0,0 +1,22 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.* + +@Serializable +data class EditGeneralForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(nameField) + val name: String +): ModifyForumRequest, GeneralForumRequest { + init { + if (name.length !in threadNameLength) { + throw IllegalArgumentException("Thread name must be in $threadNameLength range") + } + } + + override fun method(): String = "editGeneralForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/GeneralForumRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/GeneralForumRequest.kt new file mode 100644 index 0000000000..708423b4d4 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/GeneralForumRequest.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest + +sealed interface GeneralForumRequest : ForumRequest, ChatRequest diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/HideGeneralForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/HideGeneralForumTopic.kt new file mode 100644 index 0000000000..fe5e15b939 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/HideGeneralForumTopic.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class HideGeneralForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ModifyForumRequest, GeneralForumRequest { + override fun method(): String = "hideGeneralForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenGeneralForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenGeneralForumTopic.kt new file mode 100644 index 0000000000..768c83f05c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenGeneralForumTopic.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class ReopenGeneralForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, +): ModifyForumRequest, GeneralForumRequest { + override fun method(): String = "reopenGeneralForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnhideGeneralForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnhideGeneralForumTopic.kt new file mode 100644 index 0000000000..0ac38f053a --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnhideGeneralForumTopic.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class UnhideGeneralForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier +): ModifyForumRequest, GeneralForumRequest { + override fun method(): String = "unhideGeneralForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt index 5b9e3396da..6a5762dd31 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SendAction.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.requests.send +import dev.inmo.tgbotapi.requests.send.abstracts.OptionallyMessageThreadRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendChatMessageRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.actions.BotAction @@ -14,8 +15,10 @@ data class SendAction( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(actionField) - val action: BotAction -): SendChatMessageRequest { + val action: BotAction, + @SerialName(messageThreadIdField) + override val threadId: MessageThreadId? = chatId.threadId +): SendChatMessageRequest, OptionallyMessageThreadRequest { override fun method(): String = "sendChatAction" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/OptionallyWithSpoilerRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/OptionallyWithSpoilerRequest.kt new file mode 100644 index 0000000000..431d86790d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/abstracts/OptionallyWithSpoilerRequest.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.requests.send.abstracts + +import dev.inmo.tgbotapi.abstracts.SpoilerableData + +interface OptionallyWithSpoilerRequest : SpoilerableData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt index 576ab84087..ec83f84067 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendAnimation.kt @@ -25,6 +25,7 @@ fun SendAnimation( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -47,6 +48,7 @@ fun SendAnimation( text, parseMode, null, + spoilered, duration, width, height, @@ -73,6 +75,7 @@ fun SendAnimation( animation: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -95,6 +98,7 @@ fun SendAnimation( entities.makeString(), null, entities.toRawMessageEntities(), + spoilered, duration, width, height, @@ -133,6 +137,8 @@ data class SendAnimationData internal constructor( override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -157,7 +163,8 @@ data class SendAnimationData internal constructor( TextableSendMessageRequest>, ThumbedSendMessageRequest>, DuratedSendMessageRequest>, - SizedSendMessageRequest> + SizedSendMessageRequest>, + OptionallyWithSpoilerRequest { override val textSources: TextSourcesList? by lazy { rawEntities ?.asTextSources(text ?: return@lazy null) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt index e2a7dde628..0c54d063e5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendPhoto.kt @@ -23,6 +23,7 @@ fun SendPhoto( photo: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -36,6 +37,7 @@ fun SendPhoto( text, parseMode, null, + spoilered, threadId, disableNotification, protectContent, @@ -55,6 +57,7 @@ fun SendPhoto( chatId: ChatIdentifier, photo: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, threadId: MessageThreadId? = chatId.threadId, disableNotification: Boolean = false, protectContent: Boolean = false, @@ -68,6 +71,7 @@ fun SendPhoto( entities.makeString(), null, entities.toRawMessageEntities(), + spoilered, threadId, disableNotification, protectContent, @@ -98,6 +102,8 @@ data class SendPhotoData internal constructor( override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, @SerialName(messageThreadIdField) override val threadId: MessageThreadId? = chatId.threadId, @SerialName(disableNotificationField) @@ -113,7 +119,8 @@ data class SendPhotoData internal constructor( ) : DataRequest>, SendMessageRequest>, ReplyingMarkupSendMessageRequest>, - TextableSendMessageRequest> + TextableSendMessageRequest>, + OptionallyWithSpoilerRequest { override val textSources: TextSourcesList? by lazy { rawEntities ?.asTextSources(text ?: return@lazy null) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt index 8f78a4c37b..0b749649d2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendVideo.kt @@ -25,6 +25,7 @@ fun SendVideo( thumb: InputFile? = null, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -48,6 +49,7 @@ fun SendVideo( text, parseMode, null, + spoilered, duration, width, height, @@ -75,6 +77,7 @@ fun SendVideo( video: InputFile, thumb: InputFile? = null, entities: TextSourcesList, + spoilered: Boolean = false, duration: Long? = null, width: Int? = null, height: Int? = null, @@ -98,6 +101,7 @@ fun SendVideo( entities.makeString(), null, entities.toRawMessageEntities(), + spoilered, duration, width, height, @@ -137,6 +141,8 @@ data class SendVideoData internal constructor( override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, @SerialName(durationField) override val duration: Long? = null, @SerialName(widthField) @@ -163,7 +169,8 @@ data class SendVideoData internal constructor( TextableSendMessageRequest>, ThumbedSendMessageRequest>, DuratedSendMessageRequest>, - SizedSendMessageRequest> + SizedSendMessageRequest>, + OptionallyWithSpoilerRequest { override val textSources: TextSourcesList? by lazy { rawEntities ?.asTextSources(text ?: return@lazy null) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index a9ff556602..8a3d8b8d85 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -228,6 +228,7 @@ const val allowsMultipleAnswersField = "allows_multiple_answers" const val isAnonymousField = "is_anonymous" const val canManageTopicsField = "can_manage_topics" const val captionEntitiesField = "caption_entities" +const val hasSpoilerField = "has_spoiler" const val loginUrlField = "login_url" const val forwardTextField = "forward_text" const val botUsernameField = "bot_username" @@ -242,8 +243,10 @@ const val customTitleField = "custom_title" const val optionIdsField = "option_ids" const val ipAddressField = "ip_address" const val linkedChatIdField = "linked_chat_id" +const val hasHiddenMembersField = "has_hidden_members" const val joinToSendMessagesField = "join_to_send_messages" const val joinByRequestField = "join_by_request" +const val hasAggressiveAntiSpamEnabledField = "has_aggressive_anti_spam_enabled" const val horizontalAccuracyField = "horizontal_accuracy" const val revokeMessagesField = "revoke_messages" const val messageAutoDeleteTimeField = "message_auto_delete_time" @@ -461,6 +464,7 @@ const val shouldSendEmailToProviderField = "send_email_to_provider" const val resizeKeyboardField = "resize_keyboard" const val oneTimeKeyboardField = "one_time_keyboard" const val inputFieldPlaceholderField = "input_field_placeholder" +const val isPersistentField = "is_persistent" const val priceDependOnShipAddressField = "is_flexible" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt index 753b947389..8ffecc9d3f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt @@ -13,7 +13,9 @@ data class ReplyKeyboardMarkup( val oneTimeKeyboard: Boolean? = null, @SerialName(inputFieldPlaceholderField) val inputFieldPlaceholder: String? = null, - val selective: Boolean? = null + val selective: Boolean? = null, + @SerialName(isPersistentField) + val persistent: Boolean? = null ) : KeyboardMarkup { init { if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt index 5c93f6ea71..fbc6f19f3d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/Extended.kt @@ -27,7 +27,9 @@ data class ExtendedChannelChatImpl( @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) override val pinnedMessage: Message? = null, @SerialName(linkedChatIdField) - override val linkedGroupChatId: IdChatIdentifier? = null + override val linkedGroupChatId: IdChatIdentifier? = null, + @SerialName(hasHiddenMembersField) + override val membersHidden: Boolean = false ) : ExtendedChannelChat @Serializable @@ -46,7 +48,9 @@ data class ExtendedGroupChatImpl( override val inviteLink: String? = null, @SerialName(pinnedMessageField) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) - override val pinnedMessage: Message? = null + override val pinnedMessage: Message? = null, + @SerialName(hasHiddenMembersField) + override val membersHidden: Boolean = false ) : ExtendedGroupChat @Serializable @@ -109,7 +113,11 @@ data class ExtendedSupergroupChatImpl( @SerialName(joinToSendMessagesField) override val requiresJoinForMessaging: Boolean = false, @SerialName(joinByRequestField) - override val requireAdminApproveToJoin: Boolean = false + override val requireAdminApproveToJoin: Boolean = false, + @SerialName(hasAggressiveAntiSpamEnabledField) + override val isAggressiveAntiSpamEnabled: Boolean = false, + @SerialName(hasHiddenMembersField) + override val membersHidden: Boolean = false ) : ExtendedSupergroupChat @Serializable @@ -146,7 +154,11 @@ data class ExtendedForumChatImpl( @SerialName(joinToSendMessagesField) override val requiresJoinForMessaging: Boolean = false, @SerialName(joinByRequestField) - override val requireAdminApproveToJoin: Boolean = false + override val requireAdminApproveToJoin: Boolean = false, + @SerialName(hasAggressiveAntiSpamEnabledField) + override val isAggressiveAntiSpamEnabled: Boolean = false, + @SerialName(hasHiddenMembersField) + override val membersHidden: Boolean = false ) : ExtendedForumChat @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt index f3e5cf61ca..734b8bacc3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ExtendedAbstracts.kt @@ -31,6 +31,7 @@ sealed interface ExtendedPublicChat : ExtendedChat, PublicChat { val inviteLink: String? @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) val pinnedMessage: Message? + val membersHidden: Boolean } @Serializable(ExtendedChatSerializer::class) @@ -50,6 +51,11 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat, Ext * This field represents field "join_by_request" from API */ val requireAdminApproveToJoin: Boolean + + /** + * This field represents field "has_aggressive_anti_spam_enabled" from API + */ + val isAggressiveAntiSpamEnabled: Boolean } @Serializable(ExtendedChatSerializer::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index c963d3babf..7aaf0bf72d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -34,11 +34,13 @@ data class VideoFile( @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toTelegramMediaVideo( text: String? = null, - parseMode: ParseMode? = null + parseMode: ParseMode? = null, + spoilered: Boolean = false ) = TelegramMediaVideo( fileId, text, parseMode, + spoilered, width, height, duration, @@ -47,10 +49,12 @@ inline fun VideoFile.toTelegramMediaVideo( @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toTelegramMediaVideo( - textSources: TextSourcesList + textSources: TextSourcesList, + spoilered: Boolean = false ) = TelegramMediaVideo( fileId, textSources, + spoilered, width, height, duration, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt index 782f9b0799..64a8287081 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/MediaGroupMemberTelegramMedia.kt @@ -20,4 +20,4 @@ sealed interface AudioMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMed sealed interface DocumentMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia @Serializable(MediaGroupMemberTelegramMediaSerializer::class) -sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia +sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia, SpoilerableTelegramMedia diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SpoilerableTelegramMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SpoilerableTelegramMedia.kt new file mode 100644 index 0000000000..d54b6e4c77 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/SpoilerableTelegramMedia.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.types.media + +import dev.inmo.tgbotapi.abstracts.SpoilerableData + +sealed interface SpoilerableTelegramMedia : TelegramMedia, SpoilerableData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt index 557f8f7107..7f73206e76 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaAnimation.kt @@ -18,15 +18,17 @@ fun TelegramMediaAnimation( file: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, width: Int? = null, height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb) +) = TelegramMediaAnimation(file, text, parseMode, null, spoilered, width, height, duration, thumb) fun TelegramMediaAnimation( file: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, width: Int? = null, height: Int? = null, duration: Long? = null, @@ -36,6 +38,7 @@ fun TelegramMediaAnimation( entities.makeString(), null, entities.toRawMessageEntities(), + spoilered, width, height, duration, @@ -51,11 +54,13 @@ data class TelegramMediaAnimation internal constructor( override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, override val thumb: InputFile? = null -) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput { +) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput, SpoilerableTelegramMedia { override val type: String = "animation" override val textSources: TextSourcesList? by lazy { rawEntities ?.asTextSources(text ?: return@lazy null) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt index b66a07c987..5678e2f35f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaPhoto.kt @@ -18,13 +18,15 @@ internal const val photoTelegramMediaType = "photo" fun TelegramMediaPhoto( file: InputFile, text: String? = null, - parseMode: ParseMode? = null -) = TelegramMediaPhoto(file, text, parseMode, null) + parseMode: ParseMode? = null, + spoilered: Boolean = false +) = TelegramMediaPhoto(file, text, parseMode, null, spoilered) fun TelegramMediaPhoto( file: InputFile, - entities: TextSourcesList -) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities()) + entities: TextSourcesList, + spoilered: Boolean = false +) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered) @Serializable data class TelegramMediaPhoto internal constructor( @@ -34,7 +36,9 @@ data class TelegramMediaPhoto internal constructor( @SerialName(parseModeField) override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) - private val rawEntities: List? = null + private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, ) : TelegramMedia, VisualMediaGroupMemberTelegramMedia { override val type: String = photoTelegramMediaType override val textSources: TextSourcesList? by lazy { @@ -50,16 +54,20 @@ data class TelegramMediaPhoto internal constructor( fun PhotoSize.toTelegramMediaPhoto( text: String? = null, - parseMode: ParseMode? = null + parseMode: ParseMode? = null, + spoilered: Boolean = false ): TelegramMediaPhoto = TelegramMediaPhoto( fileId, text, - parseMode + parseMode, + spoilered ) fun PhotoSize.toTelegramMediaPhoto( - textSources: TextSourcesList = emptyList() + textSources: TextSourcesList = emptyList(), + spoilered: Boolean = false ): TelegramMediaPhoto = TelegramMediaPhoto( fileId, - textSources + textSources, + spoilered ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt index c5cb541938..3999b118e1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/media/TelegramMediaVideo.kt @@ -18,20 +18,22 @@ fun TelegramMediaVideo( file: InputFile, text: String? = null, parseMode: ParseMode? = null, + spoilered: Boolean = false, width: Int? = null, height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = TelegramMediaVideo(file, text, parseMode, null, width, height, duration, thumb) +) = TelegramMediaVideo(file, text, parseMode, null, spoilered, width, height, duration, thumb) fun TelegramMediaVideo( file: InputFile, entities: TextSourcesList, + spoilered: Boolean = false, width: Int? = null, height: Int? = null, duration: Long? = null, thumb: InputFile? = null -) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb) +) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered, width, height, duration, thumb) @Serializable data class TelegramMediaVideo internal constructor ( @@ -42,6 +44,8 @@ data class TelegramMediaVideo internal constructor ( override val parseMode: ParseMode? = null, @SerialName(captionEntitiesField) private val rawEntities: List? = null, + @SerialName(hasSpoilerField) + override val spoilered: Boolean = false, override val width: Int? = null, override val height: Int? = null, override val duration: Long? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/ForumTopicEdited.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/ForumTopicEdited.kt new file mode 100644 index 0000000000..ae3d4a8b7d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/ForumTopicEdited.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.forum + +import dev.inmo.tgbotapi.types.CustomEmojiId +import dev.inmo.tgbotapi.types.iconColorField +import dev.inmo.tgbotapi.types.iconCustomEmojiIdField +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent +import dev.inmo.tgbotapi.types.nameField +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ForumTopicEdited( + @SerialName(nameField) + val name: String, + @SerialName(iconCustomEmojiIdField) + val iconEmojiId: CustomEmojiId? = null +) : ForumEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicHidden.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicHidden.kt new file mode 100644 index 0000000000..a502a28ad5 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicHidden.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.forum + +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent +import kotlinx.serialization.Serializable + +@Serializable +object GeneralForumTopicHidden : ForumEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicUnhidden.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicUnhidden.kt new file mode 100644 index 0000000000..4bb2192512 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/GeneralForumTopicUnhidden.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.forum + +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent +import kotlinx.serialization.Serializable + +@Serializable +object GeneralForumTopicUnhidden : ForumEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/WriteAccessAllowed.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/WriteAccessAllowed.kt new file mode 100644 index 0000000000..6cd4ad5a67 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/forum/WriteAccessAllowed.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.forum + +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent +import kotlinx.serialization.Serializable + +@Serializable +object WriteAccessAllowed : ForumEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 5a98fdf863..c5c6277daa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -14,7 +14,11 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.* @@ -58,6 +62,7 @@ internal data class RawMessage( private val entities: RawMessageEntities? = null, private val caption: String? = null, private val caption_entities: RawMessageEntities? = null, + private val has_media_spoiler: Boolean? = null, private val audio: AudioFile? = null, private val document: DocumentFile? = null, private val animation: AnimationFile? = null, @@ -96,8 +101,12 @@ internal data class RawMessage( // Forum private val forum_topic_created: ForumTopicCreated? = null, + private val forum_topic_edited: ForumTopicEdited? = null, private val forum_topic_closed: ForumTopicClosed? = null, private val forum_topic_reopened: ForumTopicReopened? = null, + private val general_forum_topic_hidden: GeneralForumTopicHidden? = null, + private val general_forum_topic_unhidden: GeneralForumTopicUnhidden? = null, + private val write_access_allowed: WriteAccessAllowed? = null, // AutoDelete Message time changed private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null, @@ -129,13 +138,15 @@ internal data class RawMessage( video != null -> VideoContent( video, caption, - adaptedCaptionEntities + adaptedCaptionEntities, + has_media_spoiler ?: false ) animation != null -> AnimationContent( animation, document, caption, - adaptedCaptionEntities + adaptedCaptionEntities, + has_media_spoiler ?: false ) document != null -> DocumentContent( document, @@ -150,7 +161,8 @@ internal data class RawMessage( photo != null -> PhotoContent( photo.toList(), caption, - adaptedCaptionEntities + adaptedCaptionEntities, + has_media_spoiler ?: false ) sticker != null -> StickerContent(sticker) dice != null -> DiceContent(dice) @@ -213,6 +225,10 @@ internal data class RawMessage( video_chat_scheduled != null -> video_chat_scheduled message_auto_delete_timer_changed != null -> message_auto_delete_timer_changed forum_topic_created != null -> forum_topic_created + forum_topic_edited != null -> forum_topic_edited + general_forum_topic_hidden != null -> general_forum_topic_hidden + general_forum_topic_unhidden != null -> general_forum_topic_unhidden + write_access_allowed != null -> write_access_allowed forum_topic_closed != null -> forum_topic_closed forum_topic_reopened != null -> forum_topic_reopened video_chat_ended != null -> video_chat_ended diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt index d7087fc5c7..89b9ad92d0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/Abstracts.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.message.content +import dev.inmo.tgbotapi.abstracts.SpoilerableData import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.ChatIdentifier @@ -23,6 +24,7 @@ sealed interface MessageContent: ResendableContent { mediaGroupPartContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, textedMediaContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, mediaContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, + spoilerableMediaContentAdditionalBuilder: PolymorphicModuleBuilder.() -> Unit = {}, mediaCollectionContentAdditionalBuilder: PolymorphicModuleBuilder>.() -> Unit = {}, additionalBuilder: PolymorphicModuleBuilder.() -> Unit = {} ) = SerializersModule { @@ -66,6 +68,13 @@ sealed interface MessageContent: ResendableContent { mediaContentAdditionalBuilder() } + polymorphic(SpoilerableMediaContent::class) { + subclass(VideoContent::class) + subclass(PhotoContent::class) + subclass(AnimationContent::class) + + spoilerableMediaContentAdditionalBuilder() + } polymorphic(TextedMediaContent::class) { subclass(PhotoContent::class) subclass(VoiceContent::class) @@ -111,6 +120,8 @@ sealed interface MediaContent: MessageContent { fun asTelegramMedia(): TelegramMedia } +sealed interface SpoilerableMediaContent : MediaContent, SpoilerableData + @ClassCastsIncluded sealed interface ResendableContent { fun createResend( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt index 21dd74142f..724552a98f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AbstractsMedia.kt @@ -39,6 +39,6 @@ sealed interface MediaGroupPartContent : TextedMediaContent { fun toMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia } -sealed interface VisualMediaGroupPartContent : MediaGroupPartContent { +sealed interface VisualMediaGroupPartContent : MediaGroupPartContent, SpoilerableMediaContent { override fun toMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AnimationContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AnimationContent.kt index 8c842f36c6..cd7df6d9f1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AnimationContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/AnimationContent.kt @@ -18,8 +18,9 @@ data class AnimationContent( override val media: AnimationFile, val includedDocument: DocumentFile?, override val text: String?, - override val textSources: TextSourcesList = emptyList() -) : TextedMediaContent { + override val textSources: TextSourcesList = emptyList(), + override val spoilered: Boolean = false +) : TextedMediaContent, SpoilerableMediaContent { override fun createResend( chatId: ChatIdentifier, messageThreadId: MessageThreadId?, @@ -33,6 +34,7 @@ data class AnimationContent( media.fileId, media.thumb ?.fileId, textSources, + spoilered, media.duration, media.width, media.height, @@ -47,6 +49,7 @@ data class AnimationContent( override fun asTelegramMedia(): TelegramMediaAnimation = TelegramMediaAnimation( media.fileId, textSources, + spoilered, media.width, media.height, media.duration, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt index 75a488771e..8b3e98c1ee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/PhotoContent.kt @@ -17,7 +17,8 @@ import kotlinx.serialization.Serializable data class PhotoContent( override val mediaCollection: Photo, override val text: String? = null, - override val textSources: TextSourcesList = emptyList() + override val textSources: TextSourcesList = emptyList(), + override val spoilered: Boolean = false ) : MediaCollectionContent, VisualMediaGroupPartContent { override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content") @@ -33,6 +34,7 @@ data class PhotoContent( chatId, media.fileId, textSources, + spoilered, messageThreadId, disableNotification, protectContent, @@ -43,5 +45,5 @@ data class PhotoContent( override fun toMediaGroupMemberTelegramMedia(): TelegramMediaPhoto = asTelegramMedia() - override fun asTelegramMedia(): TelegramMediaPhoto = media.toTelegramMediaPhoto(textSources) + override fun asTelegramMedia(): TelegramMediaPhoto = media.toTelegramMediaPhoto(textSources, spoilered) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt index 53312ed522..15d877b916 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/VideoContent.kt @@ -17,7 +17,8 @@ import kotlinx.serialization.Serializable data class VideoContent( override val media: VideoFile, override val text: String? = null, - override val textSources: TextSourcesList = emptyList() + override val textSources: TextSourcesList = emptyList(), + override val spoilered: Boolean = false ) : VisualMediaGroupPartContent { override fun createResend( chatId: ChatIdentifier, @@ -32,6 +33,7 @@ data class VideoContent( media.fileId, media.thumb ?.fileId, textSources, + spoilered, media.duration, media.width, media.height, diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index 60b258a418..500b28a94b 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -213,6 +213,7 @@ import dev.inmo.tgbotapi.types.media.DocumentMediaGroupMemberTelegramMedia import dev.inmo.tgbotapi.types.media.DuratedTelegramMedia import dev.inmo.tgbotapi.types.media.MediaGroupMemberTelegramMedia import dev.inmo.tgbotapi.types.media.SizedTelegramMedia +import dev.inmo.tgbotapi.types.media.SpoilerableTelegramMedia import dev.inmo.tgbotapi.types.media.TelegramMedia import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation import dev.inmo.tgbotapi.types.media.TelegramMediaAudio @@ -251,7 +252,11 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VideoChatEvent import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden +import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatEnded import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatParticipantsInvited import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatScheduled @@ -315,6 +320,7 @@ import dev.inmo.tgbotapi.types.message.content.MessageContent import dev.inmo.tgbotapi.types.message.content.PhotoContent import dev.inmo.tgbotapi.types.message.content.PollContent import dev.inmo.tgbotapi.types.message.content.ResendableContent +import dev.inmo.tgbotapi.types.message.content.SpoilerableMediaContent import dev.inmo.tgbotapi.types.message.content.StaticLocationContent import dev.inmo.tgbotapi.types.message.content.StickerContent import dev.inmo.tgbotapi.types.message.content.TextContent @@ -2643,6 +2649,16 @@ public inline fun TelegramMedia.sizedTelegramMediaOrThrow(): SizedTelegramMedia public inline fun TelegramMedia.ifSizedTelegramMedia(block: (SizedTelegramMedia) -> T): T? = sizedTelegramMediaOrNull() ?.let(block) +public inline fun TelegramMedia.spoilerableTelegramMediaOrNull(): SpoilerableTelegramMedia? = this + as? dev.inmo.tgbotapi.types.media.SpoilerableTelegramMedia + +public inline fun TelegramMedia.spoilerableTelegramMediaOrThrow(): SpoilerableTelegramMedia = this + as dev.inmo.tgbotapi.types.media.SpoilerableTelegramMedia + +public inline fun + TelegramMedia.ifSpoilerableTelegramMedia(block: (SpoilerableTelegramMedia) -> T): T? = + spoilerableTelegramMediaOrNull() ?.let(block) + public inline fun TelegramMedia.telegramMediaAnimationOrNull(): TelegramMediaAnimation? = this as? dev.inmo.tgbotapi.types.media.TelegramMediaAnimation @@ -2923,6 +2939,15 @@ public inline fun ChatEvent.forumTopicCreatedOrThrow(): ForumTopicCreated = this public inline fun ChatEvent.ifForumTopicCreated(block: (ForumTopicCreated) -> T): T? = forumTopicCreatedOrNull() ?.let(block) +public inline fun ChatEvent.forumTopicEditedOrNull(): ForumTopicEdited? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited + +public inline fun ChatEvent.forumTopicEditedOrThrow(): ForumTopicEdited = this as + dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicEdited + +public inline fun ChatEvent.ifForumTopicEdited(block: (ForumTopicEdited) -> T): T? = + forumTopicEditedOrNull() ?.let(block) + public inline fun ChatEvent.forumTopicReopenedOrNull(): ForumTopicReopened? = this as? dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened @@ -2932,6 +2957,34 @@ public inline fun ChatEvent.forumTopicReopenedOrThrow(): ForumTopicReopened = th public inline fun ChatEvent.ifForumTopicReopened(block: (ForumTopicReopened) -> T): T? = forumTopicReopenedOrNull() ?.let(block) +public inline fun ChatEvent.generalForumTopicHiddenOrNull(): GeneralForumTopicHidden? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden + +public inline fun ChatEvent.generalForumTopicHiddenOrThrow(): GeneralForumTopicHidden = this as + dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicHidden + +public inline fun ChatEvent.ifGeneralForumTopicHidden(block: (GeneralForumTopicHidden) -> T): T? + = generalForumTopicHiddenOrNull() ?.let(block) + +public inline fun ChatEvent.generalForumTopicUnhiddenOrNull(): GeneralForumTopicUnhidden? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden + +public inline fun ChatEvent.generalForumTopicUnhiddenOrThrow(): GeneralForumTopicUnhidden = this as + dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidden + +public inline fun + ChatEvent.ifGeneralForumTopicUnhidden(block: (GeneralForumTopicUnhidden) -> T): T? = + generalForumTopicUnhiddenOrNull() ?.let(block) + +public inline fun ChatEvent.writeAccessAllowedOrNull(): WriteAccessAllowed? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed + +public inline fun ChatEvent.writeAccessAllowedOrThrow(): WriteAccessAllowed = this as + dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed + +public inline fun ChatEvent.ifWriteAccessAllowed(block: (WriteAccessAllowed) -> T): T? = + writeAccessAllowedOrNull() ?.let(block) + public inline fun ChatEvent.videoChatEndedOrNull(): VideoChatEnded? = this as? dev.inmo.tgbotapi.types.message.ChatEvents.voice.VideoChatEnded @@ -3516,6 +3569,16 @@ public inline fun ResendableContent.mediaContentOrThrow(): MediaContent = this a public inline fun ResendableContent.ifMediaContent(block: (MediaContent) -> T): T? = mediaContentOrNull() ?.let(block) +public inline fun ResendableContent.spoilerableMediaContentOrNull(): SpoilerableMediaContent? = this + as? dev.inmo.tgbotapi.types.message.content.SpoilerableMediaContent + +public inline fun ResendableContent.spoilerableMediaContentOrThrow(): SpoilerableMediaContent = this + as dev.inmo.tgbotapi.types.message.content.SpoilerableMediaContent + +public inline fun + ResendableContent.ifSpoilerableMediaContent(block: (SpoilerableMediaContent) -> T): T? = + spoilerableMediaContentOrNull() ?.let(block) + public inline fun ResendableContent.audioMediaGroupPartContentOrNull(): AudioMediaGroupPartContent? = this as? dev.inmo.tgbotapi.types.message.content.AudioMediaGroupPartContent diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt index 2d913a1445..9bd0909aa1 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt @@ -22,7 +22,8 @@ fun ReplyKeyboardBuilder.build( oneTimeKeyboard: Boolean? = null, inputFieldPlaceholder: String? = null, selective: Boolean? = null, -) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) + persistent: Boolean? = null, +) = ReplyKeyboardMarkup(matrix, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent) /** * Row builder of [KeyboardButton] @@ -43,8 +44,9 @@ inline fun replyKeyboard( oneTimeKeyboard: Boolean? = null, inputFieldPlaceholder: String? = null, selective: Boolean? = null, + persistent: Boolean? = null, block: ReplyKeyboardBuilder.() -> Unit -) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) +) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent) /** * Factory-function for [ReplyKeyboardBuilder], but in difference with [replyKeyboard] this method will create single-row @@ -55,8 +57,9 @@ inline fun flatReplyKeyboard( oneTimeKeyboard: Boolean? = null, inputFieldPlaceholder: String? = null, selective: Boolean? = null, + persistent: Boolean? = null, block: ReplyKeyboardRowBuilder.() -> Unit -) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective) { +) = replyKeyboard(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective, persistent) { row(block) } diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt index 2b8bc76fc6..f6f45fdfd1 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt @@ -9,11 +9,13 @@ fun ReplyKeyboardMarkup( resizeKeyboard: Boolean? = null, oneTimeKeyboard: Boolean? = null, inputFieldPlaceholder: String? = null, - selective: Boolean? = null + selective: Boolean? = null, + persistent: Boolean? = null ): ReplyKeyboardMarkup = ReplyKeyboardMarkup( flatMatrix { buttons.forEach { +it } }, resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, - selective + selective, + persistent ) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 7306a8946a..89cdc3fde6 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.bot.exceptions.* import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier import dev.inmo.tgbotapi.requests.GetUpdates +import dev.inmo.tgbotapi.requests.webhook.DeleteWebhook import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.content.MediaGroupContent @@ -23,7 +24,14 @@ fun TelegramBot.longPollingFlow( timeoutSeconds: Seconds = 30, exceptionsHandler: (ExceptionHandler)? = null, allowedUpdates: List? = ALL_UPDATES_LIST, + autoDisableWebhooks: Boolean = true ): Flow = channelFlow { + if (autoDisableWebhooks) { + runCatchingSafely { + execute(DeleteWebhook()) + } + } + var lastUpdateIdentifier: UpdateIdentifier? = null while (isActive) { @@ -86,8 +94,9 @@ fun TelegramBot.startGettingOfUpdatesByLongPolling( scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: (ExceptionHandler)? = null, allowedUpdates: List? = ALL_UPDATES_LIST, + autoDisableWebhooks: Boolean = true, updatesReceiver: UpdateReceiver -): Job = longPollingFlow(timeoutSeconds, exceptionsHandler, allowedUpdates).subscribeSafely( +): Job = longPollingFlow(timeoutSeconds, exceptionsHandler, allowedUpdates, autoDisableWebhooks).subscribeSafely( scope, exceptionsHandler ?: defaultSafelyExceptionHandler, updatesReceiver @@ -101,7 +110,8 @@ fun TelegramBot.createAccumulatedUpdatesRetrieverFlow( avoidInlineQueries: Boolean = false, avoidCallbackQueries: Boolean = false, exceptionsHandler: ExceptionHandler? = null, - allowedUpdates: List? = ALL_UPDATES_LIST + allowedUpdates: List? = ALL_UPDATES_LIST, + autoDisableWebhooks: Boolean = true, ): Flow = longPollingFlow( timeoutSeconds = 0, exceptionsHandler = { @@ -111,7 +121,8 @@ fun TelegramBot.createAccumulatedUpdatesRetrieverFlow( else -> exceptionsHandler ?.invoke(it) } }, - allowedUpdates = allowedUpdates + allowedUpdates = allowedUpdates, + autoDisableWebhooks = autoDisableWebhooks ).filter { !(it is InlineQueryUpdate && avoidInlineQueries || it is CallbackQueryUpdate && avoidCallbackQueries) } @@ -122,12 +133,14 @@ fun TelegramBot.retrieveAccumulatedUpdates( scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: (ExceptionHandler)? = null, allowedUpdates: List? = ALL_UPDATES_LIST, + autoDisableWebhooks: Boolean = true, updatesReceiver: UpdateReceiver ): Job = createAccumulatedUpdatesRetrieverFlow( avoidInlineQueries, avoidCallbackQueries, exceptionsHandler, - allowedUpdates + allowedUpdates, + autoDisableWebhooks ).subscribeSafelyWithoutExceptions( scope.LinkedSupervisorScope() ) { @@ -139,6 +152,7 @@ fun TelegramBot.retrieveAccumulatedUpdates( avoidInlineQueries: Boolean = false, avoidCallbackQueries: Boolean = false, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + autoDisableWebhooks: Boolean = true, exceptionsHandler: ExceptionHandler? = null ) = retrieveAccumulatedUpdates( avoidInlineQueries, @@ -146,6 +160,7 @@ fun TelegramBot.retrieveAccumulatedUpdates( scope, exceptionsHandler, flowsUpdatesFilter.allowedUpdates, + autoDisableWebhooks, flowsUpdatesFilter.asUpdateReceiver ) @@ -155,6 +170,7 @@ suspend fun TelegramBot.flushAccumulatedUpdates( scope: CoroutineScope = CoroutineScope(Dispatchers.Default), allowedUpdates: List? = ALL_UPDATES_LIST, exceptionsHandler: ExceptionHandler? = null, + autoDisableWebhooks: Boolean = true, updatesReceiver: UpdateReceiver = {} ) = retrieveAccumulatedUpdates( avoidInlineQueries, @@ -162,6 +178,7 @@ suspend fun TelegramBot.flushAccumulatedUpdates( scope, exceptionsHandler, allowedUpdates, + autoDisableWebhooks, updatesReceiver ).join() @@ -173,9 +190,10 @@ fun TelegramBot.longPolling( updatesFilter: UpdatesFilter, timeoutSeconds: Seconds = 30, scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + autoDisableWebhooks: Boolean = true, exceptionsHandler: ExceptionHandler? = null ): Job = updatesFilter.run { - startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) + startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, autoDisableWebhooks, asUpdateReceiver) } /** @@ -189,18 +207,21 @@ fun TelegramBot.longPolling( scope: CoroutineScope = CoroutineScope(Dispatchers.Default), exceptionsHandler: ExceptionHandler? = null, flowsUpdatesFilterUpdatesKeeperCount: Int = 100, + autoDisableWebhooks: Boolean = true, flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit -): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, exceptionsHandler) +): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, autoDisableWebhooks, exceptionsHandler) fun RequestsExecutor.startGettingOfUpdatesByLongPolling( updatesFilter: UpdatesFilter, timeoutSeconds: Seconds = 30, exceptionsHandler: ExceptionHandler? = null, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) + scope: CoroutineScope = CoroutineScope(Dispatchers.Default), + autoDisableWebhooks: Boolean = true, ): Job = startGettingOfUpdatesByLongPolling( timeoutSeconds, scope, exceptionsHandler, updatesFilter.allowedUpdates, + autoDisableWebhooks, updatesFilter.asUpdateReceiver ) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt index f83d2fd7dc..9796336908 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt @@ -6,3 +6,5 @@ typealias EventHandler = WebApp.() -> Unit typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit typealias PopupClosedEventHandler = WebApp.(String?) -> Unit +typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean +typealias TextReceivedEventHandler = WebApp.(String) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt index ff71329074..853d63f730 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt @@ -8,4 +8,6 @@ sealed class EventType(val typeName: String) { object SettingsButtonClicked : EventType("settingsButtonClicked") object InvoiceClosed : EventType("invoiceClosed") object PopupClosed : EventType("popupClosed") + object QRTextReceived : EventType("qrTextReceived") + object ClipboardTextReceived : EventType("clipboardTextReceived") } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/OpenLinkParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/OpenLinkParams.kt new file mode 100644 index 0000000000..42578ad329 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/OpenLinkParams.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.webapps + +import kotlin.js.json + +external interface OpenLinkParams { + @JsName("try_instant_view") + val tryInstantView: Boolean +} + +fun OpenLinkParams( + tryInstantView: Boolean +) = json( + *listOfNotNull( + "try_instant_view" to tryInstantView + ).toTypedArray() +).unsafeCast() diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/QRTextReceivedCallback.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/QRTextReceivedCallback.kt new file mode 100644 index 0000000000..0a82244698 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/QRTextReceivedCallback.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps + +typealias QRTextReceivedCallback = (String) -> Boolean diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/TextReceivedCallback.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/TextReceivedCallback.kt new file mode 100644 index 0000000000..3ba259b773 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/TextReceivedCallback.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.webapps + +typealias TextReceivedCallback = (String) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index d31d1d6cf9..b17a6a456c 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -8,6 +8,8 @@ import dev.inmo.tgbotapi.webapps.popup.* external class WebApp { val version: String + val platform: String + val initData: String val initDataUnsafe: WebAppInitData @@ -33,6 +35,9 @@ external class WebApp { fun showPopup(params: PopupParams, callback: ClosePopupCallback? = definedExternally) fun showAlert(message: String, callback: AlertCallback? = definedExternally) fun showConfirm(message: String, callback: ConfirmCallback? = definedExternally) + fun showScanQrPopup(params: ScanQrPopupParams, callback: QRTextReceivedCallback? = definedExternally) + fun closeScanQrPopup() + fun readTextFromClipboard(callback: TextReceivedCallback? = definedExternally) @JsName("MainButton") val mainButton: MainButton @@ -50,6 +55,10 @@ external class WebApp { internal fun onEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit) @JsName("onEvent") internal fun onEventWithPopupClosedInfo(type: String, callback: (String?) -> Unit) + @JsName("onEvent") + internal fun onEventWithQRTextInfo(type: String, callback: (String) -> Boolean) + @JsName("onEvent") + internal fun onEventWithTextInfo(type: String, callback: (String) -> Unit) fun offEvent(type: String, callback: () -> Unit) @JsName("offEvent") @@ -124,6 +133,30 @@ fun WebApp.onEvent(type: EventType.PopupClosed, eventHandler: PopupClosedEventHa ) } +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onEvent(type: EventType.QRTextReceived, eventHandler: QRTextReceivedEventHandler) = { it: String -> + eventHandler(js("this").unsafeCast(), it) +}.also { + onEventWithQRTextInfo( + type.typeName, + callback = it + ) +} + +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onEvent(type: EventType.ClipboardTextReceived, eventHandler: TextReceivedEventHandler) = { it: String -> + eventHandler(js("this").unsafeCast(), it) +}.also { + onEventWithTextInfo( + type.typeName, + callback = it + ) +} + /** * @return The callback which should be used in case you want to turn off events handling */ @@ -152,6 +185,14 @@ fun WebApp.onInvoiceClosed(eventHandler: InvoiceClosedEventHandler) = onEvent(Ev * @return The callback which should be used in case you want to turn off events handling */ fun WebApp.onPopupClosed(eventHandler: PopupClosedEventHandler) = onEvent(EventType.PopupClosed, eventHandler) +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onQRTextReceived(eventHandler: QRTextReceivedEventHandler) = onEvent(EventType.QRTextReceived, eventHandler) +/** + * @return The callback which should be used in case you want to turn off events handling + */ +fun WebApp.onClipboardTextReceived(eventHandler: TextReceivedEventHandler) = onEvent(EventType.ClipboardTextReceived, eventHandler) fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData( initData, diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ScanQrPopupParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ScanQrPopupParams.kt new file mode 100644 index 0000000000..3a16e1c2f2 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/popup/ScanQrPopupParams.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.webapps.popup + +import kotlin.js.json + + +external interface ScanQrPopupParams { + val text: String? +} + +fun ScanQrPopupParams( + text: String? = null +) = json( + *listOfNotNull( + ("text" to text).takeIf { text != null } + ).toTypedArray() +).unsafeCast()