Skip to content

Commit

Permalink
perf: debug logger
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
cnlimiter committed Jan 27, 2024
1 parent 6b6608b commit 65639e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/main/java/cn/evole/onebot/mirai/OneBotMirai.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onEnable() {

CommandManager.INSTANCE.registerCommand(OneBotMiraiCmd.INSTANCE, false);

logger.info("Plugin loaded!");
logger.info("OneBot Loaded!");
logger.info("插件当前版本: " + VERSION);
logger.info("开发交流群: 720975019");

Expand All @@ -75,20 +75,20 @@ public void onEnable() {
List<Bot> instances = Bot.getInstances();
logger.info(String.format("当前存在的机器人数量: %d", instances.size()));
instances.forEach(bot -> {
logger.info(String.format("bot : %d", bot.getId()));
logger.info(String.format("Bot : %s 开始创建", bot.getId()));
if (!SessionManager.getSessions().containsKey(bot.getId())) {
val botId = String.valueOf(bot.getId());
if (Objects.requireNonNull(PluginConfig.INSTANCE.getBots()).containsKey(botId)){
val mapConfig = PluginConfig.INSTANCE.getBots().get(botId);
SessionManager.createBotSession(bot, mapConfig);
logger.info(String.format("创建配置: %d", bot.getId()));
logger.info(String.format("Bot: %s 创建Session", bot.getId()));
}
else {
logger.debug(String.format("%s 未进行OneBot配置,请在setting.yml中进行配置", bot.getId()));
logger.debug(String.format("Bot: %s 未进行OneBot配置,请在setting.yml中进行配置", bot.getId()));
}
}
else {
logger.debug(String.format("%s 已经存在", bot.getId()));
logger.debug(String.format("Bot: %s 已经存在", bot.getId()));
}
});

Expand All @@ -102,11 +102,11 @@ public void onEnable() {
if (Objects.requireNonNull(PluginConfig.INSTANCE.getBots()).containsKey(String.valueOf(event.getBot().getId()))){
val mapConfig = PluginConfig.INSTANCE.getBots().get(botId);
val session = SessionManager.createBotSession(onlineEvent.getBot(), mapConfig);
logger.info(String.format("机器人 %s 创建 OneBot Session", event.getBot().getId()));
logger.info(String.format("Bot: %s 创建Session", event.getBot().getId()));
if (PluginConfig.INSTANCE.getDebug()) logger.info("OneBot Session: " + session);
}
else {
logger.warning(String.format("机器人 %s 未进行OneBot配置,请在setting.yml中进行配置", event.getBot().getId()));
logger.warning(String.format("Bot: %s 未进行OneBot配置,请在setting.yml中进行配置", event.getBot().getId()));
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public void onDisable() {
this.db.save();
initialSubscription.complete();
SessionManager.getSessions().forEach((aLong, botSession) -> SessionManager.closeSession(aLong));
logger.info("OneBot 已关闭");
logger.info("OneBot Stopped!");
}


Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/evole/onebot/mirai/core/EventMap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.evole.onebot.mirai.core;

import cn.evole.onebot.mirai.OneBotMirai;
import cn.evole.onebot.mirai.config.PluginConfig;
import cn.evole.onebot.mirai.model.MiraiClients;
import cn.evole.onebot.mirai.util.TransformUtils;
import cn.evole.onebot.sdk.event.Event;
Expand Down Expand Up @@ -327,7 +328,7 @@ else if (recallEvent instanceof MessageRecallEvent.FriendRecall friendRecall){
return event;
}
else {
logger.info(String.format("发生讨论组消息撤回事件, 已被插件忽略: %s", recallEvent));
if (PluginConfig.INSTANCE.getDebug()) logger.info(String.format("发生讨论组消息撤回事件, 已被插件忽略: %s", recallEvent));
return new IgnoreEvent(recallEvent.getBot().getId());
}
}
Expand Down Expand Up @@ -388,7 +389,7 @@ else if (clientEvent instanceof OtherClientOnlineEvent onlineEvent){
logger.info("即将上传图片");
return new IgnoreEvent(botEvent.getBot().getId());
} else {
logger.info(String.format("发生了被插件忽略的事件: %s", botEvent));
if (PluginConfig.INSTANCE.getDebug()) logger.info(String.format("发生了被插件忽略的事件: %s", botEvent));
return new IgnoreEvent(botEvent.getBot().getId());
}
}
Expand Down

0 comments on commit 65639e1

Please sign in to comment.