From e8b10d247d10e47c3ccc081bc367ae03433894e0 Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Thu, 3 Feb 2022 19:24:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=86=20key=20=E5=92=8C?= =?UTF-8?q?=20username=20=E7=9A=84=E5=8F=82=E6=95=B0=E7=9B=B4=E8=B5=8B?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=BA=9B=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=B8=8E=E4=BF=9D=E5=AD=98=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 key 和 username 的通过无选项方式的赋值删除,现在它们必须要通过选项来赋值了 - 补充了登录保存的 log - 修复 TrackerData 内不符合规范的调用 - 修复 username 预声明后没有被锁定的bug --- gradle.properties | 2 +- .../cono/morny/GradleProjectConfigures.java | 4 ++-- .../java/cc/sukazyo/cono/morny/MornyCoeur.java | 9 +++++---- .../java/cc/sukazyo/cono/morny/ServerMain.java | 16 ++++------------ .../cono/morny/bot/command/GetUsernameAndId.java | 2 -- .../morny/data/tracker/TrackerDataManager.java | 2 +- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index f185b84..c5986dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.5.0.3 +VERSION = 0.5.0.4 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 00ef497..7686e07 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.5.0.3"; - public static final long COMPILE_TIMESTAMP = 1643617049492L; + public static final String VERSION = "0.5.0.4"; + public static final long COMPILE_TIMESTAMP = 1643885546609L; } diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java index 321b14c..2a7d03c 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java @@ -88,7 +88,7 @@ public class MornyCoeur { } try { - final LogInResult loginResult = login(botKey); + final LogInResult loginResult = login(botKey, botUsername); this.account = loginResult.account; this.username = loginResult.username; this.trusted = new MornyTrusted(master, trustedChat); @@ -158,6 +158,7 @@ public class MornyCoeur { * 用于退出时进行缓存的任务处理等进行安全退出 */ private void exitCleanup () { + logger.info("clean:save tracker data."); TrackerDataManager.DAEMON.interrupt(); TrackerDataManager.trackingLock.lock(); if (isRemoveCommandListWhenExit) { @@ -184,15 +185,15 @@ public class MornyCoeur { * @return 成功登录后的 {@link TelegramBot} 对象 */ @Nonnull - private LogInResult login (@Nonnull String key) { + private static LogInResult login (@Nonnull String key, @Nullable String requireName) { final TelegramBot account = new TelegramBot(key); logger.info("Trying to login..."); for (int i = 1; i < 4; i++) { if (i != 1) logger.info("retrying..."); try { final String username = account.execute(new GetMe()).user().username(); - if (this.username != null && !this.username.equals(username)) - throw new RuntimeException("Required the bot @" + this.username + " but @" + username + " logged in!"); + if (requireName != null && !requireName.equals(username)) + throw new RuntimeException("Required the bot @" + requireName + " but @" + username + " logged in!"); logger.info("Succeed login to @" + username); return new LogInResult(account, username); } catch (Exception e) { diff --git a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java index 09590b9..b7d9d78 100644 --- a/src/main/java/cc/sukazyo/cono/morny/ServerMain.java +++ b/src/main/java/cc/sukazyo/cono/morny/ServerMain.java @@ -130,17 +130,6 @@ public class ServerMain { } } - } else { - - if (key == null) { - key = args[i]; - continue; - } - if (username == null) { - username = args[i]; - continue; - } - } logger.warn("Can't understand arg to some meaning :\n " + args[i]); @@ -170,7 +159,10 @@ public class ServerMain { if (showWelcome) logger.info(MornyHello.MORNY_PREVIEW_IMAGE_ASCII); if (welcomeEchoMode) return; - assert key != null; + if (key == null) { + logger.info("Parameter required has no value:\n --token."); + return; + } MornyCoeur.main( key, username, master, trustedChat, diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java b/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java index c53e746..f7d136f 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/command/GetUsernameAndId.java @@ -13,8 +13,6 @@ import com.pengrad.telegrambot.response.GetChatMemberResponse; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml; - public class GetUsernameAndId implements ITelegramCommand { @Nonnull @Override public String getName () { return "/user"; } diff --git a/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java b/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java index 06945ab..7b2372f 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/tracker/TrackerDataManager.java @@ -43,7 +43,7 @@ public class TrackerDataManager { logger.info("CALLED TO EXIT! writing cache."); } if (record.size() != 0) { - save(reset()); + save(); } else logger.info("nothing to do yet"); } while (!postProcess);