move morny.core morny.data to morny-core subproject.
Some checks are pending
Tests / check-build (push) Waiting to run
Tests / check-unit-tests (push) Blocked by required conditions
Tests / check-assembly-run (push) Blocked by required conditions

- add fake BuildConfig to pass type check
- add CoreCommandsReports.onUnauthorizedManageCommandCall for a report.
This commit is contained in:
A.C.Sukazyo Eyre 2025-02-21 19:39:22 +08:00
parent 96101ec434
commit 9d43345659
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
81 changed files with 146 additions and 30 deletions

View File

@ -3,7 +3,7 @@ package cc.sukazyo.cono.morny.reporter
import cc.sukazyo.cono.morny.core.internal.MornyInternalModule import cc.sukazyo.cono.morny.core.internal.MornyInternalModule
import cc.sukazyo.cono.morny.core.Log.logger import cc.sukazyo.cono.morny.core.Log.logger
import cc.sukazyo.cono.morny.core.MornyCoeur import cc.sukazyo.cono.morny.core.MornyCoeur
import cc.sukazyo.cono.morny.core.event.TelegramBotEvents import cc.sukazyo.cono.morny.core.event.{TelegramBotEvents, TelegramCoreCommandEvents}
class Module extends MornyInternalModule { class Module extends MornyInternalModule {
@ -46,6 +46,8 @@ class Module extends MornyInternalModule {
.registerListener(instance.botErrorsReport.onGetUpdateFailed) .registerListener(instance.botErrorsReport.onGetUpdateFailed)
TelegramBotEvents.inCoeur.OnListenerOccursException TelegramBotEvents.inCoeur.OnListenerOccursException
.registerListener(instance.botErrorsReport.onEventListenersThrowException) .registerListener(instance.botErrorsReport.onEventListenersThrowException)
TelegramCoreCommandEvents.inCoeur.OnUnauthorizedManageCommandCall
.registerListener(instance.coreCommandsReports.onUnauthorizedManageCommandCall)
} || { } || {
logger `warn` "There seems no reporter instance is provided; skipped start it." logger `warn` "There seems no reporter instance is provided; skipped start it."

View File

@ -3,7 +3,7 @@ package cc.sukazyo.cono.morny.reporter
import cc.sukazyo.cono.morny.core.{MornyCoeur, MornyConfig} import cc.sukazyo.cono.morny.core.{MornyCoeur, MornyConfig}
import cc.sukazyo.cono.morny.core.Log.logger import cc.sukazyo.cono.morny.core.Log.logger
import cc.sukazyo.cono.morny.data.MornyInformation.getVersionAllFullTagHTML import cc.sukazyo.cono.morny.data.MornyInformation.getVersionAllFullTagHTML
import cc.sukazyo.cono.morny.reporter.telegram_bot.BotErrorsReport import cc.sukazyo.cono.morny.reporter.telegram_bot.{BotErrorsReport, CoreCommandsReports}
import cc.sukazyo.cono.morny.system.telegram_api.event.{EventEnv, EventListener, EventRuntimeException} import cc.sukazyo.cono.morny.system.telegram_api.event.{EventEnv, EventListener, EventRuntimeException}
import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramFormatter.* import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramFormatter.*
import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramParseEscape.escapeHtml as h import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramParseEscape.escapeHtml as h
@ -150,6 +150,7 @@ class MornyReport (using val coeur: MornyCoeur) {
} }
object botErrorsReport extends BotErrorsReport() object botErrorsReport extends BotErrorsReport()
object coreCommandsReports extends CoreCommandsReports()
object EventStatistics { object EventStatistics {

View File

@ -0,0 +1,18 @@
package cc.sukazyo.cono.morny.reporter.telegram_bot
import cc.sukazyo.cono.morny.core.event.TelegramCoreCommandEvents
import cc.sukazyo.cono.morny.reporter.MornyReport
class CoreCommandsReports (using reporter: MornyReport) {
private val _Event = TelegramCoreCommandEvents.inCoeur(using reporter.coeur)
val onUnauthorizedManageCommandCall: _Event.OnUnauthorizedManageCommandCall.MyCallback
= (context, command) => {
reporter.unauthenticatedAction(
s"/${command.name}",
context.bind_user
)
}
}

View File

@ -0,0 +1,40 @@
// $COVERAGE-OFF$
package cc.sukazyo.cono.morny
/** This object was generated by sbt-buildinfo. */
case object BuildConfig {
/** The value is "Morny Coeur". */
val name: String = "Morny Coeur"
/** The value is "2.0.0-alpha21-SNAPSHOT". */
val version: String = "2.0.0-alpha21-SNAPSHOT"
/** The value is "3.4.1". */
val scalaVersion: String = "3.4.1"
/** The value is "1.10.0". */
val sbtVersion: String = "1.10.0"
/** The value is "2.0.0-alpha21-SNAPSHOT". */
val VERSION: String = "2.0.0-alpha21-SNAPSHOT"
/** The value is "2.0.0-alpha21-SNAPSHOT+gitbd958708.δ". */
val VERSION_FULL: String = "2.0.0-alpha21-SNAPSHOT+gitbd958708.δ"
/** The value is "2.0.0-alpha21". */
val VERSION_BASE: String = "2.0.0-alpha21"
/** The value is scala.None. */
val VERSION_DELTA: scala.Option[String] = scala.None
/** The value is "xinzheng". */
val CODENAME: String = "xinzheng"
/** The value is 1739975193572L. */
val CODE_TIMESTAMP: scala.Long = 1739975193572L
/** The value is "bd95870864075e9921257e14bf446f53d4bc5e02". */
val COMMIT: String = "bd95870864075e9921257e14bf446f53d4bc5e02"
/** The value is false. */
val CLEAN_BUILD: scala.Boolean = false
/** The value is "https://github.com/Eyre-S/Coeur-Morny-Cono". */
val CODE_STORE: String = "https://github.com/Eyre-S/Coeur-Morny-Cono"
/** The value is "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s". */
val COMMIT_PATH: String = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s"
override val toString: String = {
"name: %s, version: %s, scalaVersion: %s, sbtVersion: %s, VERSION: %s, VERSION_FULL: %s, VERSION_BASE: %s, VERSION_DELTA: %s, CODENAME: %s, CODE_TIMESTAMP: %s, COMMIT: %s, CLEAN_BUILD: %s, CODE_STORE: %s, COMMIT_PATH: %s".format(
name, version, scalaVersion, sbtVersion, VERSION, VERSION_FULL, VERSION_BASE, VERSION_DELTA, CODENAME, CODE_TIMESTAMP, COMMIT, CLEAN_BUILD, CODE_STORE, COMMIT_PATH
)
}
}
// $COVERAGE-ON$

View File

@ -6,7 +6,7 @@ import cc.sukazyo.cono.morny.core.bot.api.{BotExtension, EventListenerManager, M
import cc.sukazyo.cono.morny.core.bot.api.messages.ThreadingManager import cc.sukazyo.cono.morny.core.bot.api.messages.ThreadingManager
import cc.sukazyo.cono.morny.core.bot.event.{MornyOnInlineQuery, MornyOnTelegramCommand, MornyOnUpdateTimestampOffsetLock} import cc.sukazyo.cono.morny.core.bot.event.{MornyOnInlineQuery, MornyOnTelegramCommand, MornyOnUpdateTimestampOffsetLock}
import cc.sukazyo.cono.morny.core.bot.internal.{ErrorMessageManager, ThreadingManagerImpl} import cc.sukazyo.cono.morny.core.bot.internal.{ErrorMessageManager, ThreadingManagerImpl}
import cc.sukazyo.cono.morny.core.event.TelegramBotEvents import cc.sukazyo.cono.morny.core.event.{TelegramBotEvents, TelegramCoreCommandEvents}
import cc.sukazyo.cono.morny.core.http.api.{HttpServer, MornyHttpServerContext} import cc.sukazyo.cono.morny.core.http.api.{HttpServer, MornyHttpServerContext}
import cc.sukazyo.cono.morny.core.http.internal.MornyHttpServerContextImpl import cc.sukazyo.cono.morny.core.http.internal.MornyHttpServerContextImpl
import cc.sukazyo.cono.morny.core.module.ModuleHelper import cc.sukazyo.cono.morny.core.module.ModuleHelper
@ -119,6 +119,7 @@ class MornyCoeur (modules: List[MornyModule])(using val config: MornyConfig)(tes
given MornyCoeur = this given MornyCoeur = this
val telegramBotEvents = new TelegramBotEvents() val telegramBotEvents = new TelegramBotEvents()
val telegramCoreCommandEvents = new TelegramCoreCommandEvents()
val externalContext: GivenContext = GivenContext() val externalContext: GivenContext = GivenContext()
logger `info` logger `info`

View File

@ -4,7 +4,6 @@ import cc.sukazyo.cono.morny.core.{MornyCoeur, MornySystem}
import cc.sukazyo.cono.morny.core.bot.api.messages.{ErrorMessage, MessagingContext} import cc.sukazyo.cono.morny.core.bot.api.messages.{ErrorMessage, MessagingContext}
import cc.sukazyo.cono.morny.data.MornyInformation.* import cc.sukazyo.cono.morny.data.MornyInformation.*
import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.data.TelegramStickers
import cc.sukazyo.cono.morny.reporter.MornyReport
import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramParseEscape.escapeHtml as h import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramParseEscape.escapeHtml as h
import cc.sukazyo.cono.morny.system.telegram_api.TelegramExtensions.Requests.unsafeExecute import cc.sukazyo.cono.morny.system.telegram_api.TelegramExtensions.Requests.unsafeExecute
import cc.sukazyo.cono.morny.system.telegram_api.command.{ICommandAlias, InputCommand, ITelegramCommand} import cc.sukazyo.cono.morny.system.telegram_api.command.{ICommandAlias, InputCommand, ITelegramCommand}
@ -220,23 +219,24 @@ class MornyInformation (using coeur: MornyCoeur) extends ITelegramCommand {
.unsafeExecute .unsafeExecute
} }
// todo: fix this
private def echoEventStatistics (using update: Update): Unit = { private def echoEventStatistics (using update: Update): Unit = {
coeur.externalContext >> { (reporter: MornyReport) => // coeur.externalContext >> { (reporter: MornyReport) =>
SendMessage( // SendMessage(
update.message.chat.id, // update.message.chat.id,
VarText( // VarText(
// language=html // // language=html
"""<b>Event Statistics :</b> // """<b>Event Statistics :</b>
|in today // |in today
|{event_statistics}""".stripMargin // |{event_statistics}""".stripMargin
).render( // ).render(
"event_statistics" -> reporter.EventStatistics.eventStatisticsHTML // "event_statistics" -> reporter.EventStatistics.eventStatisticsHTML
) // )
).parseMode(ParseMode.HTML).replyToMessageId(update.message.messageId) // ).parseMode(ParseMode.HTML).replyToMessageId(update.message.messageId)
.unsafeExecute // .unsafeExecute
} || { // } || {
echo404 // echo404
} // }
} }
private def echo404 (using event: Update): Unit = private def echo404 (using event: Update): Unit =

View File

@ -4,8 +4,8 @@ import cc.sukazyo.cono.morny.core.Log.logger
import cc.sukazyo.cono.morny.core.MornyCoeur import cc.sukazyo.cono.morny.core.MornyCoeur
import cc.sukazyo.cono.morny.core.bot.api.messages import cc.sukazyo.cono.morny.core.bot.api.messages
import cc.sukazyo.cono.morny.core.bot.api.messages.MessagingContext import cc.sukazyo.cono.morny.core.bot.api.messages.MessagingContext
import cc.sukazyo.cono.morny.core.event.TelegramCoreCommandEvents
import cc.sukazyo.cono.morny.data.TelegramStickers import cc.sukazyo.cono.morny.data.TelegramStickers
import cc.sukazyo.cono.morny.reporter.MornyReport
import cc.sukazyo.cono.morny.system.telegram_api.command.ICommandAlias.HiddenAlias import cc.sukazyo.cono.morny.system.telegram_api.command.ICommandAlias.HiddenAlias
import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramFormatter.* import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramFormatter.*
import cc.sukazyo.cono.morny.system.telegram_api.TelegramExtensions.Requests.unsafeExecute import cc.sukazyo.cono.morny.system.telegram_api.TelegramExtensions.Requests.unsafeExecute
@ -24,7 +24,7 @@ class MornyManagers (using coeur: MornyCoeur) {
).replyToMessageId(cxt.bind_message.messageId) ).replyToMessageId(cxt.bind_message.messageId)
.unsafeExecute .unsafeExecute
logger `attention` s"403 ${command.name} caught from user ${cxt.bind_user toLogTag}" logger `attention` s"403 ${command.name} caught from user ${cxt.bind_user toLogTag}"
coeur.externalContext.consume[MornyReport](_.unauthenticatedAction(s"/${command.name}", cxt.bind_user)) TelegramCoreCommandEvents.inCoeur.OnUnauthorizedManageCommandCall.emit((cxt, command))
false false
else true else true
} }

View File

@ -2,16 +2,12 @@ package cc.sukazyo.cono.morny.core.event
import cc.sukazyo.cono.morny.core.MornyCoeur import cc.sukazyo.cono.morny.core.MornyCoeur
import cc.sukazyo.cono.morny.system.telegram_api.event.{EventEnv, EventListener as TelegramEventListener} import cc.sukazyo.cono.morny.system.telegram_api.event.{EventEnv, EventListener as TelegramEventListener}
import cc.sukazyo.std.event.{EventContext, RichEvent} import cc.sukazyo.std.event.RichEvent
import cc.sukazyo.std.event.impl.NormalEventManager import cc.sukazyo.std.event.impl.NormalEventManager
import com.pengrad.telegrambot.TelegramException import com.pengrad.telegrambot.TelegramException
class TelegramBotEvents (using coeur: MornyCoeur) { class TelegramBotEvents (using coeur: MornyCoeur) {
private val contextInitializer: EventContext[?]=>Unit = context => {
context.givenCxt << coeur
}
/** /**
* Event: OnGetUpdateFailed in TelegramBotEvents * Event: OnGetUpdateFailed in TelegramBotEvents
* *
@ -25,10 +21,10 @@ class TelegramBotEvents (using coeur: MornyCoeur) {
* You should register your own listener at stage [[MornyModule.onStartingPost]]. * You should register your own listener at stage [[MornyModule.onStartingPost]].
*/ */
val OnGetUpdateFailed: NormalEventManager[TelegramException, Unit] = val OnGetUpdateFailed: NormalEventManager[TelegramException, Unit] =
NormalEventManager().initContextWith(contextInitializer) NormalEventManager().initContextWith(initWithCoeur)
val OnListenerOccursException: RichEvent[(Throwable, TelegramEventListener, EventEnv), Unit] = val OnListenerOccursException: RichEvent[(Throwable, TelegramEventListener, EventEnv), Unit] =
NormalEventManager().initContextWith(contextInitializer) NormalEventManager().initContextWith(initWithCoeur)
} }

View File

@ -0,0 +1,21 @@
package cc.sukazyo.cono.morny.core.event
import cc.sukazyo.cono.morny.core.MornyCoeur
import cc.sukazyo.cono.morny.core.bot.api.messages.MessagingContext
import cc.sukazyo.cono.morny.system.telegram_api.command.ISimpleCommand
import cc.sukazyo.std.event.RichEvent
import cc.sukazyo.std.event.impl.NormalEventManager
class TelegramCoreCommandEvents (using coeur: MornyCoeur) {
val OnUnauthorizedManageCommandCall: RichEvent[(MessagingContext.WithUserAndMessage, ISimpleCommand), Unit] =
NormalEventManager().initContextWith(initWithCoeur)
}
object TelegramCoreCommandEvents {
def inCoeur (using coeur: MornyCoeur): TelegramCoreCommandEvents =
coeur.telegramCoreCommandEvents
}

View File

@ -0,0 +1,12 @@
package cc.sukazyo.cono.morny.core
import cc.sukazyo.std.event.EventContext
package object event {
def initWithCoeur (using coeur: MornyCoeur): EventContext[?]=>Unit
= context => {
context.givenCxt << coeur
}
}

View File

@ -74,7 +74,32 @@ object MornyConfiguration {
override val group = GROUP override val group = GROUP
override val root_package = s"$GROUP.cono.morny.core" override val root_package = s"$GROUP.cono.morny.core"
override val dependencies = Seq() override val dependencies = Seq(
"com.github.spotbugs" % "spotbugs-annotations" % "4.9.1" % Compile,
"cc.sukazyo" % "messiva" % "0.2.0",
"cc.sukazyo" % "resource-tools" % "0.3.1",
"cc.sukazyo" % "da4a" % "0.2.0-SNAPSHOT" changing(),
"com.github.pengrad" % "java-telegram-bot-api" % "6.2.0",
"org.http4s" %% "http4s-dsl" % "0.23.30",
"org.http4s" %% "http4s-circe" % "0.23.30",
"org.http4s" %% "http4s-netty-server" % "0.5.22",
"io.circe" %% "circe-core" % "0.14.10",
"io.circe" %% "circe-generic" % "0.14.10",
"io.circe" %% "circe-parser" % "0.14.10",
"com.cronutils" % "cron-utils" % "9.2.1",
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.scalatest" %% "scalatest-freespec" % "3.2.19" % Test,
// for test report
"com.vladsch.flexmark" % "flexmark" % "0.64.8" % Test,
"com.vladsch.flexmark" % "flexmark-profile-pegdown" % "0.64.8" % Test
)
} }