diff --git a/gradle.properties b/gradle.properties index 67c4c6b..2e5218c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.4.2.0 +VERSION = 0.4.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 04559c8..cff1c8f 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.4.2.0"; - public static final long COMPILE_TIMESTAMP = 1639492714364L; + public static final String VERSION = "0.4.2.1"; + public static final long COMPILE_TIMESTAMP = 1639494688933L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java b/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java index 6fa7883..c2a07de 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyTrusted.java @@ -14,6 +14,12 @@ public class MornyTrusted { */ public static final long TRUSTED_CHAT_ID = -1001541451710L; + /** + * morny 的主人
+ * 这项值的对象总是会被认为是可信任的 + */ + public static final long MASTER = 793274677L; + /** * 用于检查一个 telegram-user 是否受信任
*
@@ -25,6 +31,7 @@ public class MornyTrusted { * @return 所传递的用户id对应的用户是否受信任 */ public static boolean isTrusted (long userId) { + if (userId == MASTER) return true; final ChatMember chatMember = MornyCoeur.getAccount().execute(new GetChatMember(TRUSTED_CHAT_ID, userId)).chatMember(); return ( chatMember != null && ( 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 a08e3fe..47e4699 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 @@ -9,6 +9,7 @@ public class EventListeners { public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction(); public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock(); public static final OnInlineQuery INLINE_QUERY = new OnInlineQuery(); + public static final OnCallMe CALL_ME = new OnCallMe(); public static void registerAllListeners () { EventListenerManager.addListener( @@ -16,7 +17,8 @@ public class EventListeners { UPDATE_TIMESTAMP_OFFSET_LOCK, COMMANDS_LISTENER, USER_SLASH_ACTION, - INLINE_QUERY + INLINE_QUERY, + CALL_ME ); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java new file mode 100644 index 0000000..db1f20f --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java @@ -0,0 +1,74 @@ +package cc.sukazyo.cono.morny.bot.event; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.cono.morny.MornyTrusted; +import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.data.TelegramStickers; +import com.pengrad.telegrambot.model.Chat; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.model.request.ParseMode; +import com.pengrad.telegrambot.request.SendMessage; +import com.pengrad.telegrambot.request.SendSticker; +import org.jetbrains.annotations.NotNull; + +/** + * @since 0.4.2.1 + */ +public class OnCallMe extends EventListener { + + /** + * @since 0.4.2.1 + */ + private static final long ME = MornyTrusted.MASTER; + + @Override + public boolean onMessage (@NotNull Update update) { + if (update.message().text() == null) + return false; + if (update.message().chat().type() != Chat.Type.Private) + return false; + switch (update.message().text().toLowerCase()) { + case "steam": + case "sbeam": + case "sdeam": + requestSteamJoin(update); + break; + case "hana paresu": + case "花宫": + case "内群": + requestHanaParesuJoin(update); + break; + default: + return false; + } + MornyCoeur.getAccount().execute(new SendSticker( + update.message().chat().id(), + TelegramStickers.ID_SENT + ).replyToMessageId(update.message().messageId()) + ); + return true; + } + + private static void requestSteamJoin (Update event) { + MornyCoeur.getAccount().execute(new SendMessage( + ME, String.format(""" + request STEAM LIBRARY + from %s""", + event.message().from().id(), + event.message().from().firstName() + " " + event.message().from().lastName() + ) + ).parseMode(ParseMode.HTML)); + } + + private static void requestHanaParesuJoin (Update event) { + MornyCoeur.getAccount().execute(new SendMessage( + ME, String.format(""" + request Hana Paresu + from %s""", + event.message().from().id(), + event.message().from().firstName() + " " + event.message().from().lastName() + ) + ).parseMode(ParseMode.HTML)); + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java index d4715e1..d478e05 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java @@ -12,5 +12,6 @@ public class TelegramStickers { public static final String ID_403 = "CAACAgEAAxkBAAMqYYYa_7hpXH6hMOYMX4Nh8AVYd74AAnQnAAJ4_MYFRdmmsQKLDZgiBA"; public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA"; public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA"; + public static final String ID_SENT = "CAACAgEAAx0CSQh32gABA--zYbiyU_wOijEitp-0tSl_k7W6l3gAAgMmAAJ4_MYF4GrompjXPx4jBA"; }