mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
uni_meow modularize
This commit is contained in:
parent
9574dd299b
commit
083e5d1b2f
@ -8,7 +8,7 @@ object MornyConfiguration {
|
||||
val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono"
|
||||
val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s"
|
||||
|
||||
val VERSION = "2.0.0-alpha6"
|
||||
val VERSION = "2.0.0-alpha7"
|
||||
val VERSION_DELTA: Option[String] = None
|
||||
val CODENAME = "guanggu"
|
||||
|
||||
|
@ -21,6 +21,12 @@ object MornyCoeur {
|
||||
|
||||
val THREAD_SERVER_EXIT = "system-exit"
|
||||
|
||||
/** A tag that shows current [[MornyCoeur!]] is running under
|
||||
* test mode.
|
||||
*
|
||||
* @see [[MornyCoeur.testRun]] for more introduction for test mode.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
object TestRun
|
||||
|
||||
case class OnInitializingPreContext (
|
||||
@ -72,6 +78,31 @@ object MornyCoeur {
|
||||
|
||||
}
|
||||
|
||||
/** The Coeur (Main Class) of Morny.
|
||||
*
|
||||
* ## Lifecycle
|
||||
*
|
||||
* todo...
|
||||
*
|
||||
* ## Test Mode
|
||||
*
|
||||
* Coeur supports a special launch mode called test mode.When running
|
||||
* under test mode, this instance will only run till the initialize
|
||||
* is complete and exit immediately. In the lifecycle, it is run till
|
||||
* [[MornyModule.onInitializingPost]] event.
|
||||
*
|
||||
* In this way, it will be available to see if the initialize result is
|
||||
* under expected while not really start the service (aka. will not
|
||||
* take side effect).
|
||||
*
|
||||
* This mode can be enabled by the parameter [[testRun]]. When exited
|
||||
* under this mode, the [[exitReason]] will be a special value [[TestRun]].
|
||||
*
|
||||
* @param modules all morny modules.
|
||||
* @param config the immutable [[MornyConfig]] instance, will use all
|
||||
* over this Morny (Coeur) instance.
|
||||
* @param testRun if the instance should run under test mode.
|
||||
*/
|
||||
class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(testRun: Boolean = false) {
|
||||
|
||||
given MornyCoeur = this
|
||||
|
@ -25,7 +25,6 @@ class MornyCoreModule extends MornyModule {
|
||||
eventManager.register(
|
||||
// ACTIVITY_RECORDER
|
||||
// KUOHUANHUAN_NEED_SLEEP
|
||||
OnUniMeowTrigger(using commandManager),
|
||||
$OnUserRandom.RandomSelect,
|
||||
//noinspection NonAsciiCharacters
|
||||
$OnUserRandom.尊嘟假嘟,
|
||||
@ -44,8 +43,6 @@ class MornyCoreModule extends MornyModule {
|
||||
val $MornyInformationOlds = MornyInformationOlds(using $MornyInformation)
|
||||
val $MornyManagers = MornyManagers()
|
||||
//noinspection NonAsciiCharacters
|
||||
val $喵呜 = 喵呜()
|
||||
//noinspection NonAsciiCharacters
|
||||
val $创 = 创()
|
||||
commandManager.register(
|
||||
|
||||
@ -69,22 +66,10 @@ class MornyCoreModule extends MornyModule {
|
||||
|
||||
Testing(),
|
||||
DirectMsgClear(),
|
||||
|
||||
//noinspection NonAsciiCharacters
|
||||
私わね(),
|
||||
//noinspection NonAsciiCharacters
|
||||
$喵呜.Progynova,
|
||||
//noinspection NonAsciiCharacters
|
||||
$创.Chuang
|
||||
|
||||
)
|
||||
//noinspection NonAsciiCharacters
|
||||
commandManager.registerForUni(
|
||||
$喵呜.抱抱,
|
||||
$喵呜.揉揉,
|
||||
$喵呜.贴贴,
|
||||
$喵呜.蹭蹭
|
||||
)
|
||||
|
||||
queryManager.register(
|
||||
RawText(),
|
||||
|
@ -159,7 +159,7 @@ object ServerMain {
|
||||
|
||||
try
|
||||
MornyCoeur(
|
||||
MornyCoreModule() :: Nil
|
||||
ServerModulesLoader.load()
|
||||
)(using config build)(
|
||||
testRun = mode_testRun
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny.bot.command
|
||||
import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
import cc.sukazyo.cono.morny.bot.command.MornyCommandManager.CommandMap
|
||||
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
||||
import com.pengrad.telegrambot.model.{BotCommand, DeleteMyCommands, Update}
|
||||
@ -12,9 +13,11 @@ import scala.collection.mutable
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
import scala.language.postfixOps
|
||||
|
||||
object MornyCommandManager:
|
||||
type CommandMap = mutable.SeqMap[String, ISimpleCommand]
|
||||
|
||||
class MornyCommandManager (using coeur: MornyCoeur) {
|
||||
|
||||
private type CommandMap = mutable.SeqMap[String, ISimpleCommand]
|
||||
private val commands: CommandMap = mutable.SeqMap.empty
|
||||
def register [T <: ISimpleCommand] (commands: T*): Unit =
|
||||
for (i <- commands)
|
||||
|
@ -1,11 +1,10 @@
|
||||
package cc.sukazyo.cono.morny.bot.event
|
||||
package cc.sukazyo.cono.morny.uni_meow
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener}
|
||||
import cc.sukazyo.cono.morny.bot.command.MornyCommandManager
|
||||
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||
import cc.sukazyo.cono.morny.Log.logger
|
||||
|
||||
class OnUniMeowTrigger (using commands: MornyCommandManager) extends EventListener {
|
||||
class BotEventUniMeowTrigger (using commands: UniMeowCommandManager) extends EventListener {
|
||||
|
||||
override def onMessage (using event: EventEnv): Unit = {
|
||||
import event.*
|
||||
@ -13,7 +12,7 @@ class OnUniMeowTrigger (using commands: MornyCommandManager) extends EventListen
|
||||
givenCxt >> { (input: InputCommand) =>
|
||||
logger trace s"got input command {$input} from event-context"
|
||||
|
||||
for ((name, command_instance) <- commands.commands_uni) {
|
||||
for ((name, command_instance) <- commands.commands) {
|
||||
logger trace s"checking uni-meow $name"
|
||||
if (name == input.command)
|
||||
logger trace "checked"
|
@ -0,0 +1,45 @@
|
||||
package cc.sukazyo.cono.morny.uni_meow
|
||||
|
||||
import cc.sukazyo.cono.morny.{MornyCoeur, MornyModule, MornySystem}
|
||||
|
||||
class ModuleUniMeow extends MornyModule {
|
||||
|
||||
override val id: String = "coeur.uni_meow"
|
||||
override val name: String = "Coeur Uni-Meow Commands"
|
||||
override val version: String = MornySystem.VERSION
|
||||
override val description: String | Null =
|
||||
// language=Markdown
|
||||
"""Provides support for unicode command in Telegram. Also provided some
|
||||
|interesting commands.
|
||||
|
|
||||
|Requires *Group Privacy* set to `disabled` on the bot account.""".stripMargin
|
||||
|
||||
val uni_commands: UniMeowCommandManager = UniMeowCommandManager()
|
||||
|
||||
override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = {
|
||||
import cxt.*
|
||||
|
||||
externalContext << uni_commands
|
||||
givenCxt << uni_commands
|
||||
eventManager.register(
|
||||
BotEventUniMeowTrigger(using uni_commands)
|
||||
)
|
||||
|
||||
//noinspection NonAsciiCharacters
|
||||
val $喵呜 = 喵呜()
|
||||
//noinspection NonAsciiCharacters
|
||||
uni_commands.register(
|
||||
$喵呜.抱抱,
|
||||
$喵呜.揉揉,
|
||||
$喵呜.贴贴,
|
||||
$喵呜.蹭蹭
|
||||
)
|
||||
//noinspection NonAsciiCharacters
|
||||
commandManager.register(
|
||||
$喵呜.Progynova,
|
||||
私わね()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cc.sukazyo.cono.morny.uni_meow
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.command.ISimpleCommand
|
||||
import cc.sukazyo.cono.morny.bot.command.MornyCommandManager.CommandMap
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class UniMeowCommandManager {
|
||||
|
||||
private[uni_meow] val commands: CommandMap = mutable.SeqMap.empty
|
||||
def register [T <: ISimpleCommand] (commands: T*): Unit =
|
||||
for (i <- commands)
|
||||
this.commands += (i.name -> i)
|
||||
for (alias <- i.aliases)
|
||||
this.commands += (alias.name -> i)
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cc.sukazyo.cono.morny.bot.command
|
||||
package cc.sukazyo.cono.morny.uni_meow
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ISimpleCommand, ITelegramCommand}
|
||||
import cc.sukazyo.cono.morny.data.TelegramStickers
|
||||
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec
|
@ -1,6 +1,7 @@
|
||||
package cc.sukazyo.cono.morny.bot.command
|
||||
package cc.sukazyo.cono.morny.uni_meow
|
||||
|
||||
import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ISimpleCommand}
|
||||
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
|
||||
import cc.sukazyo.cono.morny.util.UseMath.over
|
||||
import cc.sukazyo.cono.morny.util.UseRandom.*
|
Loading…
Reference in New Issue
Block a user