mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-22 03:04: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
|
## Core
|
||||||
|
|
||||||
VERSION = 0.5.0.3
|
VERSION = 0.5.0.4
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
|
@ -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.5.0.3";
|
public static final String VERSION = "0.5.0.4";
|
||||||
public static final long COMPILE_TIMESTAMP = 1643617049492L;
|
public static final long COMPILE_TIMESTAMP = 1643885546609L;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class MornyCoeur {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final LogInResult loginResult = login(botKey);
|
final LogInResult loginResult = login(botKey, botUsername);
|
||||||
this.account = loginResult.account;
|
this.account = loginResult.account;
|
||||||
this.username = loginResult.username;
|
this.username = loginResult.username;
|
||||||
this.trusted = new MornyTrusted(master, trustedChat);
|
this.trusted = new MornyTrusted(master, trustedChat);
|
||||||
@ -158,6 +158,7 @@ public class MornyCoeur {
|
|||||||
* 用于退出时进行缓存的任务处理等进行安全退出
|
* 用于退出时进行缓存的任务处理等进行安全退出
|
||||||
*/
|
*/
|
||||||
private void exitCleanup () {
|
private void exitCleanup () {
|
||||||
|
logger.info("clean:save tracker data.");
|
||||||
TrackerDataManager.DAEMON.interrupt();
|
TrackerDataManager.DAEMON.interrupt();
|
||||||
TrackerDataManager.trackingLock.lock();
|
TrackerDataManager.trackingLock.lock();
|
||||||
if (isRemoveCommandListWhenExit) {
|
if (isRemoveCommandListWhenExit) {
|
||||||
@ -184,15 +185,15 @@ public class MornyCoeur {
|
|||||||
* @return 成功登录后的 {@link TelegramBot} 对象
|
* @return 成功登录后的 {@link TelegramBot} 对象
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private LogInResult login (@Nonnull String key) {
|
private static LogInResult login (@Nonnull String key, @Nullable String requireName) {
|
||||||
final TelegramBot account = new TelegramBot(key);
|
final TelegramBot account = new TelegramBot(key);
|
||||||
logger.info("Trying to login...");
|
logger.info("Trying to login...");
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < 4; i++) {
|
||||||
if (i != 1) logger.info("retrying...");
|
if (i != 1) logger.info("retrying...");
|
||||||
try {
|
try {
|
||||||
final String username = account.execute(new GetMe()).user().username();
|
final String username = account.execute(new GetMe()).user().username();
|
||||||
if (this.username != null && !this.username.equals(username))
|
if (requireName != null && !requireName.equals(username))
|
||||||
throw new RuntimeException("Required the bot @" + this.username + " but @" + username + " logged in!");
|
throw new RuntimeException("Required the bot @" + requireName + " but @" + username + " logged in!");
|
||||||
logger.info("Succeed login to @" + username);
|
logger.info("Succeed login to @" + username);
|
||||||
return new LogInResult(account, username);
|
return new LogInResult(account, username);
|
||||||
} catch (Exception e) {
|
} 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]);
|
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 (showWelcome) logger.info(MornyHello.MORNY_PREVIEW_IMAGE_ASCII);
|
||||||
if (welcomeEchoMode) return;
|
if (welcomeEchoMode) return;
|
||||||
|
|
||||||
assert key != null;
|
if (key == null) {
|
||||||
|
logger.info("Parameter required has no value:\n --token.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
MornyCoeur.main(
|
MornyCoeur.main(
|
||||||
key, username,
|
key, username,
|
||||||
master, trustedChat,
|
master, trustedChat,
|
||||||
|
@ -13,8 +13,6 @@ import com.pengrad.telegrambot.response.GetChatMemberResponse;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
|
||||||
|
|
||||||
public class GetUsernameAndId implements ITelegramCommand {
|
public class GetUsernameAndId implements ITelegramCommand {
|
||||||
|
|
||||||
@Nonnull @Override public String getName () { return "/user"; }
|
@Nonnull @Override public String getName () { return "/user"; }
|
||||||
|
@ -43,7 +43,7 @@ public class TrackerDataManager {
|
|||||||
logger.info("CALLED TO EXIT! writing cache.");
|
logger.info("CALLED TO EXIT! writing cache.");
|
||||||
}
|
}
|
||||||
if (record.size() != 0) {
|
if (record.size() != 0) {
|
||||||
save(reset());
|
save();
|
||||||
}
|
}
|
||||||
else logger.info("nothing to do yet");
|
else logger.info("nothing to do yet");
|
||||||
} while (!postProcess);
|
} while (!postProcess);
|
||||||
|
Loading…
Reference in New Issue
Block a user