diff --git a/gradle.properties b/gradle.properties index 96a7c65..ad6e88f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,12 @@ ## Core -VERSION = 0.4.1.2 +VERSION = 0.4.1.3 # dependencies libSpotbugsVersion = 4.5.0 -libMessivaVersion = 0.1.0.0 +libMessivaVersion = 0.1.0.1 libJavaTelegramBotApiVersion = 5.5.0 diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 305a77b..9000285 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.1.2"; - public static final long COMPILE_TIMESTAMP = 1639211288142L; + public static final String VERSION = "0.4.1.3"; + public static final long COMPILE_TIMESTAMP = 1639476313268L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/Log.java b/src/main/java/cc/sukazyo/cono/morny/Log.java index 7109fcb..b58c825 100644 --- a/src/main/java/cc/sukazyo/cono/morny/Log.java +++ b/src/main/java/cc/sukazyo/cono/morny/Log.java @@ -4,11 +4,15 @@ import cc.sukazyo.messiva.Logger; import cc.sukazyo.messiva.appender.ConsoleAppender; /** - * Morny 的简单控制台 log 记录器 + * Morny 的 log 管理器 */ public class Log { - /** Morny 的 Logger 实例 */ + /** + * Morny 的 Logger 实例, + * messiva 更新 + * @since 0.4.1.1 + */ public static final Logger logger = new Logger(new ConsoleAppender()); } 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 8bb693b..a08e3fe 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 @@ -8,13 +8,15 @@ public class EventListeners { public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord(); 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 void registerAllListeners () { EventListenerManager.addListener( ACTIVITY_RECORDER, UPDATE_TIMESTAMP_OFFSET_LOCK, COMMANDS_LISTENER, - USER_SLASH_ACTION + USER_SLASH_ACTION, + INLINE_QUERY ); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java new file mode 100644 index 0000000..6bf189e --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnInlineQuery.java @@ -0,0 +1,33 @@ +package cc.sukazyo.cono.morny.bot.event; + +import cc.sukazyo.cono.morny.MornyCoeur; +import cc.sukazyo.cono.morny.bot.api.EventListener; +import cc.sukazyo.cono.morny.util.EncryptUtils; +import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.model.request.InlineQueryResultArticle; +import com.pengrad.telegrambot.model.request.InputTextMessageContent; +import com.pengrad.telegrambot.model.request.ParseMode; +import com.pengrad.telegrambot.request.AnswerInlineQuery; +import org.jetbrains.annotations.NotNull; + +/** + * @since 0.4.1.3 + */ +public class OnInlineQuery extends EventListener { + + /** + * @since 0.4.1.3 + */ + @Override + public boolean onInlineQuery (@NotNull Update update) { + MornyCoeur.getAccount().execute(new AnswerInlineQuery(update.inlineQuery().id(), new InlineQueryResultArticle[]{ + new InlineQueryResultArticle( + EncryptUtils.encryptByMD5(update.inlineQuery().query()), + "Raw Input", + new InputTextMessageContent(update.inlineQuery().query()).parseMode(ParseMode.MarkdownV2) + ) + })); + return true; + } + +} diff --git a/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java b/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java new file mode 100644 index 0000000..6d502f9 --- /dev/null +++ b/src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java @@ -0,0 +1,61 @@ +package cc.sukazyo.cono.morny.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * 用于数据加密或编码的工具类
+ * 显然大部分代码是抄来的
+ * + */ +public class EncryptUtils { + + private final static String[] hexArray = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; + + /*** + * 对指定的字符串进行MD5加密 + */ + public static String encryptByMD5(String originString) { + try { + //创建具有MD5算法的信息摘要 + MessageDigest md = MessageDigest.getInstance("MD5"); + //使用指定的字节数组对摘要进行最后更新,然后完成摘要计算 + byte[] bytes = md.digest(originString.getBytes()); + //将得到的字节数组变成字符串返回 + String s = byteArrayToHex(bytes); + return s.toUpperCase(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 将字节数组转换成十六进制,并以字符串的形式返回 + * 128位是指二进制位。二进制太长,所以一般都改写成16进制, + * 每一位16进制数可以代替4位二进制数,所以128位二进制数写成16进制就变成了128/4=32位。 + */ + private static String byteArrayToHex(byte[] b){ + StringBuilder sb = new StringBuilder(); + for (byte value : b) { + sb.append(byteToHex(value)); + } + return sb.toString(); + } + + /** + * 将一个字节转换成十六进制,并以字符串的形式返回 + */ + public static String byteToHex(byte b) { + int n = b; + if (n < 0) + n = n + 256; + int d1 = n / 16; + int d2 = n % 16; + return hexArray[d1]+hexArray[d2]; + } + +}