mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2025-04-29 09:32:04 +08:00
add defined[T] for EventEnv
- Now OnQuestionMarkReply skips expired event will use this feature - OnUserRandom.RandomSelect capability patch for OnQuestionMarkReply will use this feature
This commit is contained in:
parent
2b2b93ddaa
commit
666607b430
@ -51,6 +51,20 @@ class EventEnv (
|
||||
case None => ConsumeResult(false)
|
||||
}
|
||||
|
||||
// fixme: defined() series is not tested yet
|
||||
|
||||
def defined [T: ClassTag]: Boolean = {
|
||||
variables get classTag[T].runtimeClass match
|
||||
case Some(_) => true
|
||||
case None => false
|
||||
}
|
||||
|
||||
def defined [T] (t: Class[T]): Boolean = {
|
||||
variables get t match
|
||||
case Some(_) => true
|
||||
case None => false
|
||||
}
|
||||
|
||||
def consume [T: ClassTag] (consumer: T => Unit): ConsumeResult =
|
||||
variables get classTag[T].runtimeClass match
|
||||
case Some(i) => consumer(i.asInstanceOf[T]); ConsumeResult(true)
|
||||
|
@ -11,10 +11,10 @@ class MornyEventListeners (using manager: EventListenerManager) (using coeur: Mo
|
||||
// KUOHUANHUAN_NEED_SLEEP
|
||||
OnOnAlias(),
|
||||
OnUniMeowTrigger(using coeur.commands),
|
||||
OnQuestionMarkReply(),
|
||||
$OnUserRandom.RandomSelect,
|
||||
//noinspection NonAsciiCharacters
|
||||
$OnUserRandom.尊嘟假嘟,
|
||||
OnQuestionMarkReply(),
|
||||
OnUserSlashAction(),
|
||||
OnCallMe(),
|
||||
OnCallMsgSend(),
|
||||
|
@ -16,12 +16,7 @@ class OnQuestionMarkReply (using coeur: MornyCoeur) extends EventListener {
|
||||
import event.update
|
||||
|
||||
// FIXME: not tested yet, due to cannot connect to test bot
|
||||
if boundary[Boolean] {
|
||||
event.consume[MornyOnUpdateTimestampOffsetLock.ExpiredEvent.type] { _ =>
|
||||
boundary.break(true)
|
||||
}
|
||||
false
|
||||
} then {
|
||||
if event.defined[MornyOnUpdateTimestampOffsetLock.ExpiredEvent.type] then {
|
||||
logger.debug("OnQuestionMarkReply: expired event, skipped")
|
||||
return
|
||||
} else {
|
||||
@ -32,8 +27,12 @@ class OnQuestionMarkReply (using coeur: MornyCoeur) extends EventListener {
|
||||
|
||||
import cc.sukazyo.cono.morny.util.UseMath.over
|
||||
import cc.sukazyo.cono.morny.util.UseRandom.chance_is
|
||||
if (1 over 8) chance_is false then return;
|
||||
if !isAllMessageMark(using update.message.text) then return;
|
||||
// provide a mark to notify the following event
|
||||
// that the current event is all made of question marks
|
||||
event.provide(OnQuestionMarkReply.Marked)
|
||||
|
||||
if (1 over 8) chance_is false then return;
|
||||
|
||||
if (update.message.hasProtectedContent) {
|
||||
// Copy the message
|
||||
@ -77,4 +76,6 @@ object OnQuestionMarkReply {
|
||||
}
|
||||
}
|
||||
|
||||
object Marked
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ class OnUserRandom (using coeur: MornyCoeur) {
|
||||
if rand_half then _con1 else _con2
|
||||
case USER_IF_QUERY(_con) =>
|
||||
// for capability with [[OnQuestionMarkReply]]
|
||||
if OnQuestionMarkReply.isAllMessageMark(using _con) then return;
|
||||
// fixme: not tested yet
|
||||
if event.defined[OnQuestionMarkReply.Marked.type] then return;
|
||||
(if rand_half then "不" else "") + _con
|
||||
case _ => null
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user