From 7bbe75a522d5b3ad6bb125c26a8964683782a702 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 8 Mar 2022 20:26:10 +0800 Subject: [PATCH 1/3] feature fix #28 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../cono/morny/bot/command/MornyCommands.java | 3 +- .../cono/morny/bot/command/私わね.java | 38 +++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/command/私わね.java diff --git a/gradle.properties b/gradle.properties index 0aad69a..a1972de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.5.1.1 +VERSION = 0.5.2.0 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index fd967ea..6718b5e 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.5.1.1"; - public static final long COMPILE_TIMESTAMP = 1644381533694L; + public static final String VERSION = "0.5.2.0"; + public static final long COMPILE_TIMESTAMP = 1646742061976L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java index fa4c7f8..9b53ac1 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyCommands.java @@ -76,7 +76,8 @@ public class MornyCommands { new 喵呜.抱抱(), new 喵呜.揉揉(), new 喵呜.蹭蹭(), - new 喵呜.贴贴() + new 喵呜.贴贴(), + new 私わね() ); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/私わね.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/私わね.java new file mode 100644 index 0000000..e06f66a --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/私わね.java @@ -0,0 +1,38 @@ +package cc.sukazyo.cono.morny.bot.command; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.untitled.util.telegram.object.InputCommand; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.request.SendMessage; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.concurrent.ThreadLocalRandom; + +@SuppressWarnings("NonAsciiCharacters") +public class 私わね implements ISimpleCommand { + + @Nonnull + @Override public String getName () { return "/me"; } + + @Nullable + @Override public String[] getAliases () { return null; } + + @Override + public void execute (@Nonnull InputCommand command, @Nonnull Update event) { + if (ThreadLocalRandom.current().nextInt(521) == 0) { + // 可以接入未来的心情系统(如果有的话) + final String text = switch (ThreadLocalRandom.current().nextInt(11)) { + case 0,7,8,9,10 -> "才不是"; + case 1,2,3,6 -> "才不是!"; + case 4,5 -> "才不是.."; + default -> throw new IllegalStateException("Unexpected random value in 私わね command."); + }; + MornyCoeur.extra().exec(new SendMessage( + event.message().chat().id(), + text + ).replyToMessageId(event.message().messageId())); + } + } + +} From b9aa9de57a42084b6a0d0271d54311d3b61c3b04 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sun, 13 Mar 2022 19:21:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=BA=20@kuohuanhuan=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=9D=A1=E8=A7=89=E7=A6=81=E6=AD=A2=E5=8F=91=E8=A8=80?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +-- .../cono/morny/bot/event/EventListeners.java | 2 ++ .../bot/event/OnKuohuanhuanNeedSleep.java | 32 +++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java diff --git a/gradle.properties b/gradle.properties index a1972de..5667829 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.5.2.0 +VERSION = 0.5.2.1 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 6718b5e..8d7906c 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.5.2.0"; - public static final long COMPILE_TIMESTAMP = 1646742061976L; + public static final String VERSION = "0.5.2.1"; + public static final long COMPILE_TIMESTAMP = 1647170439025L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java index 3920a57..4eca5a5 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/EventListeners.java @@ -11,11 +11,13 @@ public class EventListeners { public static final OnInlineQueries INLINE_QUERY = new OnInlineQueries(); public static final OnCallMe CALL_ME = new OnCallMe(); public static final OnEventHackHandle EVENT_HACK_HANDLE = new OnEventHackHandle(); + public static final OnKuohuanhuanNeedSleep KUOHUANHUAN_NEED_SLEEP = new OnKuohuanhuanNeedSleep(); public static void registerAllListeners () { EventListenerManager.addListener( ACTIVITY_RECORDER, UPDATE_TIMESTAMP_OFFSET_LOCK, + KUOHUANHUAN_NEED_SLEEP, COMMANDS_LISTENER, USER_SLASH_ACTION, INLINE_QUERY, diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java new file mode 100644 index 0000000..3c7101c --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java @@ -0,0 +1,32 @@ +package cc.sukazyo.cono.morny.bot.event; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.cono.morny.bot.api.EventListener; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.request.DeleteMessage; + +import javax.annotation.Nonnull; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Locale; + +public class OnKuohuanhuanNeedSleep extends EventListener { + + @Override + public boolean onMessage (@Nonnull Update update) { + if ( + update.message().from().id() == 786563752L && ( + new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) >= 23 || + new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) < 5 + ) + ) { + MornyCoeur.extra().exec( + new DeleteMessage(update.message().chat().id(), + update.message().messageId()) + ); + return true; + } + return false; + } + +} From 79e61e28a26049ab941af7ea52eb05f8f9ed85fa Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 14 Mar 2022 14:10:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=9C=E7=BA=BF=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=E5=9F=BA=E6=9C=AC=E7=AC=A6=E5=90=88=20t.me/h?= =?UTF-8?q?asutestbot=20=E6=A0=87=E5=87=86=20(#26)=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=94=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../morny/bot/event/OnUserSlashAction.java | 41 +++++++++---------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5667829..f0b6faa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.5.2.1 +VERSION = 0.6.0.2 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 8d7906c..1316cb7 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.5.2.1"; - public static final long COMPILE_TIMESTAMP = 1647170439025L; + public static final String VERSION = "0.6.0.2"; + public static final long COMPILE_TIMESTAMP = 1647237887029L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java index 5c4cf79..bfb5da3 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnUserSlashAction.java @@ -38,25 +38,23 @@ public class OnUserSlashAction extends EventListener { return false; } - int prefixLength = 1; - boolean useVerbSuffix = true; - boolean useObjectPrefix = true; - if (text.startsWith("//#") || text.startsWith("///")) { - useVerbSuffix = false; - useObjectPrefix = false; - prefixLength = 3; - } else if (text.startsWith("/#")) { - useObjectPrefix = false; - prefixLength = 2; - } else if (text.startsWith("//")) { - useVerbSuffix = false; - prefixLength = 2; + final String[] action = CommonCommand.format(text); + action[0] = action[0].substring(1); + + if (action[0].matches("^[a-zA-Z_]+$")) { + return false; // 忽略掉 Telegram 命令格式的输入 + } else if (action[0].contains("/")) { + return false; // 忽略掉疑似目录格式的输入 } - final String[] action = CommonCommand.format(text.substring(prefixLength)); - final String verb = action[0]; - final boolean hasObject = action.length != 1; - final String object = StringArrays.connectStringArray(action, " ", 1, action.length-1); + final boolean isHardParse = "".equals(action[0]); + /* 忽略空数据 */ if (isHardParse && action.length < 2) { return false; } + final String verb = isHardParse ? action[1] : action[0]; + final boolean hasObject = action.length != (isHardParse?2:1); + final String object = + hasObject ? + StringArrays.connectStringArray(action, " ", isHardParse?2:1, action.length-1) : + ""; final User origin = event.message().from(); final User target = (event.message().replyToMessage() == null ? ( origin @@ -67,16 +65,15 @@ public class OnUserSlashAction extends EventListener { MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), String.format( - "%s %s%s %s%s%s", + "%s %s%s %s %s!", TGToString.as(origin).firstnameRefHtml(), - verb, escapeHtml((useVerbSuffix?"了":"")), + escapeHtml(verb), escapeHtml((hasObject?"":"了")), origin==target ? "自己" : TGToString.as(target).firstnameRefHtml(), - escapeHtml((hasObject ? (useObjectPrefix ?" 的": " ") : "")), - escapeHtml((hasObject ? object : "")) + escapeHtml(hasObject ? object+" " : "") ) - ).parseMode(ParseMode.HTML)); + ).parseMode(ParseMode.HTML).replyToMessageId(event.message().messageId())); return true;