From 9c0d207fbb39cb488484b10739fd98d63a8431f9 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Tue, 15 Mar 2022 23:10:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=BA=20@Lapis-Apple=20=E4=B9=9F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20khh=20=E5=AE=9A=E5=88=B6=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E4=BB=A3=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 NbnhhshQuery 类里遗留的测试 main() - 删除 NbnhhshQuery.GuessReq 的冗余 static - TelegramUserInformation 整理空行 --- gradle.properties | 2 +- .../sukazyo/cono/morny/GradleProjectConfigures.java | 4 ++-- .../morny/bot/event/OnKuohuanhuanNeedSleep.java | 13 +++++++++---- .../cc/sukazyo/cono/morny/data/NbnhhshQuery.java | 6 +----- .../cono/morny/util/TelegramUserInformation.java | 1 + 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index f0b6faa..8e2dad1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.0.2 +VERSION = 0.6.1.0 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 1316cb7..1bcf519 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.6.0.2"; - public static final long COMPILE_TIMESTAMP = 1647237887029L; + public static final String VERSION = "0.6.1.0"; + public static final long COMPILE_TIMESTAMP = 1647356707522L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java index 3c7101c..8863f75 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnKuohuanhuanNeedSleep.java @@ -14,11 +14,16 @@ public class OnKuohuanhuanNeedSleep extends EventListener { @Override public boolean onMessage (@Nonnull Update update) { + final GregorianCalendar time = new GregorianCalendar(Locale.TAIWAN); + time.setTimeInMillis(System.currentTimeMillis()); if ( - update.message().from().id() == 786563752L && ( - new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) >= 23 || - new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) < 5 - ) + ( update.message().from().id() == 786563752L && ( + time.get(Calendar.HOUR_OF_DAY) >= 23 || + time.get(Calendar.HOUR_OF_DAY) < 5 + )) || ( update.message().from().id() == 1075871712L && ( + (time.get(Calendar.HOUR_OF_DAY) >= 22 && time.get(Calendar.MINUTE) >= 30) || + time.get(Calendar.HOUR_OF_DAY) < 5 + )) ) { MornyCoeur.extra().exec( new DeleteMessage(update.message().chat().id(), diff --git a/src/main/java/cc/sukazyo/cono/morny/data/NbnhhshQuery.java b/src/main/java/cc/sukazyo/cono/morny/data/NbnhhshQuery.java index 90119aa..cd1be74 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/NbnhhshQuery.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/NbnhhshQuery.java @@ -23,7 +23,7 @@ public class NbnhhshQuery { public Word[] words; } - public static record GuessReq (String text) { + public record GuessReq (String text) { } public static final String API_URL = "https://lab.magiconch.com/api/nbnhhsh/"; @@ -47,8 +47,4 @@ public class NbnhhshQuery { } } - public static void main(String[] args) { - System.out.println(new Gson().toJson(new GuessReq("8h28oey8 qe89 aoHO*)I'[ IK\"@+ )EOI)D\"{AIR\")Q @}"))); - } - } diff --git a/src/main/java/cc/sukazyo/cono/morny/util/TelegramUserInformation.java b/src/main/java/cc/sukazyo/cono/morny/util/TelegramUserInformation.java index 011e4da..1514d56 100644 --- a/src/main/java/cc/sukazyo/cono/morny/util/TelegramUserInformation.java +++ b/src/main/java/cc/sukazyo/cono/morny/util/TelegramUserInformation.java @@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny.util; import com.pengrad.telegrambot.model.User; import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml; + public class TelegramUserInformation { public static String informationOutputHTML (User user) { From 1389fbc59297d923f865b5c4cf9908887d3442e9 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 16 Mar 2022 17:51:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?runtime=20=E4=B8=BB=E6=9C=BA=E5=90=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=BF=A1=E6=81=AF=E5=AE=B9=E9=94=99?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 runtime - system 栏中添加主机名显示 - 如果显示出错则会是 "" - runtime - morny version 改名为 coeur version - MornySystem.getJarMd5 出错时现在不会再直接返回错误而是会返回 "" 或是 "" 信息 --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +-- .../cc/sukazyo/cono/morny/MornySystem.java | 14 +++++++---- .../cono/morny/bot/command/MornyCommands.java | 12 ++++++++- .../cc/sukazyo/cono/morny/util/FileUtils.java | 25 ++++++++----------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8e2dad1..f5516af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.6.1.0 +VERSION = 0.6.1.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 1bcf519..5ca11b5 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.6.1.0"; - public static final long COMPILE_TIMESTAMP = 1647356707522L; + public static final String VERSION = "0.6.1.1"; + public static final long COMPILE_TIMESTAMP = 1647424091182L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/MornySystem.java b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java index 4059bd0..4dbca43 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornySystem.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java @@ -3,7 +3,9 @@ package cc.sukazyo.cono.morny; import cc.sukazyo.cono.morny.util.FileUtils; import javax.annotation.Nonnull; +import java.io.IOException; import java.net.URISyntaxException; +import java.security.NoSuchAlgorithmException; /** * Morny Cono 的 Coeur 的程序属性存放类 @@ -20,20 +22,22 @@ public class MornySystem { * 获取程序 jar 文件的 md5-hash 值
*
* 只支持 jar 文件方式启动的程序 —— - * 如果是通过 classpath 来启动,则会返回找不到文件的错误数据
- * - 或许需要注意,这种情况下会出现程序文件所在的路径
+ * 如果是通过 classpath 来启动,程序无法找到本体jar文件,则会返回 {@code } 文本 *
* 值格式为 {@link java.lang.String} * - * @return 程序jar文件的 md5-hash 值字符串,或错误信息 + * @return 程序jar文件的 md5-hash 值字符串,或 {@code } 如果出现错误 */ @Nonnull public static String getJarMd5() { try { return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); - } catch (URISyntaxException e) { + } catch (IOException | URISyntaxException e) { e.printStackTrace(System.out); - return e.getMessage(); + return ""; + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(System.out); + return ""; } } 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 9b53ac1..69173d4 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 @@ -18,6 +18,8 @@ import com.pengrad.telegrambot.request.SetMyCommands; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -245,19 +247,26 @@ public class MornyCommands { * @since 0.4.1.2 */ private static void onCommandRuntimeExec (@Nonnull Update event) { + String hostname; + try { + hostname = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + hostname = ""; + } MornyCoeur.extra().exec(new SendMessage( event.message().chat().id(), String.format(""" system: - %s - %s + - %s - %d cores java runtime: - %s - %s vm memory: - %d / %d MB - morny version: + coeur version: - %s - %s - %s [UTC] @@ -268,6 +277,7 @@ public class MornyCommands { - %s [UTC] - [%d]""", // system + escapeHtml(hostname), escapeHtml(System.getProperty("os.name")), escapeHtml(System.getProperty("os.version")), Runtime.getRuntime().availableProcessors(), diff --git a/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java b/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java index c64a3db..57ff657 100644 --- a/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java +++ b/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java @@ -10,23 +10,18 @@ import java.security.NoSuchAlgorithmException; public class FileUtils { @Nonnull - public static String getMD5Three (@Nonnull String path) { + public static String getMD5Three (@Nonnull String path) throws IOException, NoSuchAlgorithmException { final BigInteger bi; - try { - final byte[] buffer = new byte[8192]; - int len; - final MessageDigest md = MessageDigest.getInstance("MD5"); - final FileInputStream fis = new FileInputStream(path); - while ((len = fis.read(buffer)) != -1) { - md.update(buffer, 0, len); - } - fis.close(); - final byte[] b = md.digest(); - bi = new BigInteger(1, b); - } catch (NoSuchAlgorithmException | IOException e) { - e.printStackTrace(System.out); - return e.getMessage(); + final byte[] buffer = new byte[8192]; + int len; + final MessageDigest md = MessageDigest.getInstance("MD5"); + final FileInputStream fis = new FileInputStream(path); + while ((len = fis.read(buffer)) != -1) { + md.update(buffer, 0, len); } + fis.close(); + final byte[] b = md.digest(); + bi = new BigInteger(1, b); return bi.toString(16); }