ip186 系列命令支持回复作为参数,添加 /save 命令立即保存,git 添加 .vscode 忽略规则

- gitignore 添加了 .vscode 字段
- /ip 与 /whois 命令支持了回复某条消息,以其消息内容作为参数的查询方式
- 添加 /save 与其对应的 Morny save 指令链,用于手动/统一触发数据持久化储存事件
- 更新了 hack event 的 debug log 文案
- 稍微修改了 Tracker 的保存函数链,用以支持外部触发
This commit is contained in:
A.C.Sukazyo Eyre 2022-01-02 01:04:13 +08:00
parent e808a37fb2
commit 413f734034
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
9 changed files with 77 additions and 19 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# IDE # IDE
.idea/ .idea/
.vscode/
.gradle/ .gradle/
.settings/ .settings/
/src/test/* /src/test/*

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.4.2.11 VERSION = 0.4.3.0
# 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.11"; public static final String VERSION = "0.4.3.0";
public static final long COMPILE_TIMESTAMP = 1640595623685L; public static final long COMPILE_TIMESTAMP = 1641056437585L;
} }

View File

@ -122,6 +122,14 @@ public class MornyCoeur {
logger.error("System already started coeur!!!"); logger.error("System already started coeur!!!");
} }
/**
* 向所有的数据管理器发起保存数据的指令
* @since 0.4.3.0
*/
public void saveDataAll () {
TrackerDataManager.save();
}
/** /**
* 用于退出时进行缓存的任务处理等进行安全退出 * 用于退出时进行缓存的任务处理等进行安全退出
*/ */
@ -167,6 +175,15 @@ public class MornyCoeur {
throw new RuntimeException("Login failed.."); throw new RuntimeException("Login failed..");
} }
/**
* @see #saveDataAll()
* @since 0.4.3.0
*/
public static void callSaveData () {
INSTANCE.saveDataAll();
logger.info("done all save action.");
}
/** /**
* 获取登录成功后的 telegram bot 对象 * 获取登录成功后的 telegram bot 对象
* *

View File

@ -56,6 +56,9 @@ public class OnCommandExecute extends EventListener {
case "/runtime": case "/runtime":
onCommandRuntimeExec(event); onCommandRuntimeExec(event);
break; break;
case "/save":
onSaveDataExec(event);
break;
case "/jrrp": case "/jrrp":
onCommandJrrpExec(event); onCommandJrrpExec(event);
break; break;
@ -200,4 +203,26 @@ public class OnCommandExecute extends EventListener {
).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML)); ).replyToMessageId(event.message().messageId()).parseMode(ParseMode.HTML));
} }
/**
* @since 0.4.3.0
*/
private void onSaveDataExec (Update event) {
if (MornyCoeur.trustedInstance().isTrusted(event.message().from().id())) {
logger.info(String.format("called save from command by @%s.", event.message().from().username()));
MornyCoeur.callSaveData();
MornyCoeur.getAccount().execute(new SendSticker(
event.message().chat().id(),
TelegramStickers.ID_SAVED
).replyToMessageId(event.message().messageId())
);
} else {
MornyCoeur.getAccount().execute(new SendSticker(
event.message().chat().id(),
TelegramStickers.ID_403
).replyToMessageId(event.message().messageId())
);
logger.info("403 call save tag from user @" + event.message().from().username());
}
}
} }

View File

