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); + } + } + }