1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

several more fixes

This commit is contained in:
InsanusMokrassar 2024-01-12 02:14:46 +06:00
parent 66e31e5d0c
commit 225fedde3a
5 changed files with 33 additions and 34 deletions

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.utils.extensions package dev.inmo.tgbotapi.utils.extensions
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
val AccessibleMessage.threadIdOrNull val Message.threadIdOrNull
get() = (this as? PossiblyTopicMessage) ?.threadId get() = (this as? PossiblyTopicMessage) ?.threadId

View File

@ -260,7 +260,7 @@ import dev.inmo.tgbotapi.types.message.CommonSupergroupEventMessage
import dev.inmo.tgbotapi.types.message.ForwardInfo import dev.inmo.tgbotapi.types.message.ForwardInfo
import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.message.PassportMessage
import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.PrivateEventMessage
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
@ -3495,13 +3495,13 @@ public inline fun <T>
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T? Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
= commonForumContentMessageOrNull() ?.let(block) = commonForumContentMessageOrNull() ?.let(block)
public inline fun Message.accessibleMessageOrNull(): AccessibleMessage? = this as? public inline fun Message.accessibleMessageOrNull(): Message? = this as?
dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage dev.inmo.tgbotapi.types.message.abstracts.Message
public inline fun Message.accessibleMessageOrThrow(): AccessibleMessage = this as public inline fun Message.accessibleMessageOrThrow(): Message = this as
dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage dev.inmo.tgbotapi.types.message.abstracts.Message
public inline fun <T> Message.ifAccessibleMessage(block: (AccessibleMessage) -> T): T? = public inline fun <T> Message.ifMessage(block: (Message) -> T): T? =
accessibleMessageOrNull() ?.let(block) accessibleMessageOrNull() ?.let(block)
public inline fun Message.inaccessibleMessageOrNull(): InaccessibleMessage? = this as? public inline fun Message.inaccessibleMessageOrNull(): InaccessibleMessage? = this as?

View File

