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
.idea/
.vscode/
.gradle/
.settings/
/src/test/*

View File

@ -1,6 +1,6 @@
## Core
VERSION = 0.4.2.11
VERSION = 0.4.3.0
# dependencies

View File

@ -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.4.2.11";
public static final long COMPILE_TIMESTAMP = 1640595623685L;
public static final String VERSION = "0.4.3.0";
public static final long COMPILE_TIMESTAMP = 1641056437585L;
}

View File

@ -122,6 +122,14 @@ public class MornyCoeur {
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..");
}
/**
* @see #saveDataAll()
* @since 0.4.3.0
*/
public static void callSaveData () {
INSTANCE.saveDataAll();
logger.info("done all save action.");
}
/**
* 获取登录成功后的 telegram bot 对象
*

View File

@ -56,6 +56,9 @@ public class OnCommandExecute extends EventListener {
case "/runtime":
onCommandRuntimeExec(event);
break;
case "/save":
onSaveDataExec(event);
break;
case "/jrrp":
onCommandJrrpExec(event);
break;
@ -200,4 +203,26 @@ public class OnCommandExecute extends EventListener {
).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) {
logger.debug(String.format("try hack {{%d}}((%d))", chatId, fromUser));
logger.debug(String.format("got event signed {{%d}}((%d))", chatId, fromUser));
Hacker x;
x = hackers.remove(String.format("((%d))", fromUser));
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) {
if (!command.hasArgs()) { MornyCoeur.getAccount().execute(new SendMessage(
event.message().chat().id(),
"[Unavailable] No ip defined."
).replyToMessageId(event.message().messageId())); return; }
if (command.getArgs().length > 1) { MornyCoeur.getAccount().execute(new SendMessage(
String arg = null;
if (!command.hasArgs()) {
if (event.message().replyToMessage() != null) {
arg = event.message().replyToMessage().text();
}
} else if (command.getArgs().length > 1) {
MornyCoeur.getAccount().execute(new SendMessage(
event.message().chat().id(),
"[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 {
IP186QueryResponse response = switch (command.getCommand()) {
case "/ip" -> IP186QueryHandler.queryIp(command.getArgs()[0]);
case "/whois" -> IP186QueryHandler.queryWhois(command.getArgs()[0]);
case "/ip" -> IP186QueryHandler.queryIp(arg);
case "/whois" -> IP186QueryHandler.queryWhois(arg);
default -> throw new IllegalArgumentException("Unknown 186-IP query method " + command.getCommand());
};
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_WAITING = "CAACAgEAAx0CSQh32gABA-8DYbh7W2VhJ490ucfZMUMrgMR2FW4AAm4nAAJ4_MYFjx6zpxJPWsQjBA";
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
public void run () {
trackingLock.lock();
long lastWaitTimestamp = System.currentTimeMillis();
boolean postProcess = false;
do {
@ -43,13 +42,10 @@ public class TrackerDataManager {
logger.info("CALLED TO EXIT! writing cache.");
}
if (record.size() != 0) {
logger.info("start writing tracker data.");
save(reset());
logger.info("done writing tracker data.");
}
else logger.info("nothing to do yet");
} while (!postProcess);
trackingLock.unlock();
}
}
@ -68,6 +64,12 @@ public class TrackerDataManager {
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 () {
recordLock.lock();
HashMap<Long, HashMap<Long, TreeSet<Long>>> recordOld = record;