From 253208e83004543eb2894f473cde7af5e6ba3483 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 9 Oct 2023 18:32:36 +0800 Subject: [PATCH] add /chuang --- gradle.properties | 4 +- .../morny/bot/command/MornyCommands.scala | 6 +- .../sukazyo/cono/morny/bot/command/创.scala | 79 +++++++++++++++++++ .../cono/morny/util/StringEnsure.scala | 17 ++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala create mode 100644 src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala diff --git a/gradle.properties b/gradle.properties index 0620ae1..603ea0b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ MORNY_ARCHIVE_NAME = morny-coeur MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s -VERSION = 1.0.0 +VERSION = 1.1.0-alpha1 USE_DELTA = false VERSION_DELTA = -CODENAME = beiping +CODENAME = nanchang # dependencies diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommands.scala b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommands.scala index dbc3205..0121b0c 100644 --- a/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommands.scala +++ b/src/main/scala/cc/sukazyo/cono/morny/bot/command/MornyCommands.scala @@ -30,6 +30,8 @@ class MornyCommands (using coeur: MornyCoeur) { private val $MornyManagers = MornyManagers() //noinspection NonAsciiCharacters private val $喵呜 = 喵呜() + //noinspection NonAsciiCharacters + private val $创 = 创() private val commands: CommandMap = CommandMap( $MornyHellos.On, @@ -54,7 +56,9 @@ class MornyCommands (using coeur: MornyCoeur) { //noinspection NonAsciiCharacters 私わね(), //noinspection NonAsciiCharacters - $喵呜.Progynova + $喵呜.Progynova, + //noinspection NonAsciiCharacters + $创.Chuang ) diff --git a/src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala b/src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala new file mode 100644 index 0000000..508bd99 --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala @@ -0,0 +1,79 @@ +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} + +//noinspection NonAsciiCharacters +class 创 (using coeur: MornyCoeur) { + + object Chuang extends ISimpleCommand { + + override val name: String = "chuang" + override val aliases: Array[ICommandAlias] | Null = null + + override def execute (using command: InputCommand, event: Update): Unit = { + + val text = + if (command.args nonEmpty) + command.args mkString " " + else if ((event.message.replyToMessage ne null) && (event.message.replyToMessage.text ne null)) + event.message.replyToMessage.text + else + coeur.account exec SendSticker( + event.message.chat.id, + TelegramStickers ID_404 + ).replyToMessageId(event.message.messageId) + return; + + val chuangText = 创.chuangText(text) + coeur.account exec SendMessage( + event.message.chat.id, + chuangText + ).entities( + MessageEntity(MessageEntity.Type.pre, 0, chuangText.length) + ).replyToMessageId(event.message.messageId) + + } + + } + +} + +//noinspection NonAsciiCharacters +object 创 { + + def chuangText (text: String): String = { + + val c = StringBuilder() + + import cc.sukazyo.cono.morny.util.StringEnsure.ensureSize + + import Math.* + val lines = text split '\n' + val _base = max(5, lines.map(l => l.length).max) + val _min = 5 + val _ext = _base - _min + c ++= raw" " ++= " " * _base ++= raw" \ | " += '\n' + c ++= raw" " ++= " " * _base ++= raw" -+- " += '\n' + c ++= raw" +-+-" ++= "-" * _base ++= raw"-+-\ O " += '\n' + c ++= raw" | | " ++= " " * _base ++= raw" || \ " += '\n' + if (lines.length > 1) + c ++= raw" | | " ++= lines(0).ensureSize(_base) ++= raw" || \ " += '\n' + for (l <- lines drop 1 dropRight 1) + c ++= raw" | | " ++= l.ensureSize(_base) ++= raw" || | " += '\n' + c ++= raw" | | " ++= lines.last.ensureSize(_base) ++= raw" || | O " += '\n' + else + c ++= raw" | | " ++= lines(0).ensureSize(_base) ++= raw" || \ O " += '\n' + c ++= raw" | | " ++= " " * _base ++= raw" || | -+- " += '\n' + c ++= raw" +-+-" ++= raw"-/-\-${"-" * _ext}" ++= raw"-++/-\+ _/ \ " += '\n' + c ++= raw" " ++= raw" \_/ ${" " * _ext}" ++= raw" \-/ " += '\n' + + c toString + + } + +} diff --git a/src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala b/src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala new file mode 100644 index 0000000..c56dd16 --- /dev/null +++ b/src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala @@ -0,0 +1,17 @@ +package cc.sukazyo.cono.morny.util + +object StringEnsure { + + + extension (str: String) { + + def ensureSize(size: Int, paddingStr: Char = ' '): String = { + if (str.length < size) { + val padding = paddingStr.toString * (size-str.length) + str + padding + } else str + } + + } + +}