From ee30b0a0fffa1809e90a1a14cc2d06043586d99e Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Wed, 15 Dec 2021 12:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=99=A8=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=A5=E9=80=89=E9=A1=B9=E6=96=B9=E5=BC=8F=E4=B8=BA=20token?= =?UTF-8?q?=20=E5=92=8C=20username=20=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 +- .../cc/sukazyo/cono/morny/ServerMain.java | 37 +++++++++++++++---- .../cono/morny/bot/event/OnCallMe.java | 3 ++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index 5a63cde..50cbf59 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.4.2.2 +VERSION = 0.4.2.3 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 53e4adc..8a50a22 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.2.2"; - public static final long COMPILE_TIMESTAMP = 1639541150226L; + public static final String VERSION = "0.4.2.3"; + public static final long COMPILE_TIMESTAMP = 1639543312227L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java index 89147c3..78f1702 100644 --- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java +++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java @@ -35,6 +35,13 @@ public class ServerMain { * 不要同时使用 {@code --no-hello},原因见下。 * *
  • + * {@code --token} 主程序模式的必选项
    + * 用于 bot 启动的 telegram bot api token + *
  • + *
  • + * {@code --username} {@link MornyCoeur#getUsername() bot 的 username} 预定义 + *
  • + *
  • * {@code --no-hello} 不在主程序启动时输出用于欢迎消息的字符画。 * 与 {@code --only-hello} 参数不兼容 —— 会导致程序完全没有任何输出 *
  • @@ -44,7 +51,13 @@ public class ServerMain { * * * 除去选项之外,第一个参数会被赋值为 bot 的 telegram bot api token, - * 第二个参数会被赋值为 bot 的 username 限定名。其余的参数会被认定为无法理解。 + * 第二个参数会被赋值为 bot 的 username 限定名。其余的参数会被认定为无法理解。
    + *
    + * 自 {@code 0.4.2.3},token 和 username 的赋值已被选项组支持
    + * 使用参数所进行取值的 token 和 username 已被转移至 {@code --token} 和 {@code --username} 参数, + * 或许,直接参数赋值的支持将计划在 {@code 0.4.3} 标记废弃并在 {@code 0.5} 删除。 + * 但实际上这并不影响现在的使用,选项赋值目前仍属于测试功能
    + * 但请勿混用,这将使两个赋值出现混淆并产生不可知的结果 * * @see MornyCoeur#main(String, String, long) * @since 0.4.0.0 @@ -56,11 +69,11 @@ public class ServerMain { String username = null; boolean outdatedBlock = false; - for (String arg : args) { + for (int i = 0; i < args.length; i++) { - if (arg.startsWith("-")) { + if (args[i].startsWith("-")) { - switch (arg) { + switch (args[i]) { case "--outdated-block" -> { outdatedBlock = true; continue; @@ -77,22 +90,32 @@ public class ServerMain { versionEchoMode = true; continue; } + case "--token" -> { + i++; + key = args[i]; + continue; + } + case "--username" -> { + i++; + username = args[i]; + continue; + } } } else { if (key == null) { - key = arg; + key = args[i]; continue; } if (username == null) { - username = arg; + username = args[i]; continue; } } - logger.warn("Can't understand arg to some meaning :\n " + arg); + logger.warn("Can't understand arg to some meaning :\n " + args[i]); } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java index 608c73b..c1c14e0 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCallMe.java @@ -101,6 +101,9 @@ public class OnCallMe extends EventListener { * known issue + *
    + * 现在你可以通过这个 bot 来呼叫主人(sukazyo)任何事情了 —— + * 但是直接私聊sukazyo不好吗 * * @param event 执行呼叫的tg事件 * @since 0.4.2.2