diff --git a/.gitignore b/.gitignore index 037aacb..8520bdf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # IDE .idea/ +.vscode/ .gradle/ .settings/ /src/test/* diff --git a/gradle.properties b/gradle.properties index f697b89..6f25b4a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ ## Core -VERSION = 0.4.2.11 +VERSION = 0.4.3.0 # dependencies diff --git a/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java b/src/main/java/cc/sukazyo/cono/morny/GradleProjectConfigures.java index 4760921..b19b3c0 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.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; } diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java index 06d7944..7f8a239 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java @@ -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 对象 * diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java index a49d884..5b49947 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java @@ -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()); + } + } + } diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java index a4275a4..3f814ff 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnEventHackHandle.java @@ -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)); diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Ip186Query.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Ip186Query.java index 3c73c8a..9128ed1 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Ip186Query.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/on_commands/Ip186Query.java @@ -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( - event.message().chat().id(), - "[Unavailable] Too much arguments." - ).replyToMessageId(event.message().messageId())); return; } + 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; + } 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( diff --git a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java index d478e05..c53024c 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java +++ b/src/main/java/cc/sukazyo/cono/morny/data/TelegramStickers.java @@ -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"; } 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 753944d..aed2c8d 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 @@ -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>> reset () { recordLock.lock(); HashMap>> recordOld = record;