mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-24 03:57:39 +08:00
fix /exit will mis-trigger on meant to be used on other bots
This commit is contained in:
parent
1230b9e6b5
commit
c632df4cd8
@ -1,4 +1,5 @@
|
||||
package cc.sukazyo.cono.morny.bot.command
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.command.ICommandAlias.HiddenAlias
|
||||
import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers
|
||||
@ -7,13 +8,25 @@ import cc.sukazyo.cono.morny.daemon.MornyReport
|
||||
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||
import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramFormatter.*
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
import com.pengrad.telegrambot.model.{Chat, Update}
|
||||
import com.pengrad.telegrambot.request.SendSticker
|
||||
|
||||
import scala.language.postfixOps
|
||||
|
||||
class MornyManagers (using coeur: MornyCoeur) {
|
||||
|
||||
/** Check if the command is directly targeted to Morny.
|
||||
*
|
||||
* If and only if the command is in private chat, or the command is in group chat AND the command target is explicitly
|
||||
* set to Morny's username, then the command is targeted to Morny.
|
||||
*
|
||||
* This aims to reduce the mis-trigger on some commands that are easily collisions to other bots and are important.
|
||||
*/
|
||||
def isMornyTargeted (event: Update, command: InputCommand): Boolean =
|
||||
if event.message.chat.`type` != Chat.Type.Private && command.target != coeur.username then false
|
||||
else if command.target != null && command.target != coeur.username then false
|
||||
else true
|
||||
|
||||
object Exit extends ITelegramCommand {
|
||||
|
||||
override val name: String = "exit"
|
||||
@ -23,6 +36,10 @@ class MornyManagers (using coeur: MornyCoeur) {
|
||||
|
||||
override def execute (using command: InputCommand, event: Update): Unit = {
|
||||
|
||||
if !isMornyTargeted(event, command) then
|
||||
logger debug "seems command does not targeted to morny, skipped"
|
||||
return
|
||||
|
||||
val user = event.message.from
|
||||
|
||||
if (coeur.trusted isTrusted user.id) {
|
||||
@ -58,6 +75,10 @@ class MornyManagers (using coeur: MornyCoeur) {
|
||||
|
||||
override def execute (using command: InputCommand, event: Update): Unit = {
|
||||
|
||||
if !isMornyTargeted(event, command) then
|
||||
logger debug "seems command does not targeted to morny, skipped"
|
||||
return
|
||||
|
||||
val user = event.message.from
|
||||
|
||||
if (coeur.trusted isTrusted user.id) {
|
||||
|
@ -6,7 +6,6 @@ import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, MornyQueries}
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
import com.google.gson.Gson
|
||||
import com.pengrad.telegrambot.model.Update
|
||||
import com.pengrad.telegrambot.model.request.InlineQueryResult
|
||||
import com.pengrad.telegrambot.request.AnswerInlineQuery
|
||||
|
||||
@ -32,8 +31,7 @@ class MornyOnInlineQuery (using queryManager: MornyQueries) (using coeur: MornyC
|
||||
|
||||
if (results isEmpty) return;
|
||||
|
||||
logger debug resultAnswers.map(Gson().toJson(_)).mkString("\n")
|
||||
|
||||
logger trace "Query answers:\n" + resultAnswers.map(" " + Gson().toJson(_)).mkString("\n")
|
||||
coeur.account exec AnswerInlineQuery(
|
||||
update.inlineQuery.id, resultAnswers toArray:_*
|
||||
).cacheTime(cacheTime).isPersonal(isPersonal)
|
||||
|
@ -6,7 +6,7 @@ import com.pengrad.telegrambot.model.request.InlineQueryResult
|
||||
object InlineQueryUnit {
|
||||
|
||||
object defaults:
|
||||
val CACHE_TIME = 1
|
||||
val CACHE_TIME = 300
|
||||
val IS_PERSONAL = false
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user