Skip to content

Commit

Permalink
build: version 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Jan 27, 2024
1 parent 65639e1 commit 269df16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
version=0.2.2
version=0.2.3
maven_group=cn.evole.bot
archives_base_name=OneBot-Mirai
authors=cnlimiter
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/evole/onebot/mirai/OneBotMirai.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ else if (event instanceof BotInvitedJoinGroupRequestEvent requestEvent) {

@Override
public void onDisable() {
this.db.save();
db.save();
initialSubscription.complete();
SessionManager.getSessions().forEach((aLong, botSession) -> SessionManager.closeSession(aLong));
logger.info("OneBot Stopped!");
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/cn/evole/onebot/mirai/core/session/BotSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BotSession {
private final OneBotHttpServer httpServer;
private final OneBotWSServer websocketServer;
private final List<OneBotWSClient> websocketClient = new ArrayList<>();
private final MiraiLogger miraiLogger = MiraiLogger.Factory.INSTANCE.create(BotSession.class);
private final MiraiLogger miraiLogger = OneBotMirai.logger;


@Override
Expand All @@ -67,11 +67,11 @@ public BotSession(Bot bot, BotConfig botConfig){


if (this.botConfig.getHttp().getEnable()){
this.miraiLogger.info(String.format("创建正向HTTP服务器: %s: %s", botConfig.getHttp().getHost(), botConfig.getHttp().getPort()));
this.miraiLogger.info(String.format("创建正向HTTP服务器: %s:%s", botConfig.getHttp().getHost(), botConfig.getHttp().getPort()));
this.httpServer.create();
}
if (this.botConfig.getWs().getEnable()){
this.miraiLogger.info(String.format("创建正向WS服务器: %s: %s", botConfig.getWs().getWsHost(), botConfig.getWs().getWsPort()));
this.miraiLogger.info(String.format("创建正向WS服务器: %s:%s", botConfig.getWs().getWsHost(), botConfig.getWs().getWsPort()));
this.websocketServer.create();
}

Expand All @@ -81,7 +81,7 @@ public BotSession(Bot bot, BotConfig botConfig){
this, ws_re
);
client.create();
this.miraiLogger.info(String.format("创建反向WS服务器: %s: %s", ws_re.getReverseHost(), ws_re.getReversePort()));
this.miraiLogger.info(String.format("创建反向WS服务器: %s:%s", ws_re.getReverseHost(), ws_re.getReversePort()));
this.websocketClient.add(client);
}
}
Expand All @@ -93,37 +93,35 @@ public void close() {
this.websocketClient.forEach(OneBotWSClient::close);
}

private final ThreadLocal<Gson> gsonTl = new ThreadLocal<Gson>();
private final ThreadLocal<Gson> gsonTl = ThreadLocal.withInitial(GsonUtils::getGson);
public void triggerEvent(BotEvent event){
var e = EventMap.toDTO(event);
gsonTl.set(GsonUtils.getGson());
var json = gsonTl.get().toJson(e);
if (!(e instanceof IgnoreEvent)) {
var debug = PluginConfig.INSTANCE.getDebug();


if (this.botConfig.getHttp().getEnable()){
if (debug) this.miraiLogger.info("将上报http事件");
if (debug) this.miraiLogger.info("上报HTTP事件");
Properties header = new Properties();
header.putIfAbsent("User-Agent", "OneBotMirai/"+ OneBotMirai.VERSION);
header.putIfAbsent("X-Self-ID", bot.getId());
if (!botConfig.getHttp().getSecret().isEmpty()) header.putIfAbsent("X-Signature", BaseUtils.getSha(json, botConfig.getHttp().getSecret(),"SHA-1", false));
var response = HttpUtils.jsonPost(this.miraiLogger, this.botConfig.getHttp().getPostUrl(), json, header);
if (response != null){
if (debug) this.miraiLogger.info("收到上报响应 %s".formatted(response));
if (debug) this.miraiLogger.info("收到HTTP上报响应 %s".formatted(response));
try {
var respJson = new JsonsObject(response);
var sentJson = new JsonsObject(json);
//todo 快速操作
//var params = hashMapOf("context" to sentJson, "operation" to respJson)
//miraiApi.handleQuickOperation(params)
} catch (Exception e1) {
this.miraiLogger.error("解析HTTP上报返回数据成json失败");
this.miraiLogger.error("解析HTTP上报返回数据失败");
}
}
}

if (this.botConfig.getWs().getEnable()){
if (debug) this.miraiLogger.info("将广播正向websocket事件");
if (debug) this.miraiLogger.info("广播正向websocket事件");
this.websocketServer.broadcast(json);
}

Expand All @@ -135,11 +133,11 @@ public void triggerEvent(BotEvent event){
client.send(json);
}
}catch (Exception ex){
this.miraiLogger.warning("error sending msg", ex);
this.miraiLogger.warning("广播反向websocket事件失败:", ex);
}
return client.isOpen();
}).count();
if (debug) this.miraiLogger.info(String.format("将广播反向websocket事件, 共计发送 :%d", sendCount));
if (debug) this.miraiLogger.info(String.format("广播反向websocket事件, 共发送 :%d", sendCount));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SessionManager{


@Getter
private static final LinkedHashMap<Long, BotSession> sessions = new LinkedHashMap<>();//一个机器人对应一个websocket连接
private static final LinkedHashMap<Long, BotSession> sessions = new LinkedHashMap<>();//一个机器人对应一个session

public static BotSession get(long botId){
return sessions.get(botId);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/evole/onebot/mirai/database/NanoDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @Project: onebot-mirai
* @Author: cnlimiter
* @CreateTime: 2024/1/19 0:44
* @Description:
* @Description: 高性能、微型、伪数据库
*/

@SuppressWarnings({"unused", "BusyWait", "ResultOfMethodCallIgnored"})
Expand Down

0 comments on commit 269df16

Please sign in to comment.