[[[release 0.6.1.1]]]

## 📇功能

- 为 @Lapis-Apple 也添加 khh 定制功能
- runtime 主机名显示
- runtime/version 信息容错报错
  - 如果主机名显示出错则会是 "<unknown>"
  - core-md5 出错将会显示 "<non-jar-runtime>" 或是 "<calculation-error>" 信息而非报错信息
This commit is contained in:
A.C.Sukazyo Eyre 2022-03-17 13:15:07 +08:00
commit 0d4588d3d2
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
8 changed files with 44 additions and 33 deletions

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.6.0.2 VERSION = 0.6.1.1
# dependencies # dependencies

View File

@ -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.6.0.2"; public static final String VERSION = "0.6.1.1";
public static final long COMPILE_TIMESTAMP = 1647237887029L; public static final long COMPILE_TIMESTAMP = 1647493945844L;
} }

View File

@ -3,7 +3,9 @@ package cc.sukazyo.cono.morny;
import cc.sukazyo.cono.morny.util.FileUtils; import cc.sukazyo.cono.morny.util.FileUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
/** /**
* Morny Cono Coeur 的程序属性存放类 * Morny Cono Coeur 的程序属性存放类
@ -20,20 +22,22 @@ public class MornySystem {
* 获取程序 jar 文件的 md5-hash <br> * 获取程序 jar 文件的 md5-hash <br>
* <br> * <br>
* 只支持 jar 文件方式启动的程序 * 只支持 jar 文件方式启动的程序
* 如果是通过 classpath 来启动则会返回找不到文件的错误数据<br> * 如果是通过 classpath 来启动程序无法找到本体jar文件则会返回 {@code <non-jar-runtime>} 文本
* - 或许需要注意这种情况下会出现程序文件所在的路径<br>
* <br> * <br>
* 值格式为 {@link java.lang.String} * 值格式为 {@link java.lang.String}
* *
* @return 程序jar文件的 md5-hash 值字符串错误信息 * @return 程序jar文件的 md5-hash 值字符串 {@code <non-jar-runtime>} 如果出现错误
*/ */
@Nonnull @Nonnull
public static String getJarMd5() { public static String getJarMd5() {
try { try {
return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
} catch (URISyntaxException e) { } catch (IOException | URISyntaxException e) {
e.printStackTrace(System.out); e.printStackTrace(System.out);
return e.getMessage(); return "<non-jar-runtime>";
} catch (NoSuchAlgorithmException e) {
e.printStackTrace(System.out);
return "<calculation-error>";
} }
} }

View File

@ -18,6 +18,8 @@ import com.pengrad.telegrambot.request.SetMyCommands;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -245,19 +247,26 @@ public class MornyCommands {
* @since 0.4.1.2 * @since 0.4.1.2
*/ */
private static void onCommandRuntimeExec (@Nonnull Update event) { private static void onCommandRuntimeExec (@Nonnull Update event) {
String hostname;
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostname = "<unknown>";
}
MornyCoeur.extra().exec(new SendMessage( MornyCoeur.extra().exec(new SendMessage(
event.message().chat().id(), event.message().chat().id(),
String.format(""" String.format("""
system: system:
- <code>%s</code> - <code>%s</code>
- <code>%s</code> - <code>%s</code>
- <code>%s</code>
- <code>%d</code> cores - <code>%d</code> cores
java runtime: java runtime:
- <code>%s</code> - <code>%s</code>
- <code>%s</code> - <code>%s</code>
vm memory: vm memory:
- <code>%d</code> / <code>%d</code> MB - <code>%d</code> / <code>%d</code> MB
morny version: coeur version:
- <code>%s</code> - <code>%s</code>
- <code>%s</code> - <code>%s</code>
- <code>%s [UTC]</code> - <code>%s [UTC]</code>
@ -268,6 +277,7 @@ public class MornyCommands {
- <code>%s [UTC]</code> - <code>%s [UTC]</code>
- [<code>%d</code>]""", - [<code>%d</code>]""",
// system // system
escapeHtml(hostname),
escapeHtml(System.getProperty("os.name")), escapeHtml(System.getProperty("os.name")),
escapeHtml(System.getProperty("os.version")), escapeHtml(System.getProperty("os.version")),
Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(),

View File

@ -14,11 +14,16 @@ public class OnKuohuanhuanNeedSleep extends EventListener {
@Override @Override
public boolean onMessage (@Nonnull Update update) { public boolean onMessage (@Nonnull Update update) {
final GregorianCalendar time = new GregorianCalendar(Locale.TAIWAN);
time.setTimeInMillis(System.currentTimeMillis());
if ( if (
update.message().from().id() == 786563752L && ( ( update.message().from().id() == 786563752L && (
new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) >= 23 || time.get(Calendar.HOUR_OF_DAY) >= 23 ||
new GregorianCalendar(Locale.TAIWAN).get(Calendar.HOUR_OF_DAY) < 5 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( MornyCoeur.extra().exec(
new DeleteMessage(update.message().chat().id(), new DeleteMessage(update.message().chat().id(),

View File

@ -23,7 +23,7 @@ public class NbnhhshQuery {
public Word[] words; 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/"; 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 @}")));
}
} }

View File

@ -10,9 +10,8 @@ import java.security.NoSuchAlgorithmException;
public class FileUtils { public class FileUtils {
@Nonnull @Nonnull
public static String getMD5Three (@Nonnull String path) { public static String getMD5Three (@Nonnull String path) throws IOException, NoSuchAlgorithmException {
final BigInteger bi; final BigInteger bi;
try {
final byte[] buffer = new byte[8192]; final byte[] buffer = new byte[8192];
int len; int len;
final MessageDigest md = MessageDigest.getInstance("MD5"); final MessageDigest md = MessageDigest.getInstance("MD5");
@ -23,10 +22,6 @@ public class FileUtils {
fis.close(); fis.close();
final byte[] b = md.digest(); final byte[] b = md.digest();
bi = new BigInteger(1, b); bi = new BigInteger(1, b);
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace(System.out);
return e.getMessage();
}
return bi.toString(16); return bi.toString(16);
} }

View File

@ -3,6 +3,7 @@ package cc.sukazyo.cono.morny.util;
import com.pengrad.telegrambot.model.User; import com.pengrad.telegrambot.model.User;
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml; import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
public class TelegramUserInformation { public class TelegramUserInformation {
public static String informationOutputHTML (User user) { public static String informationOutputHTML (User user) {