change the Question Mark Reply from reply to forward copy

This commit is contained in:
A.C.Sukazyo Eyre 2025-02-04 22:33:23 +08:00
parent d8c7d1285b
commit 4c165976b5
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
2 changed files with 23 additions and 5 deletions

View File

@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
VERSION = 1.4.1-alpha.1
VERSION = 1.5.0-alpha.1
USE_DELTA = false
VERSION_DELTA =

View File

@ -4,7 +4,7 @@ import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener}
import cc.sukazyo.cono.morny.MornyCoeur
import cc.sukazyo.cono.morny.bot.event.OnQuestionMarkReply.isAllMessageMark
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
import com.pengrad.telegrambot.request.SendMessage
import com.pengrad.telegrambot.request.{ForwardMessage, SendMessage}
import scala.language.postfixOps
import scala.util.boundary
@ -21,9 +21,27 @@ class OnQuestionMarkReply (using coeur: MornyCoeur) extends EventListener {
if (1 over 8) chance_is false then return;
if !isAllMessageMark(using update.message.text) then return;
coeur.account exec SendMessage(
update.message.chat.id, update.message.text
).replyToMessageId(update.message.messageId)
if (update.message.hasProtectedContent) {
// Copy the message
// if the message cannot be forwarded.
// Some chats may have restrictions on forwarding messages caused
// we cannot use the best behavior (on the 'else' branch).
// so use this as a fallback.
// Due to the CopyMessage function only exists in the newer version's API,
// we can only send the message again.
// TODO: change to CopyMessage when the API is updated.
// This is the old behavior with changes that removes the reply to the original message.
coeur.account exec SendMessage(
update.message.chat.id, update.message.text
)
} else {
// forward the message
// if the message triggers question mark repeat
coeur.account exec ForwardMessage(
update.message.chat.id,
update.message.chat.id, update.message.messageId
)
}
event.setEventOk
}