@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.Username import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.types.chat.Chat import dev.inmo.tgbotapi.types.chat.Chat
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.threadId import dev.inmo.tgbotapi.types.threadId
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
@ -32,43 +32,43 @@ inline fun WithPreviewChat.sameChat(chat: Chat) =
* @return true in case if [this] message is placed in the same chat that [other] * @return true in case if [this] message is placed in the same chat that [other]
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun WithPreviewChat.sameChat(other: AccessibleMessage) = sameChat(other.chat) inline fun WithPreviewChat.sameChat(other: Message) = sameChat(other.chat)
/** /**
* @return true in case if [this] message is from the same chat (with id == [chatId]) and [this] [AccessibleMessage.messageId] * @return true in case if [this] message is from the same chat (with id == [chatId]) and [this] [Message.messageId]
* equal [messageId] identifier * equal [messageId] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameMessage( inline fun Message.sameMessage(
chatId: ChatIdentifier, chatId: ChatIdentifier,
messageId: MessageId messageId: MessageId
) = sameChat(chatId) && this.messageId == messageId ) = sameChat(chatId) && this.messageId == messageId
/** /**
* @return true in case if [this] message is from the same [chat] and [this] [AccessibleMessage.messageId] equal [messageId] * @return true in case if [this] message is from the same [chat] and [this] [Message.messageId] equal [messageId]
* identifier * identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameMessage( inline fun Message.sameMessage(
chat: Chat, chat: Chat,
messageId: MessageId messageId: MessageId
) = sameChat(chat) && this.messageId == messageId ) = sameChat(chat) && this.messageId == messageId
/** /**
* @return true in case if [this] message is the same as [other]. The same here means that these messages from one chat * @return true in case if [this] message is the same as [other]. The same here means that these messages from one chat
* and have equal [AccessibleMessage.messageId] identifier * and have equal [Message.messageId] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameMessage(other: AccessibleMessage) = sameMessage(other.chat, other.messageId) inline fun Message.sameMessage(other: Message) = sameMessage(other.chat, other.messageId)
/** /**
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these * @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * messages from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameTopic( inline fun Message.sameTopic(
chatId: ChatIdentifier, chatId: ChatIdentifier,
threadId: MessageThreadId? = chatId.threadId threadId: MessageThreadId? = chatId.threadId
) = sameChat(chatId) && threadIdOrNull == threadId ) = sameChat(chatId) && threadIdOrNull == threadId
@ -77,10 +77,10 @@ inline fun AccessibleMessage.sameTopic(
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these * @return true in case if [this] message is in the chat [chatId] and topic [threadId]. The same here means that these
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * messages from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameThread( inline fun Message.sameThread(
chatId: ChatIdentifier, chatId: ChatIdentifier,
threadId: MessageThreadId? = chatId.threadId threadId: MessageThreadId? = chatId.threadId
) = sameTopic(chatId, threadId) ) = sameTopic(chatId, threadId)
@ -89,10 +89,10 @@ inline fun AccessibleMessage.sameThread(
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these * @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * messages from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameTopic( inline fun Message.sameTopic(
chat: Chat, chat: Chat,
threadId: MessageThreadId? = chat.id.threadId threadId: MessageThreadId? = chat.id.threadId
) = sameTopic(chat.id, threadId) ) = sameTopic(chat.id, threadId)
@ -101,10 +101,10 @@ inline fun AccessibleMessage.sameTopic(
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these * @return true in case if [this] message is from the [chat] and topic [threadId]. The same here means that these
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * messages from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameThread( inline fun Message.sameThread(
chat: Chat, chat: Chat,
threadId: MessageThreadId? = chat.id.threadId threadId: MessageThreadId? = chat.id.threadId
) = sameThread(chat.id, threadId) ) = sameThread(chat.id, threadId)
@ -113,16 +113,16 @@ inline fun AccessibleMessage.sameThread(
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is from the same chat and topic as [other]. The same here means that these * @return true in case if [this] message is from the same chat and topic as [other]. The same here means that these
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * messages from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameTopic(other: AccessibleMessage) = sameTopic(other.chat, other.threadIdOrNull) inline fun Message.sameTopic(other: Message) = sameTopic(other.chat, other.threadIdOrNull)
/** /**
* Thread is the same thing that topic * Thread is the same thing that topic
* *
* @return true in case if [this] message is in the same topic as the [other]. The same here means that these messages * @return true in case if [this] message is in the same topic as the [other]. The same here means that these messages
* from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier * from one chat and have equal [Message.threadIdOrNull] identifier
*/ */
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameThread(other: AccessibleMessage) = sameTopic(other) inline fun Message.sameThread(other: Message) = sameTopic(other)

View File

@ -11,7 +11,6 @@ import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList

View File

@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates
import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.TextContent import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull
@ -58,10 +58,10 @@ fun CommonMessage<*>.hasNoCommands(): Boolean = !this.hasCommands()
* } * }
* ``` * ```
* *
* @return true if this [AccessibleMessage] is from forum ([threadIdOrNull] is not null). False otherwise. * @return true if this [Message] is from forum ([threadIdOrNull] is not null). False otherwise.
* @see notForumMessage * @see notForumMessage
*/ */
fun AccessibleMessage.forumMessage(): Boolean = threadIdOrNull != null fun Message.forumMessage(): Boolean = threadIdOrNull != null
/** /**
* A predicate to test that message has not been sent in the forum. * A predicate to test that message has not been sent in the forum.
@ -76,7 +76,7 @@ fun AccessibleMessage.forumMessage(): Boolean = threadIdOrNull != null
* } * }
* ``` * ```
* *
* @return true if this [AccessibleMessage] is not from forum ([threadIdOrNull] is not null). False otherwise. * @return true if this [Message] is not from forum ([threadIdOrNull] is not null). False otherwise.
* @see forumMessage * @see forumMessage
*/ */
fun AccessibleMessage.notForumMessage(): Boolean = !forumMessage() fun Message.notForumMessage(): Boolean = !forumMessage()