-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from simple-robot/dev/merge-events
优化消息事件相关的类型继承关系结构;增加部分对发送文本消息以及MessageEntity的元素支持
- Loading branch information
Showing
19 changed files
with
855 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...te/simbot/component/telegram/core/event/internal/AbstractTelegramGroupMessageEventImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2024. ForteScarlet. | ||
* | ||
* This file is part of simbot-component-telegram. | ||
* | ||
* simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms | ||
* of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package love.forte.simbot.component.telegram.core.event.internal | ||
|
||
import love.forte.simbot.component.telegram.core.actor.TelegramMember | ||
import love.forte.simbot.component.telegram.core.actor.internal.toTelegramMember | ||
import love.forte.simbot.component.telegram.core.bot.internal.TelegramBotImpl | ||
import love.forte.simbot.component.telegram.core.bot.requestDataBy | ||
import love.forte.simbot.component.telegram.core.event.TelegramGroupMessageEvent | ||
import love.forte.simbot.component.telegram.core.message.TelegramMessageContent | ||
import love.forte.simbot.component.telegram.core.message.TelegramMessageReceipt | ||
import love.forte.simbot.component.telegram.core.message.internal.TelegramMessageContentImpl | ||
import love.forte.simbot.component.telegram.core.message.internal.toTelegramMessageReceipt | ||
import love.forte.simbot.component.telegram.core.message.send | ||
import love.forte.simbot.message.MessageContent | ||
import love.forte.simbot.telegram.api.message.SendMessageApi | ||
import love.forte.simbot.telegram.api.message.buildSendMessageApi | ||
import love.forte.simbot.telegram.type.ChatId | ||
import love.forte.simbot.telegram.type.Message | ||
import love.forte.simbot.telegram.type.ReplyParameters | ||
|
||
|
||
/** | ||
* | ||
* @author ForteScarlet | ||
*/ | ||
internal abstract class AbstractTelegramGroupMessageEventImpl( | ||
final override val bot: TelegramBotImpl, | ||
final override val sourceContent: Message | ||
) : TelegramGroupMessageEvent { | ||
override val messageContent: TelegramMessageContent = TelegramMessageContentImpl(bot, sourceContent) | ||
|
||
override suspend fun author(): TelegramMember { | ||
// TODO from!!? check senderChat? | ||
return sourceContent.from!!.toTelegramMember(bot) | ||
} | ||
|
||
override suspend fun reply(text: String): TelegramMessageReceipt { | ||
return buildSendMessageApi(ChatId(sourceContent.chat.id), text) { | ||
replyParameters = ReplyParameters(sourceContent.messageId) | ||
}.requestDataBy(bot).toTelegramMessageReceipt(bot) | ||
} | ||
|
||
override suspend fun reply(message: love.forte.simbot.message.Message): TelegramMessageReceipt { | ||
return bot.send(message, sourceContent.chat.id) { | ||
SendMessageApi.builder().also { | ||
it.replyParameters = ReplyParameters(messageId = sourceContent.messageId) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun reply(messageContent: MessageContent): TelegramMessageReceipt { | ||
return bot.send( | ||
messageContent, | ||
sourceContent.chat.id, | ||
copyApiBlock = { | ||
replyParameters = ReplyParameters(messageId = sourceContent.messageId) | ||
}, | ||
builderFactory = { | ||
SendMessageApi.builder().also { | ||
it.replyParameters = ReplyParameters(messageId = sourceContent.messageId) | ||
} | ||
} | ||
) | ||
} | ||
} |
Oops, something went wrong.