diff --git a/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala b/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala index 00d99dc..bde5b4f 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/MornyCoeur.scala @@ -37,6 +37,9 @@ object MornyCoeur { userid: Long, tasks: Scheduler, trusted: MornyTrusted, + eventManager: EventListenerManager, + commandManager: MornyCommandManager, + queryManager: MornyQueryManager, givenCxt: GivenContext ) @@ -153,19 +156,45 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes /** current Morny's [[MornyTrusted]] instance */ val trusted: MornyTrusted = MornyTrusted() - modules.foreach(it => it.onInitializingPre(OnInitializingPreContext( - externalContext, - coeurStartTimestamp, account, username, userid, tasks, trusted, - initializeContext))) - val daemons: MornyDaemons = MornyDaemons() initializeContext << daemons val eventManager: EventListenerManager = EventListenerManager() - eventManager register MornyOnUpdateTimestampOffsetLock() val commands: MornyCommandManager = MornyCommandManager() val queries: MornyQueryManager = MornyQueryManager() + + // Coeur Initializing Pre Event + modules.foreach(it => it.onInitializingPre(OnInitializingPreContext( + externalContext, + coeurStartTimestamp, account, username, userid, tasks, trusted, + eventManager, commands, queries, + initializeContext))) + + // register core/api events + eventManager register MornyOnUpdateTimestampOffsetLock() eventManager register MornyOnTelegramCommand(using commands) eventManager register MornyOnInlineQuery(using queries) + { // register core commands + import bot.command.* + val $MornyHellos = MornyHellos() + val $MornyInformation = MornyInformation() + val $MornyInformationOlds = MornyInformationOlds(using $MornyInformation) + val $MornyManagers = MornyManagers() + commands.register( + + $MornyHellos.On, + $MornyHellos.Hello, + MornyInfoOnStart(), + + $MornyManagers.SaveData, + $MornyInformation, + $MornyInformationOlds.Version, + $MornyInformationOlds.Runtime, + $MornyManagers.Exit, + + DirectMsgClear(), + + ) + } // Coeur Initializing Event modules.foreach(it => it.onInitializing(OnInitializingContext( @@ -175,7 +204,6 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes initializeContext))) eventManager register daemons.reporter.EventStatistics.EventInfoCatcher - val watchDog: WatchDog = WatchDog("watch-dog", 1000, 1500, { (consumed, _) => import cc.sukazyo.cono.morny.util.CommonFormat.formatDuration as f logger warn @@ -184,6 +212,8 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes tasks.notifyIt() }) initializeContext / this << watchDog + + // Coeur Initializing Post Event modules.foreach(it => it.onInitializingPost(OnInitializingPostContext( externalContext, coeurStartTimestamp, account, username, userid, tasks, trusted, @@ -197,11 +227,13 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes logger info "done test run, exiting." this.exit(0, TestRun) + // Coeur Starting Pre configure_exitCleanup() - // put things that need to cleanup when exit below - // so that it will be correctly cleanup when normal run and will not execute in testRun. + + // Coeur Starting Event modules.foreach(it => it.onStarting(OnStartingContext( initializeContext))) + daemons.start() logger info "start telegram event listening" import com.pengrad.telegrambot.TelegramException @@ -250,6 +282,8 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes } }) + + // Coeur Starting Post Event modules.foreach(it => it.onStartingPost(OnStartingPostContext( initializeContext))) @@ -270,14 +304,15 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes private def exitCleanup (): Unit = { daemons.reporter.reportCoeurExit() + modules.foreach(it => it.onExiting) account.shutdown() logger info "stopped bot account" - modules.foreach(it => it.onExit) daemons.stop() tasks.waitForStop() logger info s"morny tasks stopped: remains ${tasks.amount} tasks not be executed" if config.commandLogoutClear then commands.automaticTGListRemove() + modules.foreach(it => it.onExited) logger info "done exit cleanup" } diff --git a/src/main/scala/cc/sukazyo/cono/morny/MornyCoreModule.scala b/src/main/scala/cc/sukazyo/cono/morny/MornyCoreModule.scala deleted file mode 100644 index 30130b8..0000000 --- a/src/main/scala/cc/sukazyo/cono/morny/MornyCoreModule.scala +++ /dev/null @@ -1,82 +0,0 @@ -package cc.sukazyo.cono.morny - -import cc.sukazyo.cono.morny.MornyCoeur.OnInitializingContext - -class MornyCoreModule extends MornyModule { - - override val id: String = "cc.sukazyo.cono.morny.bot" - override val name: String = "Morny Coeur - Core (for refactor temporary)" - override val version: String = MornySystem.VERSION - - override val description: String | Null = - """Core module of Morny Coeur. - | - |Exists for temporary use, when refactor completed it should be replaced - |by all other small modules that provide different functionality. - |""".stripMargin - - override def onInitializing (using MornyCoeur)(cxt: OnInitializingContext): Unit = { - import cc.sukazyo.cono.morny.bot.command.* - import cc.sukazyo.cono.morny.bot.event.* - import cc.sukazyo.cono.morny.bot.query.* - import cxt.* - - val $OnUserRandom = OnUserRandom() - eventManager.register( - // ACTIVITY_RECORDER - // KUOHUANHUAN_NEED_SLEEP - $OnUserRandom.RandomSelect, - //noinspection NonAsciiCharacters - $OnUserRandom.尊嘟假嘟, - OnQuestionMarkReply(), - OnUserSlashAction(), - OnCallMe(), - OnCallMsgSend(), - OnGetSocial(), - OnMedicationNotifyApply() - ) - - val $MornyHellos = MornyHellos() - val $IP186Query = IP186Query() - val $MornyInformation = MornyInformation() - val $MornyInformationOlds = MornyInformationOlds(using $MornyInformation) - val $MornyManagers = MornyManagers() - //noinspection NonAsciiCharacters - val $创 = 创() - commandManager.register( - - $MornyHellos.On, - $MornyHellos.Hello, - MornyInfoOnStart(), - GetUsernameAndId(), - Nbnhhsh(), - $IP186Query.IP, - $IP186Query.Whois, - Encryptor(), - MornyOldJrrp(), - GetSocial(), - - $MornyManagers.SaveData, - $MornyInformation, - $MornyInformationOlds.Version, - $MornyInformationOlds.Runtime, - $MornyManagers.Exit, - - Testing(), - DirectMsgClear(), - //noinspection NonAsciiCharacters - $创.Chuang - - ) - - queryManager.register( - RawText(), - MyInformation(), - ShareToolTwitter(), - ShareToolBilibili(), - ShareToolSocialContent() - ) - - } - -} diff --git a/src/main/scala/cc/sukazyo/cono/morny/MornyModule.scala b/src/main/scala/cc/sukazyo/cono/morny/MornyModule.scala index 5ae926b..d50b1f2 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/MornyModule.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/MornyModule.scala @@ -19,6 +19,7 @@ trait MornyModule { def onRoutineSavingData (using MornyCoeur): Unit = {} - def onExit (using MornyCoeur): Unit = {} + def onExiting (using MornyCoeur): Unit = {} + def onExited (using MornyCoeur): Unit = {} } diff --git a/src/main/scala/cc/sukazyo/cono/morny/ServerModulesLoader.scala b/src/main/scala/cc/sukazyo/cono/morny/ServerModulesLoader.scala index 4a1d1b2..8625440 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/ServerModulesLoader.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ServerModulesLoader.scala @@ -1,16 +1,23 @@ package cc.sukazyo.cono.morny -import cc.sukazyo.cono.morny.event_hack.ModuleEventHack -import cc.sukazyo.cono.morny.uni_meow.ModuleUniMeow - object ServerModulesLoader { def load (): List[MornyModule] = { List( - ModuleEventHack(), - ModuleUniMeow(), - MornyCoreModule() + + tele_utils.ModuleTeleUtils(), + randomize_somthing.ModuleRandomize(), + slash_action.ModuleSlashAction(), + nbnhhsh.ModuleNbnhhsh(), + ip186.ModuleIP186(), + encrypt_tool.ModuleEncryptor(), + call_me.ModuleCallMe(), + social_share.ModuleSocialShare(), + medication_timer.ModuleMedicationTimer(), + morny_misc.ModuleMornyMisc(), + uni_meow.ModuleUniMeow() + ) } diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommandManager.scala b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommandManager.scala index 77248c0..4d8b9c7 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommandManager.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommandManager.scala @@ -25,13 +25,6 @@ class MornyCommandManager (using coeur: MornyCoeur) { for (alias <- i.aliases) this.commands += (alias.name -> i) - private[bot] val commands_uni: CommandMap = mutable.SeqMap.empty - def registerForUni [T <: ISimpleCommand] (commands: T*): Unit = - for (i <- commands) - this.commands_uni += (i.name -> i) - for (alias <- i.aliases) - this.commands_uni += (alias.name -> i) - def execute (using command: InputCommand, event: Update): Boolean = { if (commands contains command.command) commands(command.command) execute; diff --git a/src/main/scala/cc/sukazyo/cono/morny/call_me/ModuleCallMe.scala b/src/main/scala/cc/sukazyo/cono/morny/call_me/ModuleCallMe.scala new file mode 100644 index 0000000..d268603 --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/call_me/ModuleCallMe.scala @@ -0,0 +1,22 @@ +package cc.sukazyo.cono.morny.call_me + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleCallMe extends MornyInternalModule { + + override val id: String = "morny.call_me" + override val name: String = "Morny Can Call Master" + override val description: String | Null = + """Provides a serial private message handler that can talk with Morny's Master + |inside the Morny bot PM.""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + + eventManager register OnCallMe() + eventManager register OnCallMsgSend() + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMe.scala b/src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMe.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMe.scala rename to src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMe.scala index 5d303d2..200d0b4 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMe.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMe.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.call_me import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMsgSend.scala b/src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMsgSend.scala similarity index 99% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMsgSend.scala rename to src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMsgSend.scala index 00a2ef8..32deb5d 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnCallMsgSend.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/call_me/OnCallMsgSend.scala @@ -1,10 +1,10 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.call_me import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec -import com.pengrad.telegrambot.model.{Chat, Message, MessageEntity, Update} +import com.pengrad.telegrambot.model.{Chat, Message, MessageEntity} import com.pengrad.telegrambot.model.request.ParseMode import com.pengrad.telegrambot.request.{GetChat, SendMessage, SendSticker} diff --git a/src/main/scala/cc/sukazyo/cono/morny/daemon/MornyDaemons.scala b/src/main/scala/cc/sukazyo/cono/morny/daemon/MornyDaemons.scala index 22f9fe0..cfef7b8 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/daemon/MornyDaemons.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/daemon/MornyDaemons.scala @@ -2,18 +2,15 @@ package cc.sukazyo.cono.morny.daemon import cc.sukazyo.cono.morny.Log.logger import cc.sukazyo.cono.morny.MornyCoeur -import cc.sukazyo.cono.morny.event_hack.EventHacker class MornyDaemons (using val coeur: MornyCoeur) { - val medicationTimer: MedicationTimer = MedicationTimer() val reporter: MornyReport = MornyReport() def start (): Unit = { logger notice "ALL Morny Daemons starting..." - medicationTimer.start() reporter.start() logger notice "Morny Daemons started." @@ -24,7 +21,6 @@ class MornyDaemons (using val coeur: MornyCoeur) { logger notice "stopping All Morny Daemons..." - medicationTimer.stop() reporter.stop() logger notice "stopped ALL Morny Daemons." diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Encryptor.scala b/src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/Encryptor.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/Encryptor.scala rename to src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/Encryptor.scala index 243f62c..5fb9989 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Encryptor.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/Encryptor.scala @@ -1,7 +1,8 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.encrypt_tool import cc.sukazyo.cono.morny.Log.logger import cc.sukazyo.cono.morny.MornyCoeur +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} import cc.sukazyo.cono.morny.bot.command.ICommandAlias.ListedAlias import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.util.tgapi.InputCommand diff --git a/src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/ModuleEncryptor.scala b/src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/ModuleEncryptor.scala new file mode 100644 index 0000000..d87ec6c --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/encrypt_tool/ModuleEncryptor.scala @@ -0,0 +1,20 @@ +package cc.sukazyo.cono.morny.encrypt_tool + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleEncryptor extends MornyInternalModule { + + override val id: String = "morny.encrypt" + override val name: String = "Morny Encrypt Tools" + override val description: String | Null = + // language=markdown + """Provides `/encrypt` command for enc/dec/hash things. + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + commandManager register Encryptor() + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/event_hack/ModuleEventHack.scala b/src/main/scala/cc/sukazyo/cono/morny/event_hack/ModuleEventHack.scala deleted file mode 100644 index 949e750..0000000 --- a/src/main/scala/cc/sukazyo/cono/morny/event_hack/ModuleEventHack.scala +++ /dev/null @@ -1,35 +0,0 @@ -package cc.sukazyo.cono.morny.event_hack - -import cc.sukazyo.cono.morny.internal.MornyInternalModule -import cc.sukazyo.cono.morny.MornyCoeur - -class ModuleEventHack extends MornyInternalModule { - - override val id: String = "morny.event_hack" - override val name: String = "Morny Event Hack" - override val description: String | Null = - // language=markdown - """The `/event_hack` command which can make morny output the next - |serialized event. - |""".stripMargin - - override def onInitializingPre (using MornyCoeur)(cxt: MornyCoeur.OnInitializingPreContext): Unit = { - import cxt.* - - given hacker: EventHacker = EventHacker() - - externalContext << hacker - givenCxt << hacker - - } - - override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { - import cxt.* - given EventHacker = externalContext >!> classOf[EventHacker] - - commandManager.register(BotCmdEventHack()) - eventManager.register(BotEventEventHackHandle()) - - } - -} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/IP186Query.scala b/src/main/scala/cc/sukazyo/cono/morny/ip186/BotCommand.scala similarity index 94% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/IP186Query.scala rename to src/main/scala/cc/sukazyo/cono/morny/ip186/BotCommand.scala index 47a3fe7..4580dd4 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/IP186Query.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ip186/BotCommand.scala @@ -1,7 +1,7 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.ip186 import cc.sukazyo.cono.morny.MornyCoeur -import cc.sukazyo.cono.morny.extra.ip186.IP186QueryHandler +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} import cc.sukazyo.cono.morny.util.tgapi.InputCommand import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec import com.pengrad.telegrambot.model.Update @@ -10,7 +10,7 @@ import com.pengrad.telegrambot.request.SendMessage import scala.language.postfixOps -class IP186Query (using coeur: MornyCoeur) { +class BotCommand (using coeur: MornyCoeur) { private enum Subs (val cmd: String): case IP extends Subs("ip") diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186QueryHandler.scala b/src/main/scala/cc/sukazyo/cono/morny/ip186/IP186QueryHandler.scala similarity index 97% rename from src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186QueryHandler.scala rename to src/main/scala/cc/sukazyo/cono/morny/ip186/IP186QueryHandler.scala index 630bf29..1685de3 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186QueryHandler.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ip186/IP186QueryHandler.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.ip186 +package cc.sukazyo.cono.morny.ip186 import cc.sukazyo.cono.morny.util.SttpPublic.{mornyBasicRequest, Schemes} import sttp.client3.{asString, HttpError, SttpClientException, UriContext} diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186Response.scala b/src/main/scala/cc/sukazyo/cono/morny/ip186/IP186Response.scala similarity index 56% rename from src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186Response.scala rename to src/main/scala/cc/sukazyo/cono/morny/ip186/IP186Response.scala index 6673044..12fb431 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/ip186/IP186Response.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/ip186/IP186Response.scala @@ -1,3 +1,3 @@ -package cc.sukazyo.cono.morny.extra.ip186 +package cc.sukazyo.cono.morny.ip186 case class IP186Response (url: String, body: String) diff --git a/src/main/scala/cc/sukazyo/cono/morny/ip186/ModuleIP186.scala b/src/main/scala/cc/sukazyo/cono/morny/ip186/ModuleIP186.scala new file mode 100644 index 0000000..612bb7c --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/ip186/ModuleIP186.scala @@ -0,0 +1,24 @@ +package cc.sukazyo.cono.morny.ip186 + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleIP186 extends MornyInternalModule { + + override val id: String = "morny.ext.ip186" + override val name: String = "Morny ip.186 support" + override val description: String | Null = + // language=markdown + """Provides `/ip` and `/markdown` commands, using ip.186516.xyz as query backend. + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + val $command = BotCommand() + commandManager.register( + $command.IP, + $command.Whois + ) + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/daemon/MedicationTimer.scala b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala similarity index 96% rename from src/main/scala/cc/sukazyo/cono/morny/daemon/MedicationTimer.scala rename to src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala index 8275614..5dadf15 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/daemon/MedicationTimer.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/MedicationTimer.scala @@ -1,8 +1,8 @@ -package cc.sukazyo.cono.morny.daemon +package cc.sukazyo.cono.morny.medication_timer import cc.sukazyo.cono.morny.Log.logger import cc.sukazyo.cono.morny.MornyCoeur -import cc.sukazyo.cono.morny.daemon.MedicationTimer.calcNextRoutineTimestamp +import cc.sukazyo.cono.morny.medication_timer.MedicationTimer.calcNextRoutineTimestamp import cc.sukazyo.cono.morny.util.schedule.RoutineTask import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec import cc.sukazyo.cono.morny.util.CommonFormat diff --git a/src/main/scala/cc/sukazyo/cono/morny/medication_timer/ModuleMedicationTimer.scala b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/ModuleMedicationTimer.scala new file mode 100644 index 0000000..33e80ee --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/ModuleMedicationTimer.scala @@ -0,0 +1,57 @@ +package cc.sukazyo.cono.morny.medication_timer + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.Log.logger +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleMedicationTimer extends MornyInternalModule { + + override val id: String = "morny.medication_timer" + override val name: String = "Morny Medication Timer" + override val description: String | Null = + """A notify tool for Morny notify its master to take medication. + |""".stripMargin + + override def onInitializingPre (using MornyCoeur)(cxt: MornyCoeur.OnInitializingPreContext): Unit = { + import cxt.* + + val instance: MedicationTimer = MedicationTimer() + externalContext << instance + givenCxt << instance + + } + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + + externalContext >> { (instance: MedicationTimer) => + eventManager register OnMedicationNotifyApply(using instance) + } || { + logger warn "There seems no Medication Timer instance is provided; skipped register events for it." + } + + } + + override def onStarting (using coeur: MornyCoeur)(cxt: MornyCoeur.OnStartingContext): Unit = { + import coeur.* + + externalContext >> { (instance: MedicationTimer) => + instance.start() + } || { + logger warn "There seems no Medication Timer instance is provided; skipped start it." + } + + } + + override def onExiting (using coeur: MornyCoeur): Unit = { + import coeur.* + + externalContext >> { (instance: MedicationTimer) => + instance.stop() + } || { + logger warn "There seems no Medication Timer instance need to be stop." + } + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnMedicationNotifyApply.scala b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/OnMedicationNotifyApply.scala similarity index 72% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnMedicationNotifyApply.scala rename to src/main/scala/cc/sukazyo/cono/morny/medication_timer/OnMedicationNotifyApply.scala index 40f20c4..38f3ae1 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnMedicationNotifyApply.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/medication_timer/OnMedicationNotifyApply.scala @@ -1,10 +1,10 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.medication_timer import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} import cc.sukazyo.cono.morny.MornyCoeur import com.pengrad.telegrambot.model.Message -class OnMedicationNotifyApply (using coeur: MornyCoeur) extends EventListener { +class OnMedicationNotifyApply (using instance: MedicationTimer)(using coeur: MornyCoeur) extends EventListener { override def onEditedMessage (using event: EventEnv): Unit = editedMessageProcess(event.update.editedMessage) @@ -13,7 +13,7 @@ class OnMedicationNotifyApply (using coeur: MornyCoeur) extends EventListener { private def editedMessageProcess (edited: Message)(using event: EventEnv): Unit = { if edited.chat.id != coeur.config.medicationNotifyToChat then return; - if coeur.daemons.medicationTimer.refreshNotificationWrite(edited) then + if instance.refreshNotificationWrite(edited) then event.setEventOk } diff --git a/src/main/scala/cc/sukazyo/cono/morny/morny_misc/ModuleMornyMisc.scala b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/ModuleMornyMisc.scala new file mode 100644 index 0000000..5bb699c --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/ModuleMornyMisc.scala @@ -0,0 +1,20 @@ +package cc.sukazyo.cono.morny.morny_misc + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleMornyMisc extends MornyInternalModule { + + override val id: String = "morny.misc" + override val name: String = "Morny Misc Things" + override val description: String | Null = "Misc things that from old days Morny." + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + + commandManager register MornyOldJrrp() + commandManager register Testing() + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/data/MornyJrrp.scala b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyJrrp.scala similarity index 93% rename from src/main/scala/cc/sukazyo/cono/morny/data/MornyJrrp.scala rename to src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyJrrp.scala index b2e9172..9be67bc 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/data/MornyJrrp.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyJrrp.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.data +package cc.sukazyo.cono.morny.morny_misc import cc.sukazyo.cono.morny.util.EpochDateTime.{EpochDays, EpochMillis} import com.pengrad.telegrambot.model.User diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyOldJrrp.scala b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyOldJrrp.scala similarity index 91% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyOldJrrp.scala rename to src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyOldJrrp.scala index 7e09ef4..3773a1c 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyOldJrrp.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/MornyOldJrrp.scala @@ -1,6 +1,7 @@ -package cc.sukazyo.cono.morny.bot.command -import cc.sukazyo.cono.morny.data.MornyJrrp +package cc.sukazyo.cono.morny.morny_misc + import cc.sukazyo.cono.morny.MornyCoeur +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramFormatter.* import cc.sukazyo.cono.morny.util.tgapi.InputCommand import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Testing.scala b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/Testing.scala similarity index 87% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/Testing.scala rename to src/main/scala/cc/sukazyo/cono/morny/morny_misc/Testing.scala index 1ea3b6a..dea0371 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Testing.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/morny_misc/Testing.scala @@ -1,6 +1,7 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.morny_misc 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.tgapi.TelegramExtensions.Bot.exec import com.pengrad.telegrambot.model.Update diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.scala b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/CommandNbnhhsh.scala similarity index 93% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.scala rename to src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/CommandNbnhhsh.scala index f988b6a..7b8743e 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/Nbnhhsh.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/CommandNbnhhsh.scala @@ -1,8 +1,8 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.nbnhhsh import cc.sukazyo.cono.morny.MornyCoeur +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} import cc.sukazyo.cono.morny.data.TelegramStickers -import cc.sukazyo.cono.morny.extra.NbnhhshQuery import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.escapeHtml as h import cc.sukazyo.cono.morny.util.tgapi.InputCommand import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec @@ -11,10 +11,9 @@ import com.pengrad.telegrambot.model.request.ParseMode import com.pengrad.telegrambot.request.{SendMessage, SendSticker} import sttp.client3.{HttpError, SttpClientException} -import java.io.IOException import scala.language.postfixOps -class Nbnhhsh (using coeur: MornyCoeur) extends ITelegramCommand { +class CommandNbnhhsh (using coeur: MornyCoeur) extends ITelegramCommand { private val NBNHHSH_RESULT_HEAD_HTML = // language=html diff --git a/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/ModuleNbnhhsh.scala b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/ModuleNbnhhsh.scala new file mode 100644 index 0000000..19bb05e --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/ModuleNbnhhsh.scala @@ -0,0 +1,25 @@ +package cc.sukazyo.cono.morny.nbnhhsh + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleNbnhhsh extends MornyInternalModule { + + override val id: String = "morny.nbnhhsh" + override val name: String = "Morny Nbnhhsh Query" + override val description: String | Null = + // language=markdown + """Provides a way to translate text using nbnhhsh(能不能好好说话) API. + | + |- command `/nbnhhsh` for translate input or replied. + |- inline query is still under WIP. + | + |API Url: https://lab.magiconch.com/api/nbnhhsh + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + commandManager register CommandNbnhhsh() + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/NbnhhshQuery.scala b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/NbnhhshQuery.scala similarity index 96% rename from src/main/scala/cc/sukazyo/cono/morny/extra/NbnhhshQuery.scala rename to src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/NbnhhshQuery.scala index 99a8170..0bd6ced 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/NbnhhshQuery.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/nbnhhsh/NbnhhshQuery.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra +package cc.sukazyo.cono.morny.nbnhhsh import cc.sukazyo.cono.morny.util.SttpPublic.mornyBasicRequest import com.google.gson.Gson diff --git a/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/ModuleRandomize.scala b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/ModuleRandomize.scala new file mode 100644 index 0000000..ee22c5f --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/ModuleRandomize.scala @@ -0,0 +1,29 @@ +package cc.sukazyo.cono.morny.randomize_somthing + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleRandomize extends MornyInternalModule { + + override val id: String = "morny.rand" + override val name: String = "Morny Randomize Something" + override val description: String | Null = + // language=markdown + """Randomize reply something by rand. + | + |Can randomly reply like *尊嘟假嘟*, and provide support for */ $this or $that*, + |and more interesting things. + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + + val $OnUserRandom = OnUserRandom() + eventManager register $OnUserRandom.RandomSelect + eventManager register OnQuestionMarkReply() + //noinspection NonAsciiCharacters + eventManager register $OnUserRandom.尊嘟假嘟 + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReply.scala b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnQuestionMarkReply.scala similarity index 90% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReply.scala rename to src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnQuestionMarkReply.scala index 2b37510..aaeb765 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReply.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnQuestionMarkReply.scala @@ -1,8 +1,8 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.randomize_somthing 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.randomize_somthing.OnQuestionMarkReply.isAllMessageMark import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec import com.pengrad.telegrambot.request.SendMessage diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserRandom.scala b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnUserRandom.scala similarity index 96% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserRandom.scala rename to src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnUserRandom.scala index 10bd70a..d5a0060 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserRandom.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/randomize_somthing/OnUserRandom.scala @@ -1,9 +1,8 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.randomize_somthing import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec -import com.pengrad.telegrambot.model.Update import com.pengrad.telegrambot.request.SendMessage import com.pengrad.telegrambot.response.SendResponse @@ -13,7 +12,6 @@ class OnUserRandom (using coeur: MornyCoeur) { object RandomSelect extends EventListener { - private val USER_OR_QUERY = "^(.+)(?:还是|or)(.+)$" r private val USER_IF_QUERY = "^(.+)(?:吗\\?|?|\\?|吗?)$" r diff --git a/src/main/scala/cc/sukazyo/cono/morny/slash_action/ModuleSlashAction.scala b/src/main/scala/cc/sukazyo/cono/morny/slash_action/ModuleSlashAction.scala new file mode 100644 index 0000000..840f622 --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/slash_action/ModuleSlashAction.scala @@ -0,0 +1,24 @@ +package cc.sukazyo.cono.morny.slash_action + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleSlashAction extends MornyInternalModule { + + override val id: String = "morny.slash" + override val name: String = "Morny SlashBot Support" + override val description: String | Null = + // language=markdown + """Reply calls like "抱", "摸摸". + | + |This module requires *Group Privacy* set to `disabled` on the bot account. + | + |(@RongSlashBot)[https://t.me/RongSlashBot] + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + eventManager register OnUserSlashAction() + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.scala b/src/main/scala/cc/sukazyo/cono/morny/slash_action/OnUserSlashAction.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.scala rename to src/main/scala/cc/sukazyo/cono/morny/slash_action/OnUserSlashAction.scala index 7e42632..f5591c9 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/slash_action/OnUserSlashAction.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.slash_action import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} diff --git a/src/main/scala/cc/sukazyo/cono/morny/social_share/ModuleSocialShare.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/ModuleSocialShare.scala new file mode 100644 index 0000000..566deba --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/ModuleSocialShare.scala @@ -0,0 +1,28 @@ +package cc.sukazyo.cono.morny.social_share + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur + +class ModuleSocialShare extends MornyInternalModule { + + override val id: String = "morny.social" + override val name: String = "Morny Social Media Share Tools" + override val description: String | Null = + """Provides a serial tools contains refactor share url, get content from + |social media, and more. + |""".stripMargin + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + + queryManager register query.ShareToolTwitter() + queryManager register query.ShareToolBilibili() + + commandManager register command.GetSocial() + eventManager register event.OnGetSocial() + queryManager register query.ShareToolSocialContent() + + } + +} + \ No newline at end of file diff --git a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialContent.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialContent.scala similarity index 94% rename from src/main/scala/cc/sukazyo/cono/morny/data/social/SocialContent.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialContent.scala index e7766bc..469e6fe 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialContent.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialContent.scala @@ -1,7 +1,7 @@ -package cc.sukazyo.cono.morny.data.social +package cc.sukazyo.cono.morny.social_share.api -import cc.sukazyo.cono.morny.data.social.SocialContent.{SocialMedia, SocialMediaType, SocialMediaWithUrl} -import cc.sukazyo.cono.morny.data.social.SocialContent.SocialMediaType.{Photo, Video} +import cc.sukazyo.cono.morny.social_share.api.SocialContent.{SocialMedia, SocialMediaType, SocialMediaWithUrl} +import cc.sukazyo.cono.morny.social_share.api.SocialContent.SocialMediaType.{Photo, Video} import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.query.InlineQueryUnit import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec diff --git a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialTwitterParser.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialTwitterParser.scala similarity index 88% rename from src/main/scala/cc/sukazyo/cono/morny/data/social/SocialTwitterParser.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialTwitterParser.scala index b8cef11..8c0e3f7 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialTwitterParser.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialTwitterParser.scala @@ -1,8 +1,8 @@ -package cc.sukazyo.cono.morny.data.social +package cc.sukazyo.cono.morny.social_share.api -import cc.sukazyo.cono.morny.data.social.SocialContent.{SocialMedia, SocialMediaWithUrl} -import cc.sukazyo.cono.morny.data.social.SocialContent.SocialMediaType.{Photo, Video} -import cc.sukazyo.cono.morny.extra.twitter.{FXApi, FXTweet} +import cc.sukazyo.cono.morny.social_share.api.SocialContent.{SocialMedia, SocialMediaWithUrl} +import cc.sukazyo.cono.morny.social_share.api.SocialContent.SocialMediaType.{Photo, Video} +import cc.sukazyo.cono.morny.social_share.external.twitter.{FXApi, FXTweet} import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.escapeHtml as h object SocialTwitterParser { diff --git a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialWeiboParser.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialWeiboParser.scala similarity index 86% rename from src/main/scala/cc/sukazyo/cono/morny/data/social/SocialWeiboParser.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialWeiboParser.scala index 7acaa08..43139e0 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/data/social/SocialWeiboParser.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/api/SocialWeiboParser.scala @@ -1,8 +1,8 @@ -package cc.sukazyo.cono.morny.data.social +package cc.sukazyo.cono.morny.social_share.api -import cc.sukazyo.cono.morny.data.social.SocialContent.SocialMediaType.Photo -import cc.sukazyo.cono.morny.data.social.SocialContent.SocialMediaWithBytesData -import cc.sukazyo.cono.morny.extra.weibo.{genWeiboStatusUrl, MApi, MStatus, StatusUrlInfo} +import cc.sukazyo.cono.morny.social_share.api.SocialContent.SocialMediaType.Photo +import cc.sukazyo.cono.morny.social_share.api.SocialContent.SocialMediaWithBytesData +import cc.sukazyo.cono.morny.social_share.external.weibo.{genWeiboStatusUrl, MApi, MStatus, StatusUrlInfo} import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramParseEscape.{cleanupHtml as ch, escapeHtml as h} import io.circe.{DecodingFailure, ParsingFailure} import sttp.client3.{HttpError, SttpClientException} diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/GetSocial.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/command/GetSocial.scala similarity index 84% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/GetSocial.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/command/GetSocial.scala index b69c49d..66147eb 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/GetSocial.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/command/GetSocial.scala @@ -1,8 +1,10 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.social_share.command + import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.util.tgapi.InputCommand import cc.sukazyo.cono.morny.MornyCoeur -import cc.sukazyo.cono.morny.bot.event.OnGetSocial +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} +import cc.sukazyo.cono.morny.social_share.event.OnGetSocial import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec import com.pengrad.telegrambot.model.Update import com.pengrad.telegrambot.request.SendSticker diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnGetSocial.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/event/OnGetSocial.scala similarity index 90% rename from src/main/scala/cc/sukazyo/cono/morny/bot/event/OnGetSocial.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/event/OnGetSocial.scala index 5732d58..b0775ad 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/event/OnGetSocial.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/event/OnGetSocial.scala @@ -1,13 +1,13 @@ -package cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.social_share.event import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} -import cc.sukazyo.cono.morny.bot.event.OnGetSocial.tryFetchSocial import cc.sukazyo.cono.morny.data.TelegramStickers -import cc.sukazyo.cono.morny.extra.{twitter, weibo} +import cc.sukazyo.cono.morny.social_share.event.OnGetSocial.tryFetchSocial import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec import cc.sukazyo.cono.morny.Log.{exceptionLog, logger} -import cc.sukazyo.cono.morny.data.social.{SocialTwitterParser, SocialWeiboParser} +import cc.sukazyo.cono.morny.social_share.api.{SocialTwitterParser, SocialWeiboParser} +import cc.sukazyo.cono.morny.social_share.external.{twitter, weibo} import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Message.entitiesSafe import com.pengrad.telegrambot.model.Chat import com.pengrad.telegrambot.model.request.ParseMode @@ -74,9 +74,9 @@ object OnGetSocial { } def tryFetchSocialOfTweet (url: twitter.TweetUrlInformation)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) = + import cc.sukazyo.cono.morny.social_share.external.twitter.FXApi import io.circe.{DecodingFailure, ParsingFailure} import sttp.client3.SttpClientException - import twitter.FXApi try { val api = FXApi.Fetch.status(Some(url.screenName), url.statusId) SocialTwitterParser.parseFXTweet(api).outputToTelegram @@ -90,9 +90,9 @@ object OnGetSocial { coeur.daemons.reporter.exception(e, "Error on requesting FixTweet API") def tryFetchSocialOfWeibo (url: weibo.StatusUrlInfo)(using replyChat: Long, replyToMessage: Int)(using coeur: MornyCoeur) = + import cc.sukazyo.cono.morny.social_share.external.weibo.MApi import io.circe.{DecodingFailure, ParsingFailure} import sttp.client3.{HttpError, SttpClientException} - import weibo.MApi try { val api = MApi.Fetch.statuses_show(url.id) SocialWeiboParser.parseMStatus(api).outputToTelegram diff --git a/src/main/scala/cc/sukazyo/cono/morny/util/BiliTool.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BiliTool.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/util/BiliTool.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BiliTool.scala index 37a2473..1fd831f 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/util/BiliTool.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BiliTool.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.util +package cc.sukazyo.cono.morny.social_share.external.bilibili import cc.sukazyo.cono.morny.util.UseMath.** diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/BilibiliForms.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BilibiliForms.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/extra/BilibiliForms.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BilibiliForms.scala index 3dc55f3..d6387bb 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/BilibiliForms.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/bilibili/BilibiliForms.scala @@ -1,6 +1,5 @@ -package cc.sukazyo.cono.morny.extra +package cc.sukazyo.cono.morny.social_share.external.bilibili -import cc.sukazyo.cono.morny.util.BiliTool import cc.sukazyo.cono.morny.util.SttpPublic.{mornyBasicRequest, Schemes} import cc.sukazyo.cono.morny.util.UseSelect.select import sttp.client3.{HttpError, SttpClientException} diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXApi.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXApi.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala index 11a4af8..1b73a8e 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXApi.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXApi.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter import cc.sukazyo.cono.morny.util.SttpPublic import cc.sukazyo.cono.morny.util.SttpPublic.mornyBasicRequest diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXAuthor.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXAuthor.scala similarity index 93% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXAuthor.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXAuthor.scala index 1aacb81..9afadb0 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXAuthor.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXAuthor.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Information about the author of a tweet. * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXExternalMedia.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXExternalMedia.scala similarity index 86% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXExternalMedia.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXExternalMedia.scala index 202c55e..36c8c6b 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXExternalMedia.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXExternalMedia.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Data for external media, currently only video. * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXMosaicPhoto.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXMosaicPhoto.scala similarity index 78% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXMosaicPhoto.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXMosaicPhoto.scala index 4fd6453..4b28407 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXMosaicPhoto.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXMosaicPhoto.scala @@ -1,6 +1,6 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter -import cc.sukazyo.cono.morny.extra.twitter.FXMosaicPhoto.formatsType +import cc.sukazyo.cono.morny.social_share.external.twitter.FXMosaicPhoto.formatsType /** Data for the mosaic service, which stitches photos together * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPhoto.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala similarity index 85% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPhoto.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala index d759110..78c690d 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPhoto.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPhoto.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** This can help compare items in a pool of media * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPool.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPool.scala similarity index 86% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPool.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPool.scala index bfc7f80..e944839 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPool.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPool.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Data for a poll on a given Tweet. * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPoolChoice.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPoolChoice.scala similarity index 85% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPoolChoice.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPoolChoice.scala index 1dfe0bd..f684830 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXPoolChoice.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXPoolChoice.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Data for a single choice in a poll * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTranslate.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTranslate.scala similarity index 85% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTranslate.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTranslate.scala index 0f6a08b..1f4613b 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTranslate.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTranslate.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Information about a requested translation for a Tweet, when asked. * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTweet.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala similarity index 95% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTweet.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala index b4b2b57..68483d8 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXTweet.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXTweet.scala @@ -1,6 +1,6 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter -import cc.sukazyo.cono.morny.extra.twitter.FXTweet.mediaType +import cc.sukazyo.cono.morny.social_share.external.twitter.FXTweet.mediaType import cc.sukazyo.cono.morny.util.EpochDateTime.EpochSeconds /** The container of all the information for a Tweet. diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXVideo.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXVideo.scala similarity index 90% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXVideo.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXVideo.scala index b58f133..24852ed 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/FXVideo.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/FXVideo.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.twitter +package cc.sukazyo.cono.morny.social_share.external.twitter /** Data for a Tweet's video * diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/package.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/package.scala similarity index 98% rename from src/main/scala/cc/sukazyo/cono/morny/extra/twitter/package.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/package.scala index ee07551..bfe5892 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/twitter/package.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/twitter/package.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra +package cc.sukazyo.cono.morny.social_share.external import scala.util.matching.Regex diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MApi.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MApi.scala similarity index 97% rename from src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MApi.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MApi.scala index c87236f..bc0e373 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MApi.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MApi.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.weibo +package cc.sukazyo.cono.morny.social_share.external.weibo case class MApi [D] ( ok: Int, diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MPic.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MPic.scala similarity index 87% rename from src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MPic.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MPic.scala index d9d2167..0d1fb09 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MPic.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MPic.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.weibo +package cc.sukazyo.cono.morny.social_share.external.weibo case class MPic ( pid: String, diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MStatus.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MStatus.scala similarity index 97% rename from src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MStatus.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MStatus.scala index 8d52be6..2669d3b 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MStatus.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MStatus.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.weibo +package cc.sukazyo.cono.morny.social_share.external.weibo case class MStatus ( diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MUser.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MUser.scala similarity index 78% rename from src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MUser.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MUser.scala index f01fff5..c2faa53 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/MUser.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/MUser.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra.weibo +package cc.sukazyo.cono.morny.social_share.external.weibo case class MUser ( diff --git a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/package.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/package.scala similarity index 95% rename from src/main/scala/cc/sukazyo/cono/morny/extra/weibo/package.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/package.scala index c57e5dc..3a36419 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/extra/weibo/package.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/external/weibo/package.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.extra +package cc.sukazyo.cono.morny.social_share.external package object weibo { diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolBilibili.scala similarity index 92% rename from src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolBilibili.scala index f7b6872..6ba9ba2 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolBilibili.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolBilibili.scala @@ -1,8 +1,9 @@ -package cc.sukazyo.cono.morny.bot.query +package cc.sukazyo.cono.morny.social_share.query import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils.inlineQueryId import cc.sukazyo.cono.morny.Log.{exceptionLog, logger} +import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, ITelegramQuery} import com.pengrad.telegrambot.model.Update import com.pengrad.telegrambot.model.request.{InlineQueryResultArticle, InputTextMessageContent, ParseMode} @@ -24,7 +25,7 @@ class ShareToolBilibili (using coeur: MornyCoeur) extends ITelegramQuery { if (event.inlineQuery.query == null) return null if (event.inlineQuery.query isBlank) return null - import cc.sukazyo.cono.morny.extra.BilibiliForms.* + import cc.sukazyo.cono.morny.social_share.external.bilibili.BilibiliForms.* val result: BiliVideoId = try parse_videoUrl(event.inlineQuery.query) diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolSocialContent.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolSocialContent.scala similarity index 71% rename from src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolSocialContent.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolSocialContent.scala index 60912e7..12442d0 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolSocialContent.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolSocialContent.scala @@ -1,8 +1,10 @@ -package cc.sukazyo.cono.morny.bot.query -import cc.sukazyo.cono.morny.data.social.{SocialTwitterParser, SocialWeiboParser} -import cc.sukazyo.cono.morny.extra.{twitter, weibo} -import cc.sukazyo.cono.morny.extra.twitter.{FXApi, TweetUrlInformation} -import cc.sukazyo.cono.morny.extra.weibo.{MApi, StatusUrlInfo} +package cc.sukazyo.cono.morny.social_share.query + +import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, ITelegramQuery} +import cc.sukazyo.cono.morny.social_share.api.{SocialTwitterParser, SocialWeiboParser} +import cc.sukazyo.cono.morny.social_share.external.{twitter, weibo} +import cc.sukazyo.cono.morny.social_share.external.twitter.{FXApi, TweetUrlInformation} +import cc.sukazyo.cono.morny.social_share.external.weibo.{MApi, StatusUrlInfo} import com.pengrad.telegrambot.model.Update class ShareToolSocialContent extends ITelegramQuery { diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.scala b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolTwitter.scala similarity index 81% rename from src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.scala rename to src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolTwitter.scala index 3105b05..187e2c5 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/query/ShareToolTwitter.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/social_share/query/ShareToolTwitter.scala @@ -1,7 +1,8 @@ -package cc.sukazyo.cono.morny.bot.query +package cc.sukazyo.cono.morny.social_share.query -import cc.sukazyo.cono.morny.extra.twitter -import cc.sukazyo.cono.morny.extra.twitter.TweetUrlInformation +import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, ITelegramQuery} +import cc.sukazyo.cono.morny.social_share.external.twitter +import cc.sukazyo.cono.morny.social_share.external.twitter.TweetUrlInformation import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils.inlineQueryId import com.pengrad.telegrambot.model.Update import com.pengrad.telegrambot.model.request.InlineQueryResultArticle diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/query/RawText.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/InlineRawText.scala similarity index 81% rename from src/main/scala/cc/sukazyo/cono/morny/bot/query/RawText.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/InlineRawText.scala index 036fb1d..fa19780 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/query/RawText.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/InlineRawText.scala @@ -1,11 +1,13 @@ -package cc.sukazyo.cono.morny.bot.query +package cc.sukazyo.cono.morny.tele_utils + +import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, ITelegramQuery} import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils.inlineQueryId import com.pengrad.telegrambot.model.Update import com.pengrad.telegrambot.model.request.{InlineQueryResultArticle, InputTextMessageContent} import scala.language.postfixOps -class RawText extends ITelegramQuery { +class InlineRawText extends ITelegramQuery { private val ID_PREFIX = "[morny/r/text]" private val TITLE = "Raw Text" diff --git a/src/main/scala/cc/sukazyo/cono/morny/tele_utils/ModuleTeleUtils.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/ModuleTeleUtils.scala new file mode 100644 index 0000000..bae6288 --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/ModuleTeleUtils.scala @@ -0,0 +1,45 @@ +package cc.sukazyo.cono.morny.tele_utils + +import cc.sukazyo.cono.morny.internal.MornyInternalModule +import cc.sukazyo.cono.morny.MornyCoeur +import cc.sukazyo.cono.morny.tele_utils.event_hack.{CommandEventHack, EventHacker, HackerEventHandler} +import cc.sukazyo.cono.morny.tele_utils.user_info.{CommandGetUser, InlineMyInformation} + +class ModuleTeleUtils extends MornyInternalModule { + + override val id: String = "morny.tele_utils" + override val name: String = "Morny Tele Utils : EventHack, User data, and more" + override val description: String | Null = + // language=markdown + """Added a serial tools for developing easier on Telegram. + | + |- `/event_hack`: Get the next event's raw serial data of you. + |- `/user`: Get user metadata for you or your roommate or by id. + | Also supported to get user's DC. + |""".stripMargin + + override def onInitializingPre (using MornyCoeur)(cxt: MornyCoeur.OnInitializingPreContext): Unit = { + import cxt.* + + given hacker: EventHacker = EventHacker() + + externalContext << hacker + givenCxt << hacker + + } + + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { + import cxt.* + given EventHacker = externalContext >!> classOf[EventHacker] + + eventManager register HackerEventHandler() + commandManager register CommandEventHack() + + commandManager register CommandGetUser() + queryManager register InlineMyInformation() + + queryManager register InlineRawText() + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/event_hack/BotCmdEventHack.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/CommandEventHack.scala similarity index 91% rename from src/main/scala/cc/sukazyo/cono/morny/event_hack/BotCmdEventHack.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/CommandEventHack.scala index 009da4e..8f2d7fc 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/event_hack/BotCmdEventHack.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/CommandEventHack.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.event_hack +package cc.sukazyo.cono.morny.tele_utils.event_hack import cc.sukazyo.cono.morny.MornyCoeur import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} @@ -10,7 +10,7 @@ import com.pengrad.telegrambot.request.SendSticker import scala.language.postfixOps -class BotCmdEventHack (using hacker: EventHacker)(using coeur: MornyCoeur) extends ITelegramCommand { +class CommandEventHack (using hacker: EventHacker)(using coeur: MornyCoeur) extends ITelegramCommand { override val name: String = "event_hack" override val aliases: List[ICommandAlias] = Nil diff --git a/src/main/scala/cc/sukazyo/cono/morny/event_hack/EventHacker.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/EventHacker.scala similarity index 97% rename from src/main/scala/cc/sukazyo/cono/morny/event_hack/EventHacker.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/EventHacker.scala index b3afff9..5ff34ee 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/event_hack/EventHacker.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/EventHacker.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.event_hack +package cc.sukazyo.cono.morny.tele_utils.event_hack import cc.sukazyo.cono.morny.Log.logger import cc.sukazyo.cono.morny.MornyCoeur diff --git a/src/main/scala/cc/sukazyo/cono/morny/event_hack/BotEventEventHackHandle.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/HackerEventHandler.scala similarity index 93% rename from src/main/scala/cc/sukazyo/cono/morny/event_hack/BotEventEventHackHandle.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/HackerEventHandler.scala index ac6f245..3059f0f 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/event_hack/BotEventEventHackHandle.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/event_hack/HackerEventHandler.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.event_hack +package cc.sukazyo.cono.morny.tele_utils.event_hack import cc.sukazyo.cono.morny.bot.api.{EventEnv, EventListener} import cc.sukazyo.cono.morny.Log.logger @@ -11,7 +11,7 @@ import com.pengrad.telegrambot.request.SendMessage import scala.collection.mutable import scala.language.postfixOps -class BotEventEventHackHandle (using hacker: EventHacker)(using coeur: MornyCoeur) extends EventListener { +class HackerEventHandler (using hacker: EventHacker)(using coeur: MornyCoeur) extends EventListener { private def trigger (chat_id: Long, from_id: Long)(using event: EventEnv): Unit = given Update = event.update diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/CommandGetUser.scala similarity index 91% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/CommandGetUser.scala index 4e2c435..341fd43 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/CommandGetUser.scala @@ -1,6 +1,7 @@ -package cc.sukazyo.cono.morny.bot.command +package cc.sukazyo.cono.morny.tele_utils.user_info import cc.sukazyo.cono.morny.MornyCoeur +import cc.sukazyo.cono.morny.bot.command.{ICommandAlias, ITelegramCommand} import cc.sukazyo.cono.morny.util.tgapi.{InputCommand, Standardize} import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramUserInformation import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.exec @@ -10,7 +11,7 @@ import com.pengrad.telegrambot.request.{GetChatMember, SendMessage} import scala.language.postfixOps -class GetUsernameAndId (using coeur: MornyCoeur) extends ITelegramCommand { +class CommandGetUser (using coeur: MornyCoeur) extends ITelegramCommand { override val name: String = "user" override val aliases: List[ICommandAlias] = Nil diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/query/MyInformation.scala b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/InlineMyInformation.scala similarity index 83% rename from src/main/scala/cc/sukazyo/cono/morny/bot/query/MyInformation.scala rename to src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/InlineMyInformation.scala index 1b27068..ccb3328 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/query/MyInformation.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/tele_utils/user_info/InlineMyInformation.scala @@ -1,5 +1,6 @@ -package cc.sukazyo.cono.morny.bot.query +package cc.sukazyo.cono.morny.tele_utils.user_info +import cc.sukazyo.cono.morny.bot.query.{InlineQueryUnit, ITelegramQuery} import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils.inlineQueryId import cc.sukazyo.cono.morny.util.tgapi.formatting.TelegramUserInformation import com.pengrad.telegrambot.model.Update @@ -7,7 +8,7 @@ import com.pengrad.telegrambot.model.request.{InlineQueryResultArticle, InputTex import scala.language.postfixOps -class MyInformation extends ITelegramQuery { +class InlineMyInformation extends ITelegramQuery { private val ID_PREFIX = "[morny/info/me]" private val TITLE = "My Account Information" diff --git a/src/main/scala/cc/sukazyo/cono/morny/uni_meow/ModuleUniMeow.scala b/src/main/scala/cc/sukazyo/cono/morny/uni_meow/ModuleUniMeow.scala index e673691..091e3fc 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/uni_meow/ModuleUniMeow.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/uni_meow/ModuleUniMeow.scala @@ -16,11 +16,15 @@ class ModuleUniMeow extends MornyInternalModule { val uni_commands: UniMeowCommandManager = UniMeowCommandManager() + override def onInitializingPre (using MornyCoeur)(cxt: MornyCoeur.OnInitializingPreContext): Unit = { + import cxt.* + externalContext << uni_commands + givenCxt << uni_commands + } + override def onInitializing (using MornyCoeur)(cxt: MornyCoeur.OnInitializingContext): Unit = { import cxt.* - externalContext << uni_commands - givenCxt << uni_commands eventManager.register( BotEventUniMeowTrigger(using uni_commands) ) @@ -37,7 +41,8 @@ class ModuleUniMeow extends MornyInternalModule { //noinspection NonAsciiCharacters commandManager.register( $喵呜.Progynova, - 私わね() + 私わね(), + 创().Chuang ) } diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala b/src/main/scala/cc/sukazyo/cono/morny/uni_meow/创.scala similarity index 95% rename from src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala rename to src/main/scala/cc/sukazyo/cono/morny/uni_meow/创.scala index d32c87a..7f025ca 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/uni_meow/创.scala @@ -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.tgapi.TelegramExtensions.Bot.* import com.pengrad.telegrambot.model.{MessageEntity, Update} diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala index 38ee81d..60cd01f 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.test.bot.event -import cc.sukazyo.cono.morny.bot.event.OnQuestionMarkReply +import cc.sukazyo.cono.morny.randomize_somthing.OnQuestionMarkReply import cc.sukazyo.cono.morny.test.MornyTests import org.scalatest.prop.TableDrivenPropertyChecks diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala index 9ac6686..5dfcae7 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.test.daemon -import cc.sukazyo.cono.morny.daemon.MedicationTimer +import cc.sukazyo.cono.morny.medication_timer.MedicationTimer import cc.sukazyo.cono.morny.test.MornyTests import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis import org.scalatest.prop.TableDrivenPropertyChecks diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/extra/BilibiliFormsTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/extra/BilibiliFormsTest.scala index fd2d1fd..1245846 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/extra/BilibiliFormsTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/extra/BilibiliFormsTest.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.test.extra -import cc.sukazyo.cono.morny.extra.BilibiliForms.* +import cc.sukazyo.cono.morny.social_share.external.bilibili.BilibiliForms.* import cc.sukazyo.cono.morny.test.MornyTests import org.scalatest.prop.TableDrivenPropertyChecks diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/FXApiTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/FXApiTest.scala index 7a84054..0a5db9c 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/FXApiTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/FXApiTest.scala @@ -1,7 +1,7 @@ package cc.sukazyo.cono.morny.test.extra.twitter -import cc.sukazyo.cono.morny.extra.twitter.FXApi -import cc.sukazyo.cono.morny.extra.twitter.FXApi.Fetch +import cc.sukazyo.cono.morny.social_share.external.twitter.FXApi +import cc.sukazyo.cono.morny.social_share.external.twitter.FXApi.Fetch import cc.sukazyo.cono.morny.test.MornyTests import org.scalatest.prop.TableDrivenPropertyChecks import org.scalatest.tagobjects.{Network, Slow} diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/PackageTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/PackageTest.scala index e65189e..ac69623 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/PackageTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/extra/twitter/PackageTest.scala @@ -1,6 +1,6 @@ package cc.sukazyo.cono.morny.test.extra.twitter -import cc.sukazyo.cono.morny.extra.twitter.{parseTweetUrl, TweetUrlInformation} +import cc.sukazyo.cono.morny.social_share.external.twitter.{parseTweetUrl, TweetUrlInformation} import cc.sukazyo.cono.morny.test.MornyTests class PackageTest extends MornyTests { diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/BiliToolTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/BiliToolTest.scala index 1ae8264..99f44d8 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/BiliToolTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/BiliToolTest.scala @@ -16,13 +16,13 @@ class BiliToolTest extends MornyTests with TableDrivenPropertyChecks { ) forAll (examples) { (bv, av) => s"while using av$av/BV$bv :" - { - import cc.sukazyo.cono.morny.util.BiliTool.{toAv, toBv} + import cc.sukazyo.cono.morny.social_share.external.bilibili.BiliTool.{toAv, toBv} "av to bv works" in { toBv(av) shouldEqual bv } "bv to av works" in { toAv(bv) shouldEqual av } }} "BV with unsupported length :" - { - import cc.sukazyo.cono.morny.util.BiliTool.{toAv, IllegalFormatException} + import cc.sukazyo.cono.morny.social_share.external.bilibili.BiliTool.{toAv, IllegalFormatException} val examples = Table( "bv", "12345", @@ -48,7 +48,7 @@ class BiliToolTest extends MornyTests with TableDrivenPropertyChecks { ("1mK4O1C7Bl", "l"), ("1--4O1C7Bl", "[symbols]") ) - import cc.sukazyo.cono.morny.util.BiliTool.{toAv, IllegalFormatException} + import cc.sukazyo.cono.morny.social_share.external.bilibili.BiliTool.{toAv, IllegalFormatException} forAll(examples) { (bv, with_sp) => s"'$with_sp' should throws IllegalFormatException" in: an [IllegalFormatException] should be thrownBy toAv(bv) @@ -58,7 +58,7 @@ class BiliToolTest extends MornyTests with TableDrivenPropertyChecks { "av/bv converting should be reversible" in { for (_ <- 1 to 20) { val rand_av = Random.between(0, 999999999L) - import cc.sukazyo.cono.morny.util.BiliTool.{toAv, toBv} + import cc.sukazyo.cono.morny.social_share.external.bilibili.BiliTool.{toAv, toBv} val my_bv = toBv(rand_av) toAv(my_bv) shouldEqual rand_av toBv(toAv(my_bv)) shouldEqual my_bv