koishi-plugin-cs2-server-query 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +14 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -454,6 +454,18 @@ function apply(ctx, config) {
|
|
|
454
454
|
return `您当前订阅的地图列表:
|
|
455
455
|
${subscriptionList}`;
|
|
456
456
|
});
|
|
457
|
+
async function sendMessageToTarget(ctx2, targetId, pushType, message) {
|
|
458
|
+
try {
|
|
459
|
+
if (pushType === "私聊") {
|
|
460
|
+
await ctx2.bots[0].sendPrivateMessage(targetId, message);
|
|
461
|
+
} else {
|
|
462
|
+
await ctx2.bots[0].sendMessage(targetId, message);
|
|
463
|
+
}
|
|
464
|
+
} catch (err) {
|
|
465
|
+
ctx2.logger("cs2-server-query").error(`发送消息失败: ${err.message}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
__name(sendMessageToTarget, "sendMessageToTarget");
|
|
457
469
|
ctx.setInterval(async () => {
|
|
458
470
|
for (const group of groups) {
|
|
459
471
|
for (const server of group.servers) {
|
|
@@ -464,10 +476,10 @@ ${subscriptionList}`;
|
|
|
464
476
|
server.map = newMap;
|
|
465
477
|
const relevantSubscriptions = subscriptions.filter((sub) => sub.groupName === group.name && (sub.mapName === newMap || sub.mapName === mapTranslations[newMap]?.translation));
|
|
466
478
|
for (const sub of relevantSubscriptions) {
|
|
467
|
-
const message =
|
|
479
|
+
const message = `您订阅的地图已出现,服务器 "${server.name}" 已更换地图为 "${newMap}" (${mapTranslations[newMap]?.translation || "无翻译"}),当前玩家数: ${server.players}/${server.maxPlayers}
|
|
468
480
|
connect ${server.ip}`;
|
|
469
481
|
const targetId = sub.pushType === "私聊" ? sub.userId : sub.channelId;
|
|
470
|
-
await ctx
|
|
482
|
+
await sendMessageToTarget(ctx, targetId, sub.pushType, message);
|
|
471
483
|
}
|
|
472
484
|
}
|
|
473
485
|
} catch (err) {
|