From f195d5c1bbec1a5da013834ab7195d97336d2495 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Sat, 15 Oct 2022 17:16:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=20/info=20stickers?= =?UTF-8?q?=20=E5=91=BD=E4=BB=A4=E5=8F=AF=E4=BB=A5(=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=8F=8D=E5=B0=84)=E5=88=97=E5=87=BA=20morny=20=E6=89=80?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=9A=84=E6=89=80=E6=9C=89=E8=B4=B4=E7=BA=B8?= =?UTF-8?q?=E6=88=96=E6=98=AF=E6=9F=90=E8=B4=B4=E7=BA=B8=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=89=80=E5=AE=9A=E4=B9=89=E7=9A=84=E8=B4=B4=E7=BA=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../command/{EncUtils.java => Encryptor.java} | 2 +- .../cono/morny/bot/command/MornyCommands.java | 3 +- .../morny/bot/command/MornyInformations.java | 46 ++++++++++++++++++ .../cono/morny/data/TelegramStickers.java | 48 +++++++++++++++++++ 6 files changed, 100 insertions(+), 5 deletions(-) rename src/main/java/cc/sukazyo/cono/morny/bot/command/{EncUtils.java => Encryptor.java} (99%) create mode 100644 src/main/java/cc/sukazyo/cono/morny/bot/command/MornyInformations.java diff --git a/gradle.properties b/gradle.properties index 3c7131f..dfdc9dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.8.0.5 +VERSION = 0.8.0.6 CODENAME = fuzhou diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index b1ea0ac..203a4a6 100644 --- a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java +++ b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java @@ -4,7 +4,7 @@ package cc.sukazyo.cono.morny; * the final field that will be updated by gradle automatically. */ public class GradleProjectConfigures { - public static final String VERSION = "0.8.0.5"; + public static final String VERSION = "0.8.0.6"; public static final String CODENAME = "fuzhou"; - public static final long COMPILE_TIMESTAMP = 1665763018652L; + public static final long COMPILE_TIMESTAMP = 1665825000740L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/EncUtils.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/Encryptor.java similarity index 99% rename from src/main/java/cc/sukazyo/cono/morny/bot/command/EncUtils.java rename to src/main/java/cc/sukazyo/cono/morny/bot/command/Encryptor.java index 1c439e0..93aacca 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/EncUtils.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/Encryptor.java @@ -20,7 +20,7 @@ import java.util.Base64; import static cc.sukazyo.cono.morny.Log.logger; -public class EncUtils implements ITelegramCommand { +public class Encryptor implements ITelegramCommand { @Nonnull @Override public String getName () { return "encrypt"; } @Nullable @Override public String[] getAliases () { return new String[0]; } 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 381dc36..7b37258 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 @@ -68,8 +68,9 @@ public class MornyCommands { new Nbnhhsh(), new Ip186Query.Ip(), new Ip186Query.Whois(), - new EncUtils(), + new Encryptor(), new SaveData(), + new MornyInformations(), new Version(), new MornyRuntime(), new Jrrp(), diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyInformations.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyInformations.java new file mode 100644 index 0000000..9d815bb --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/MornyInformations.java @@ -0,0 +1,46 @@ +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 com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.request.SendSticker; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class MornyInformations implements ITelegramCommand { + + private static final String ACT_STICKER = "stickers"; + + @Nonnull @Override public String getName () { return "info"; } + @Nullable @Override public String[] getAliases () { return new String[0]; } + @Nonnull @Override public String getParamRule () { return "[(stickers)|(stickers.)sticker_id]"; } + @Nonnull @Override public String getDescription () { return "输出 Morny 当前版本的一些预定义信息"; } + + @Override + public void execute (@Nonnull InputCommand command, @Nonnull Update event) { + + if (!command.hasArgs() || command.getArgs().length > 1) { + MornyCoeur.extra().exec(new SendSticker(event.message().chat().id(), TelegramStickers.ID_404).replyToMessageId(event.message().messageId())); + } + + final String action = command.getArgs()[0]; + + if (action.startsWith("stickers")) { + if (action.equals("stickers")) + TelegramStickers.echoAllStickers(MornyCoeur.extra(), event.message().chat().id(), event.message().messageId()); + else { + TelegramStickers.echoStickerByID( + action.substring((ACT_STICKER+".").length()), + MornyCoeur.extra(), event.message().chat().id(), event.message().messageId() + ); + } + return; + } + + MornyCoeur.extra().exec(new SendSticker(event.message().chat().id(), TelegramStickers.ID_404).replyToMessageId(event.message().messageId())); + + } + +} 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 0acd42b..fb3f01c 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java @@ -1,5 +1,12 @@ package cc.sukazyo.cono.morny.data; +import cc.sukazyo.cono.morny.util.tgapi.ExtraAction; +import com.pengrad.telegrambot.request.SendMessage; +import com.pengrad.telegrambot.request.SendSticker; +import com.pengrad.telegrambot.response.SendResponse; + +import java.lang.reflect.Field; + /** * 存放 bot 使用到的贴纸 * @since 0.4.2.0 @@ -17,4 +24,45 @@ public class TelegramStickers { public static final String ID_PROGYNOVA = "CAACAgUAAxkBAAICm2KEuL7UQqNP7vSPCg2DHJIND6UsAAKLAwACH4WSBszIo722aQ3jJAQ"; public static final String ID_NETWORK_ERR = "CAACAgEAAxkBAAID0WNJgNEkD726KW4vZeFlw0FlVVyNAAIXJgACePzGBb50o7O1RbxoKgQ"; + public static void echoAllStickers (ExtraAction actionObject, long sentChat, int replyToMessageId) { + + for (Field object : TelegramStickers.class.getFields()) { + if (object.getType()==String.class && object.getName().startsWith("ID_")) { + try { + + final String stickerId = (String)object.get(""); + SendSticker echo = new SendSticker(sentChat, stickerId); + SendMessage echoName = new SendMessage(sentChat, object.getName()); + if (replyToMessageId!=-1) echo.replyToMessageId(replyToMessageId); + SendResponse echoedName = actionObject.exec(echoName); + actionObject.exec(echo.replyToMessageId(echoedName.message().messageId())); + + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + } + + public static void echoStickerByID (String stickerFieldID, ExtraAction actionObject, long sentChat, int replyToMessageId) { + try { + // normally get the sticker and echo + Field sticker = TelegramStickers.class.getField(stickerFieldID); + SendMessage echoName = new SendMessage(sentChat, sticker.getName()); + SendSticker echo = new SendSticker(sentChat, (String)sticker.get("")); + if (replyToMessageId!=-1) echo.replyToMessageId(replyToMessageId); + SendResponse echoedName = actionObject.exec(echoName); + actionObject.exec(echo.replyToMessageId(echoedName.message().messageId())); + } catch (NoSuchFieldException e) { + // no such sticker found + SendSticker echo404 = new SendSticker(sentChat, TelegramStickers.ID_404); + if (replyToMessageId!=-1) echo404.replyToMessageId(replyToMessageId); + actionObject.exec(echo404); + } catch (IllegalAccessException e) { + // java-reflect get sticker FILE_ID failed + throw new RuntimeException(e); + } + } + }