@ -57,7 +57,7 @@ public class OnEventHackHandle extends EventListener {
} }
private boolean onEventHacked (Update update, long chatId, long fromUser) { private boolean onEventHacked (Update update, long chatId, long fromUser) {
logger.debug(String.format("try hack {{%d}}((%d))", chatId, fromUser)); logger.debug(String.format("got event signed {{%d}}((%d))", chatId, fromUser));
Hacker x; Hacker x;
x = hackers.remove(String.format("((%d))", fromUser)); x = hackers.remove(String.format("((%d))", fromUser));
if (x == null) x = hackers.remove(String.format("{{%d}}", chatId)); if (x == null) x = hackers.remove(String.format("{{%d}}", chatId));

View File

@ -20,20 +20,32 @@ public class Ip186Query {
public static void exec (@Nonnull Update event, @Nonnull InputCommand command) { public static void exec (@Nonnull Update event, @Nonnull InputCommand command) {
if (!command.hasArgs()) { MornyCoeur.getAccount().execute(new SendMessage( String arg = null;
event.message().chat().id(), if (!command.hasArgs()) {
"[Unavailable] No ip defined." if (event.message().replyToMessage() != null) {
).replyToMessageId(event.message().messageId())); return; } arg = event.message().replyToMessage().text();
}
if (command.getArgs().length > 1) { MornyCoeur.getAccount().execute(new SendMessage( } else if (command.getArgs().length > 1) {
MornyCoeur.getAccount().execute(new SendMessage(
event.message().chat().id(), event.message().chat().id(),
"[Unavailable] Too much arguments." "[Unavailable] Too much arguments."
).replyToMessageId(event.message().messageId())); return; } ).replyToMessageId(event.message().messageId()));
return;
} else {
arg = command.getArgs()[0];
}
if (arg == null) {
MornyCoeur.getAccount().execute(new SendMessage(
event.message().chat().id(),
"[Unavailable] No ip defined."
).replyToMessageId(event.message().messageId()));
return;
}
try { try {
IP186QueryResponse response = switch (command.getCommand()) { IP186QueryResponse response = switch (command.getCommand()) {
case "/ip" -> IP186QueryHandler.queryIp(command.getArgs()[0]); case "/ip" -> IP186QueryHandler.queryIp(arg);
case "/whois" -> IP186QueryHandler.queryWhois(command.getArgs()[0]); case "/whois" -> IP186QueryHandler.queryWhois(arg);
default -> throw new IllegalArgumentException("Unknown 186-IP query method " + command.getCommand()); default -> throw new IllegalArgumentException("Unknown 186-IP query method " + command.getCommand());
}; };
MornyCoeur.getAccount().execute(new SendMessage( MornyCoeur.getAccount().execute(new SendMessage(

View File

@ -13,5 +13,6 @@ public class TelegramStickers {
public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA"; public static final String ID_404 = "CAACAgEAAx0CSQh32gABA966YbRJpbmi2lCHINBDuo1DknSTsbsAAqUoAAJ4_MYFUa8SIaZriAojBA";
public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA"; public static final String ID_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA";
public static final String ID_SENT = "CAACAgEAAx0CSQh32gABA--zYbiyU_wOijEitp-0tSl_k7W6l3gAAgMmAAJ4_MYF4GrompjXPx4jBA"; public static final String ID_SENT = "CAACAgEAAx0CSQh32gABA--zYbiyU_wOijEitp-0tSl_k7W6l3gAAgMmAAJ4_MYF4GrompjXPx4jBA";
public static final String ID_SAVED = "CAACAgEAAx0CSQh32gABBExuYdB_G0srfhQldRWkBYxWzCOv4-IAApooAAJ4_MYFcjuNZszfQcQjBA";
} }

View File

@ -26,7 +26,6 @@ public class TrackerDataManager {
@Override @Override
public void run () { public void run () {
trackingLock.lock();
long lastWaitTimestamp = System.currentTimeMillis(); long lastWaitTimestamp = System.currentTimeMillis();
boolean postProcess = false; boolean postProcess = false;
do { do {
@ -43,13 +42,10 @@ 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) {
logger.info("start writing tracker data.");
save(reset()); save(reset());
logger.info("done writing tracker data.");
} }
else logger.info("nothing to do yet"); else logger.info("nothing to do yet");
} while (!postProcess); } while (!postProcess);
trackingLock.unlock();
} }
} }
@ -68,6 +64,12 @@ public class TrackerDataManager {
DAEMON.start(); DAEMON.start();
} }
public static void save () {
logger.info("start writing tracker data.");
save(reset());
logger.info("done writing tracker data.");
}
private static HashMap<Long, HashMap<Long, TreeSet<Long>>> reset () { private static HashMap<Long, HashMap<Long, TreeSet<Long>>> reset () {
recordLock.lock(); recordLock.lock();
HashMap<Long, HashMap<Long, TreeSet<Long>>> recordOld = record; HashMap<Long, HashMap<Long, TreeSet<Long>>> recordOld = record;