1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +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
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
val AccessibleMessage.threadIdOrNull
val Message.threadIdOrNull
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.PassportMessage
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.AnonymousGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
@ -3495,13 +3495,13 @@ public inline fun <T>
Message.ifCommonForumContentMessage(block: (CommonForumContentMessage<MessageContent>) -> T): T?
= commonForumContentMessageOrNull() ?.let(block)
public inline fun Message.accessibleMessageOrNull(): AccessibleMessage? = this as?
dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
public inline fun Message.accessibleMessageOrNull(): Message? = this as?
dev.inmo.tgbotapi.types.message.abstracts.Message
public inline fun Message.accessibleMessageOrThrow(): AccessibleMessage = this as
dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
public inline fun Message.accessibleMessageOrThrow(): Message = this as
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)
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.Username
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.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]
*/
@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
*/
@Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameMessage(
inline fun Message.sameMessage(
chatId: ChatIdentifier,
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
*/
@Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameMessage(
inline fun Message.sameMessage(
chat: Chat,
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
* and have equal [AccessibleMessage.messageId] identifier
* and have equal [Message.messageId] identifier
*/
@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
*
* @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")
inline fun AccessibleMessage.sameTopic(
inline fun Message.sameTopic(
chatId: ChatIdentifier,
threadId: MessageThreadId? = chatId.threadId
) = sameChat(chatId) && threadIdOrNull == threadId
@ -77,10 +77,10 @@ inline fun AccessibleMessage.sameTopic(
* 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
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier
* messages from one chat and have equal [Message.threadIdOrNull] identifier
*/
@Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameThread(
inline fun Message.sameThread(
chatId: ChatIdentifier,
threadId: MessageThreadId? = chatId.threadId
) = sameTopic(chatId, threadId)
@ -89,10 +89,10 @@ inline fun AccessibleMessage.sameThread(
* 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
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier
* messages from one chat and have equal [Message.threadIdOrNull] identifier
*/
@Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameTopic(
inline fun Message.sameTopic(
chat: Chat,
threadId: MessageThreadId? = chat.id.threadId
) = sameTopic(chat.id, threadId)
@ -101,10 +101,10 @@ inline fun AccessibleMessage.sameTopic(
* 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
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier
* messages from one chat and have equal [Message.threadIdOrNull] identifier
*/
@Suppress("NOTHING_TO_INLINE")
inline fun AccessibleMessage.sameThread(
inline fun Message.sameThread(
chat: Chat,
threadId: MessageThreadId? = chat.id.threadId
) = sameThread(chat.id, threadId)
@ -113,16 +113,16 @@ inline fun AccessibleMessage.sameThread(
* 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
* messages from one chat and have equal [AccessibleMessage.threadIdOrNull] identifier
* messages from one chat and have equal [Message.threadIdOrNull] identifier
*/
@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
*
* @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")
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.voice.*
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.content.TextContent
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.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.textsources.BotCommandTextSource
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
*/
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.
@ -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
*/
fun AccessibleMessage.notForumMessage(): Boolean = !forumMessage()
fun Message.notForumMessage(): Boolean = !forumMessage()