mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-26 21:17:41 +08:00
Compare commits
25 Commits
45a85e15f5
...
30c5ae71cc
Author | SHA1 | Date | |
---|---|---|---|
30c5ae71cc | |||
692abb9f56 | |||
253208e830 | |||
49bbc03ec0 | |||
3661cb1264 | |||
afe8d315a2 | |||
72aea15209 | |||
e42dfacb2e | |||
30b10382d6 | |||
6b7c895ddc | |||
7def016bdc | |||
0d4588d3d2 | |||
77337b4557 | |||
864800122e | |||
f0821ac492 | |||
fc3eb3983a | |||
31e25308bb | |||
fcea3d51b7 | |||
f9d3601c42 | |||
868542cd4e | |||
85bc22ea91 | |||
f6b64493b2 | |||
7dee5a9d40 | |||
9f394bef66 | |||
8e570405c2 |
@ -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-RC6
|
||||
VERSION = 1.1.0
|
||||
|
||||
USE_DELTA = false
|
||||
VERSION_DELTA =
|
||||
|
||||
CODENAME = beiping
|
||||
CODENAME = nanchang
|
||||
|
||||
# dependencies
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package cc.sukazyo.cono.morny
|
||||
|
||||
import cc.sukazyo.messiva.logger.Logger
|
||||
import cc.sukazyo.messiva.appender.ConsoleAppender
|
||||
import cc.sukazyo.messiva.formatter.SimpleFormatter
|
||||
import cc.sukazyo.messiva.log.LogLevel
|
||||
import cc.sukazyo.messiva.logger.Logger
|
||||
|
||||
import java.io.{PrintWriter, StringWriter}
|
||||
|
||||
|
@ -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
|
||||
|
||||
)
|
||||
|
||||
|
76
src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala
Normal file
76
src/main/scala/cc/sukazyo/cono/morny/bot/command/创.scala
Normal file
@ -0,0 +1,76 @@
|
||||
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
|
||||
// this will directly return for not conflict with @autoziyaobot
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,14 @@ import cc.sukazyo.cono.morny.MornyCoeur
|
||||
|
||||
class MornyEventListeners (using manager: EventListenerManager) (using coeur: MornyCoeur) {
|
||||
|
||||
private val $OnUserRandom = OnUserRandom()
|
||||
manager.register(
|
||||
// ACTIVITY_RECORDER
|
||||
// KUOHUANHUAN_NEED_SLEEP
|
||||
OnUniMeowTrigger(using coeur.commands),
|
||||
OnUserRandom(),
|
||||
$OnUserRandom.RandomSelect,
|
||||
//noinspection NonAsciiCharacters
|
||||
$OnUserRandom.尊嘟假嘟,
|
||||
OnQuestionMarkReply(),
|
||||
OnUserSlashAction(),
|
||||
OnCallMe(),
|
||||
|
@ -36,7 +36,9 @@ object OnQuestionMarkReply {
|
||||
|
||||
def isAllMessageMark (using text: String): Boolean = {
|
||||
boundary[Boolean] {
|
||||
for (c <- text) if QUESTION_MARKS contains c then boundary.break(false)
|
||||
for (c <- text)
|
||||
if !(QUESTION_MARKS contains c) then
|
||||
boundary break false
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -4,37 +4,65 @@ import cc.sukazyo.cono.morny.MornyCoeur
|
||||
import cc.sukazyo.cono.morny.bot.api.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.request.{AbstractSendRequest, SendMessage}
|
||||
import com.pengrad.telegrambot.response.SendResponse
|
||||
|
||||
import scala.language.postfixOps
|
||||
|
||||
class OnUserRandom (using coeur: MornyCoeur) extends EventListener {
|
||||
class OnUserRandom (using coeur: MornyCoeur) {
|
||||
|
||||
private val USER_OR_QUERY = "^(.+)(?:还是|or)(.+)$"r
|
||||
private val USER_IF_QUERY = "^(.+)(?:吗\\?|?|\\?|吗?)$"r
|
||||
object RandomSelect extends EventListener {
|
||||
|
||||
override def onMessage(using update: Update): Boolean = {
|
||||
|
||||
if update.message.text == null then return false
|
||||
if !(update.message.text startsWith "/") then return false
|
||||
private val USER_OR_QUERY = "^(.+)(?:还是|or)(.+)$" r
|
||||
private val USER_IF_QUERY = "^(.+)(?:吗\\?|?|\\?|吗?)$" r
|
||||
|
||||
import cc.sukazyo.cono.morny.util.UseRandom.rand_half
|
||||
val query = update.message.text substring 1
|
||||
val result: String|Null = query match
|
||||
case USER_OR_QUERY(_con1, _con2) =>
|
||||
if rand_half then _con1 else _con2
|
||||
case USER_IF_QUERY(_con) =>
|
||||
// for capability with [[OnQuestionMarkReply]]
|
||||
if OnQuestionMarkReply.isAllMessageMark(using _con) then return false
|
||||
(if rand_half then "不" else "") + _con
|
||||
case _ => null
|
||||
override def onMessage (using update: Update): Boolean = {
|
||||
|
||||
if result == null then return false
|
||||
if update.message.text == null then return false
|
||||
if !(update.message.text startsWith "/") then return false
|
||||
|
||||
coeur.account exec SendMessage(
|
||||
update.message.chat.id, result
|
||||
).replyToMessageId(update.message.messageId)
|
||||
true
|
||||
import cc.sukazyo.cono.morny.util.UseRandom.rand_half
|
||||
val query = update.message.text substring 1
|
||||
val result: String | Null = query match
|
||||
case USER_OR_QUERY(_con1, _con2) =>
|
||||
if rand_half then _con1 else _con2
|
||||
case USER_IF_QUERY(_con) =>
|
||||
// for capability with [[OnQuestionMarkReply]]
|
||||
if OnQuestionMarkReply.isAllMessageMark(using _con) then return false
|
||||
(if rand_half then "不" else "") + _con
|
||||
case _ => null
|
||||
|
||||
if result == null then return false
|
||||
|
||||
coeur.account exec SendMessage(
|
||||
update.message.chat.id, result
|
||||
).replyToMessageId(update.message.messageId)
|
||||
true
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//noinspection NonAsciiCharacters
|
||||
object 尊嘟假嘟 extends EventListener {
|
||||
|
||||
private val keywords = Array("尊嘟假嘟", "O.o", "o.O")
|
||||
|
||||
override def onMessage (using event: Update): Boolean = {
|
||||
|
||||
if event.message.text == null then return false
|
||||
|
||||
if !(keywords contains event.message.text) then return false
|
||||
|
||||
import cc.sukazyo.cono.morny.util.UseRandom.rand_half
|
||||
coeur.account exec SendMessage(
|
||||
event.message.chat.id,
|
||||
if rand_half then "尊嘟" else "假嘟"
|
||||
).replyToMessageId(event.message.messageId)
|
||||
true
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
17
src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala
Normal file
17
src/main/scala/cc/sukazyo/cono/morny/util/StringEnsure.scala
Normal file
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.event
|
||||
|
||||
import cc.sukazyo.cono.morny.bot.event.OnQuestionMarkReply
|
||||
import cc.sukazyo.cono.morny.test.MornyTests
|
||||
import org.scalatest.prop.TableDrivenPropertyChecks
|
||||
|
||||
class OnQuestionMarkReplyTest extends MornyTests with TableDrivenPropertyChecks {
|
||||
|
||||
"on replying a question mark :" - {
|
||||
|
||||
"on checking if a message is a question mark :" - {
|
||||
|
||||
val examples = Table(
|
||||
("text", "is"),
|
||||
("回来了", false),
|
||||
("为什么?", false),
|
||||
("?这不合理", false),
|
||||
("??尊嘟假嘟", false),
|
||||
("?????", true),
|
||||
("?", true),
|
||||
("?", true),
|
||||
("??❔", true),
|
||||
)
|
||||
forAll(examples) { (text, is) =>
|
||||
|
||||
s"$text should checked with result $is" in:
|
||||
OnQuestionMarkReply.isAllMessageMark(using text) shouldEqual is
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user