mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-21 18:54:54 +08:00
删除了 key 和 username 的参数直赋,修正一些登录与保存的小问题
- 将 key 和 username 的通过无选项方式的赋值删除,现在它们必须要通过选项来赋值了 - 补充了登录保存的 log - 修复 TrackerData 内不符合规范的调用 - 修复 username 预声明后没有被锁定的bug
This commit is contained in:
parent
b77194fef7
commit
e8b10d247d
@ -1,6 +1,6 @@
|
||||
## Core
|
||||
|
||||
VERSION = 0.5.0.3
|
||||
VERSION = 0.5.0.4
|
||||
|
||||
# dependencies
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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"; }
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user