mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 11:14:55 +08:00
添加 inline/raw 功能,依赖更新与javadoc:Log修改
- 添加输出原始消息的 InlineQuery 功能。 - 依赖:messiva : 0.1.0.0 -> 0.1.0.1
This commit is contained in:
parent
6c8f311faf
commit
a2011e486d
@ -1,12 +1,12 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.4.1.2
|
VERSION = 0.4.1.3
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
libSpotbugsVersion = 4.5.0
|
libSpotbugsVersion = 4.5.0
|
||||||
|
|
||||||
libMessivaVersion = 0.1.0.0
|
libMessivaVersion = 0.1.0.1
|
||||||
|
|
||||||
libJavaTelegramBotApiVersion = 5.5.0
|
libJavaTelegramBotApiVersion = 5.5.0
|
||||||
|
|
||||||
|
@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
|
|||||||
* the final field that will be updated by gradle automatically.
|
* the final field that will be updated by gradle automatically.
|
||||||
*/
|
*/
|
||||||
public class GradleProjectConfigures {
|
public class GradleProjectConfigures {
|
||||||
public static final String VERSION = "0.4.1.2";
|
public static final String VERSION = "0.4.1.3";
|
||||||
public static final long COMPILE_TIMESTAMP = 1639211288142L;
|
public static final long COMPILE_TIMESTAMP = 1639476313268L;
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,15 @@ import cc.sukazyo.messiva.Logger;
|
|||||||
import cc.sukazyo.messiva.appender.ConsoleAppender;
|
import cc.sukazyo.messiva.appender.ConsoleAppender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Morny 的简单控制台 log 记录器
|
* Morny 的 log 管理器
|
||||||
*/
|
*/
|
||||||
public class Log {
|
public class Log {
|
||||||
|
|
||||||
/** Morny 的 Logger 实例 */
|
/**
|
||||||
|
* Morny 的 Logger 实例,
|
||||||
|
* messiva 更新
|
||||||
|
* @since 0.4.1.1
|
||||||
|
*/
|
||||||
public static final Logger logger = new Logger(new ConsoleAppender());
|
public static final Logger logger = new Logger(new ConsoleAppender());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,15 @@ public class EventListeners {
|
|||||||
public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
public static final OnActivityRecord ACTIVITY_RECORDER = new OnActivityRecord();
|
||||||
public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction();
|
public static final OnUserSlashAction USER_SLASH_ACTION = new OnUserSlashAction();
|
||||||
public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock();
|
public static final OnUpdateTimestampOffsetLock UPDATE_TIMESTAMP_OFFSET_LOCK = new OnUpdateTimestampOffsetLock();
|
||||||
|
public static final OnInlineQuery INLINE_QUERY = new OnInlineQuery();
|
||||||
|
|
||||||
public static void registerAllListeners () {
|
public static void registerAllListeners () {
|
||||||
EventListenerManager.addListener(
|
EventListenerManager.addListener(
|
||||||
ACTIVITY_RECORDER,
|
ACTIVITY_RECORDER,
|
||||||
UPDATE_TIMESTAMP_OFFSET_LOCK,
|
UPDATE_TIMESTAMP_OFFSET_LOCK,
|
||||||
COMMANDS_LISTENER,
|
COMMANDS_LISTENER,
|
||||||
USER_SLASH_ACTION
|
USER_SLASH_ACTION,
|
||||||
|
INLINE_QUERY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java
Normal file
61
src/main/java/cc/sukazyo/cono/morny/util/EncryptUtils.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于数据加密或编码的工具类<br>
|
||||||
|
* <s>显然大部分代码是抄来的</s><br>
|
||||||
|
* <ul>
|
||||||
|
* <li><a href="https://blog.csdn.net/yu540135101/article/details/86765457">{@link #encryptByMD5} & {@link #byteToHex}
|
||||||
|
* & {@link #byteArrayToHex} 来源</a></li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user