Compare commits

...

2 Commits

Author SHA1 Message Date
341d4cd851
add -t argument for test run 2023-12-20 17:46:02 +08:00
58cf4cc74b
change ISimpleCommand.aliases type to List from Array 2023-12-20 17:28:17 +08:00
23 changed files with 52 additions and 37 deletions

View File

@ -55,6 +55,7 @@ lazy val root = (project in file("."))
"-source", "17",
"-target", "17"
),
autoAPIMappings := true,
assemblyMergeStrategy := {
case module if module endsWith "module-info.class" => MergeStrategy.concat

View File

@ -8,7 +8,7 @@ object MornyConfiguration {
val MORNY_CODE_STORE = "https://github.com/Eyre-S/Coeur-Morny-Cono"
val MORNY_COMMIT_PATH = "https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s"
val VERSION = "2.0.0-alpha1.1"
val VERSION = "2.0.0-alpha3"
val VERSION_DELTA: Option[String] = None
val CODENAME = "guanggu"
@ -42,6 +42,9 @@ object MornyConfiguration {
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.scalatest" %% "scalatest-freespec" % "3.2.17" % Test,
// for test report
"com.vladsch.flexmark" % "flexmark" % "0.64.0" % Test,
"com.vladsch.flexmark" % "flexmark-profile-pegdown" % "0.64.0" % Test
)

View File

@ -3,7 +3,7 @@ package cc.sukazyo.cono.morny
import cc.sukazyo.cono.morny.bot.command.MornyCommands
import cc.sukazyo.cono.morny.daemon.MornyDaemons
import cc.sukazyo.cono.morny.Log.{exceptionLog, logger}
import cc.sukazyo.cono.morny.MornyCoeur.THREAD_SERVER_EXIT
import cc.sukazyo.cono.morny.MornyCoeur.{TestRun, THREAD_SERVER_EXIT}
import cc.sukazyo.cono.morny.bot.api.EventListenerManager
import cc.sukazyo.cono.morny.bot.event.{MornyEventListeners, MornyOnInlineQuery, MornyOnTelegramCommand, MornyOnUpdateTimestampOffsetLock}
import cc.sukazyo.cono.morny.bot.query.MornyQueries
@ -21,9 +21,11 @@ object MornyCoeur {
val THREAD_SERVER_EXIT = "system-exit"
object TestRun
}
class MornyCoeur (using val config: MornyConfig) {
class MornyCoeur (using val config: MornyConfig)(testRun: Boolean = false) {
given MornyCoeur = this
@ -43,8 +45,6 @@ class MornyCoeur (using val config: MornyConfig) {
System exit -1
throw RuntimeException()
configure_exitCleanup()
///<<< BLOCK END instance configure & startup stage 1
/** inner value: about why morny exit, used in [[daemon.MornyReport]]. */
@ -94,6 +94,14 @@ class MornyCoeur (using val config: MornyConfig) {
///>>> BLOCK START instance configure & startup stage 2
logger info "done initialize."
if testRun then
logger info "done test run, exiting."
this.exit(0, TestRun)
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.
daemons.start()
logger info "start telegram event listening"
import com.pengrad.telegrambot.TelegramException

View File

@ -21,6 +21,7 @@ object ServerMain {
val config = new MornyConfig.Prototype()
var mode_echoVersion = false
var mode_echoHello = false
var mode_testRun = false
var showHello = true
val unknownArgs = ArrayBuffer[String]()
@ -31,6 +32,7 @@ object ServerMain {
args(i) match {
case "-d" | "--dbg" | "--debug" => Log.debug(true)
case "-t" | "--test" => mode_testRun = true
case "--no-hello" | "-hf" | "--quiet" | "-q" => showHello = false
case "--only-hello" | "-ho" | "-o" | "-hi" => mode_echoHello = true
@ -156,7 +158,9 @@ object ServerMain {
Thread.currentThread setName THREAD_MORNY_INIT
try
MornyCoeur(using config build)
MornyCoeur(using config build)(
testRun = mode_testRun
)
catch {
case _: CheckFailure.NullTelegramBotKey =>
logger.info("Parameter required has no value:\n --token.")

View File

@ -13,7 +13,7 @@ import scala.language.postfixOps
class DirectMsgClear (using coeur: MornyCoeur) extends ISimpleCommand {
override val name: String = "r"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = {

View File

@ -22,7 +22,7 @@ import scala.language.postfixOps
class Encryptor (using coeur: MornyCoeur) extends ITelegramCommand {
override val name: String = "encrypt"
override val aliases: Array[ICommandAlias] | Null = Array(ListedAlias("enc"))
override val aliases: List[ICommandAlias] = ListedAlias("enc") :: Nil
override val paramRule: String = "[algorithm|(l)] [(uppercase)]"
override val description: String = "通过指定算法加密回复的内容 (目前只支持文本)"

View File

@ -11,7 +11,7 @@ import scala.language.postfixOps
class EventHack (using coeur: MornyCoeur) extends ITelegramCommand {
override val name: String = "event_hack"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[(user|group|any)]"
override val description: String = "输出 bot 下一个获取到的事件序列化数据"

View File

@ -10,7 +10,7 @@ import com.pengrad.telegrambot.request.SendSticker
class GetSocial (using coeur: MornyCoeur) extends ITelegramCommand {
override val name: String = "get"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "<tweet-url|weibo-status-url>"
override val description: String = "从社交媒体分享链接获取其内容"

View File

@ -13,7 +13,7 @@ import scala.language.postfixOps
class GetUsernameAndId (using coeur: MornyCoeur) extends ITelegramCommand {
override val name: String = "user"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[userid]"
override val description: String = "获取指定或回复的用户相关信息"

View File

@ -18,13 +18,13 @@ class IP186Query (using coeur: MornyCoeur) {
object IP extends ITelegramCommand:
override val name: String = "ip"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[ip]"
override val description: String = "通过 https://ip.186526.xyz 查询 ip 资料"
override def execute (using command: InputCommand, event: Update): Unit = query
object Whois extends ITelegramCommand:
override val name: String = "whois"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[domain]"
override val description: String = "通过 https://ip.186526.xyz 查询域名资料"
override def execute (using command: InputCommand, event: Update): Unit = query

View File

@ -25,9 +25,9 @@ trait ISimpleCommand {
* the unique identifier, it uses the same namespace with [[name]], means
* it also cannot be duplicate with other [[name]] or [[aliases]].
*
* It can be [[Null]], means no aliases.
* It should not be [[Null]], using [[Nil]] instead for no aliases.
*/
val aliases: Array[ICommandAlias]|Null
val aliases: List[ICommandAlias]
/** The work code of this command.
*

View File

@ -19,7 +19,7 @@ class MornyCommands (using coeur: MornyCoeur) {
val stash = mutable.SeqMap.empty[String, ISimpleCommand]
for (i <- commands)
stash += (i.name -> i)
if (i.aliases ne null) for (alias <- i.aliases)
for (alias <- i.aliases)
stash += (alias.name -> i)
stash
@ -122,7 +122,7 @@ class MornyCommands (using coeur: MornyCoeur) {
BotCommand(name, if paramRule isBlank then intro else s"$paramRule - $intro")
val list = mutable.ArrayBuffer[BotCommand](
buildOne(command.name, command.paramRule, command.description))
if (command.aliases ne null) for (alias <- command.aliases)
for (alias <- command.aliases)
if (alias.listed) list += buildOne(alias.name, "", "↑")
list toArray

View File

@ -14,7 +14,7 @@ class MornyHellos (using coeur: MornyCoeur) {
object On extends ITelegramCommand {
override val name: String = "on"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = ""
override val description: String = "检查是否在线"
@ -29,7 +29,7 @@ class MornyHellos (using coeur: MornyCoeur) {
object Hello extends ITelegramCommand {
override val name: String = "hello"
override val aliases: Array[ICommandAlias] | Null = Array(ListedAlias("hi"))
override val aliases: List[ICommandAlias] = ListedAlias("hi") :: Nil
override val paramRule: String = ""
override val description: String = "打招呼"

View File

@ -13,7 +13,7 @@ import scala.language.postfixOps
class MornyInfoOnStart (using coeur: MornyCoeur) extends ISimpleCommand {
override val name: String = "start"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = {

View File

@ -27,7 +27,7 @@ class MornyInformation (using coeur: MornyCoeur) extends ITelegramCommand {
}
override val name: String = "info"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[(version|runtime|stickers[.IDs]|tasks|event)]"
override val description: String = "输出当前 Morny 的各种信息"

View File

@ -7,12 +7,12 @@ class MornyInformationOlds (using base: MornyInformation) {
object Version extends ISimpleCommand:
override val name: String = "version"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = base.echoVersion
object Runtime extends ISimpleCommand:
override val name: String = "runtime"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = base.echoRuntime
}

View File

@ -17,7 +17,7 @@ class MornyManagers (using coeur: MornyCoeur) {
object Exit extends ITelegramCommand {
override val name: String = "exit"
override val aliases: Array[ICommandAlias] | Null = Array(HiddenAlias("stop"), HiddenAlias("quit"))
override val aliases: List[ICommandAlias] = HiddenAlias("stop") :: HiddenAlias("quit") :: Nil
override val paramRule: String = "exit"
override val description: String = "关闭 Bot (仅可信成员)"
@ -52,7 +52,7 @@ class MornyManagers (using coeur: MornyCoeur) {
object SaveData extends ITelegramCommand {
override val name: String = "save"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = ""
override val description: String = "保存缓存数据到文件(仅可信成员)"

View File

@ -11,7 +11,7 @@ import com.pengrad.telegrambot.request.SendMessage
class MornyOldJrrp (using coeur: MornyCoeur) extends ITelegramCommand {
override val name: String = "jrrp"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = ""
override val description: String = "获取 (假的) jrrp"

View File

@ -21,7 +21,7 @@ class Nbnhhsh (using coeur: MornyCoeur) extends ITelegramCommand {
"<a href=\"https://lab.magiconch.com/nbnhhsh/\">## Result of nbnhhsh query :</a>"
override val name: String = "nbnhhsh"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = "[text]"
override val description: String = "检索文本内 nbnhhsh 词条"

View File

@ -12,7 +12,7 @@ import scala.language.postfixOps
class Testing (using coeur: MornyCoeur) extends ISimpleCommand {
override val name: String = "test"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = {

View File

@ -1,11 +1,10 @@
package cc.sukazyo.cono.morny.bot.command
import cc.sukazyo.cono.morny.MornyCoeur
import cc.sukazyo.cono.morny.data.TelegramStickers
import cc.sukazyo.cono.morny.util.tgapi.InputCommand
import cc.sukazyo.cono.morny.util.tgapi.TelegramExtensions.Bot.*
import com.pengrad.telegrambot.model.{MessageEntity, Update}
import com.pengrad.telegrambot.request.{SendMessage, SendSticker}
import com.pengrad.telegrambot.request.SendMessage
//noinspection NonAsciiCharacters
class (using coeur: MornyCoeur) {
@ -13,7 +12,7 @@ class 创 (using coeur: MornyCoeur) {
object Chuang extends ISimpleCommand {
override val name: String = "chuang"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = {

View File

@ -17,35 +17,35 @@ class 喵呜 (using coeur: MornyCoeur) {
object 抱抱 extends ISimpleCommand {
override val name: String = "抱抱"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit =
replyingSet("贴贴", "贴贴")
}
object 揉揉 extends ISimpleCommand {
override val name: String = "揉揉"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit =
replyingSet("蹭蹭", "摸摸")
}
object 蹭蹭 extends ISimpleCommand {
override val name: String = "蹭蹭"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit =
replyingSet("揉揉", "蹭蹭")
}
object 贴贴 extends ISimpleCommand {
override val name: String = "贴贴"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit =
replyingSet("贴贴", "贴贴")
}
object Progynova extends ITelegramCommand {
override val name: String = "install"
override val aliases: Array[ICommandAlias]|Null = null
override val aliases: List[ICommandAlias] = Nil
override val paramRule: String = ""
override val description: String = "抽取一个神秘盒子"
override def execute (using command: InputCommand, event: Update): Unit = {

View File

@ -12,7 +12,7 @@ import com.pengrad.telegrambot.request.SendMessage
class 私わね (using coeur: MornyCoeur) extends ISimpleCommand {
override val name: String = "me"
override val aliases: Array[ICommandAlias] | Null = null
override val aliases: List[ICommandAlias] = Nil
override def execute (using command: InputCommand, event: Update): Unit = {