启动器支持以选项方式为 token 和 username 赋值

This commit is contained in:
A.C.Sukazyo Eyre 2021-12-15 12:43:00 +08:00
parent 12b4c91829
commit ee30b0a0ff
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
4 changed files with 36 additions and 10 deletions

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.4.2.2 VERSION = 0.4.2.3
# 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.4.2.2"; public static final String VERSION = "0.4.2.3";
public static final long COMPILE_TIMESTAMP = 1639541150226L; public static final long COMPILE_TIMESTAMP = 1639543312227L;
} }

View File

@ -35,6 +35,13 @@ public class ServerMain {
* 不要同时使用 {@code --no-hello}原因见下 * 不要同时使用 {@code --no-hello}原因见下
* </li> * </li>
* <li> * <li>
* {@code --token} <b>主程序模式的必选项</b><br>
* 用于 bot 启动的 telegram bot api token
* </li>
* <li>
* {@code --username} {@link MornyCoeur#getUsername() bot username} 预定义
* </li>
* <li>
* {@code --no-hello} 不在主程序启动时输出用于欢迎消息的字符画 * {@code --no-hello} 不在主程序启动时输出用于欢迎消息的字符画
* {@code --only-hello} 参数不兼容 会导致程序完全没有任何输出 * {@code --only-hello} 参数不兼容 会导致程序完全没有任何输出
* </li> * </li>
@ -44,7 +51,13 @@ public class ServerMain {
* </li> * </li>
* </ul> * </ul>
* 除去选项之外第一个参数会被赋值为 bot telegram bot api token * 除去选项之外第一个参数会被赋值为 bot telegram bot api token
* 第二个参数会被赋值为 bot username 限定名其余的参数会被认定为无法理解 * 第二个参数会被赋值为 bot username 限定名其余的参数会被认定为无法理解<br>
* <br>
* <b> {@code 0.4.2.3}token username 的赋值已被选项组支持</b><br>
* 使用参数所进行取值的 token username 已被转移至 {@code --token} {@code --username} 参数
* <u>或许直接参数赋值的支持将计划在 {@code 0.4.3} 标记废弃并在 {@code 0.5} 删除</u>
* <s>但实际上这并不影响现在的使用选项赋值目前仍属于测试功能</s><br>
* <b>但请勿混用</b>这将使两个赋值出现混淆并<b>产生不可知的结果</b>
* *
* @see MornyCoeur#main(String, String, long) * @see MornyCoeur#main(String, String, long)
* @since 0.4.0.0 * @since 0.4.0.0
@ -56,11 +69,11 @@ public class ServerMain {
String username = null; String username = null;
boolean outdatedBlock = false; 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" -> { case "--outdated-block" -> {
outdatedBlock = true; outdatedBlock = true;
continue; continue;
@ -77,22 +90,32 @@ public class ServerMain {
versionEchoMode = true; versionEchoMode = true;
continue; continue;
} }
case "--token" -> {
i++;
key = args[i];
continue;
}
case "--username" -> {
i++;
username = args[i];
continue;
}
} }
} else { } else {
if (key == null) { if (key == null) {
key = arg; key = args[i];
continue; continue;
} }
if (username == null) { if (username == null) {
username = arg; username = args[i];
continue; continue;
} }
} }
logger.warn("Can't understand arg to some meaning :\n " + arg); logger.warn("Can't understand arg to some meaning :\n " + args[i]);
} }

View File

@ -101,6 +101,9 @@ public class OnCallMe extends EventListener {
* <u>known issue</u><ul> * <u>known issue</u><ul>
* <li>无法处理与转发带有媒体的消息</li> * <li>无法处理与转发带有媒体的消息</li>
* </ul> * </ul>
* <br>
* 现在你可以通过这个 bot 来呼叫主人sukazyo任何事情了
* <s>但是直接私聊sukazyo不好吗</s>
* *
* @param event 执行呼叫的tg事件 * @param event 执行呼叫的tg事件
* @since 0.4.2.2 * @since 0.4.2.2