koishi-plugin-adapter-onebot-multi 1.0.2 → 1.0.3
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 +21 -15
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1460,13 +1460,15 @@ var LoadBalancer = class {
|
|
|
1460
1460
|
* 检查群是否应该被管理(根据白名单/黑名单模式)
|
|
1461
1461
|
*/
|
|
1462
1462
|
shouldManageChannel(channelId) {
|
|
1463
|
+
const normalizedChannelId = String(channelId || "").trim();
|
|
1464
|
+
if (!normalizedChannelId) return false;
|
|
1463
1465
|
const mode = this.config.channelFilterMode || "blacklist";
|
|
1464
1466
|
if (mode === "whitelist") {
|
|
1465
1467
|
const whitelist = this.config.channelWhitelist || [];
|
|
1466
|
-
return whitelist.length === 0 || whitelist.includes(
|
|
1468
|
+
return whitelist.length === 0 || whitelist.includes(normalizedChannelId);
|
|
1467
1469
|
} else {
|
|
1468
1470
|
const blacklist = this.config.channelBlacklist || [];
|
|
1469
|
-
return !blacklist.includes(
|
|
1471
|
+
return !blacklist.includes(normalizedChannelId);
|
|
1470
1472
|
}
|
|
1471
1473
|
}
|
|
1472
1474
|
/**
|
|
@@ -1519,14 +1521,16 @@ var LoadBalancer = class {
|
|
|
1519
1521
|
this.listenerDisposers.push(this.ctx.on("guild-added", (session) => {
|
|
1520
1522
|
if (!this.config.enabled) return;
|
|
1521
1523
|
if (session.platform !== "onebot") return;
|
|
1524
|
+
const guildId = String(session.guildId || "").trim();
|
|
1525
|
+
if (!guildId) return;
|
|
1522
1526
|
const botChannelSet = this.botChannels.get(session.selfId) || /* @__PURE__ */ new Set();
|
|
1523
|
-
const isNewChannel = !botChannelSet.has(
|
|
1524
|
-
botChannelSet.add(
|
|
1527
|
+
const isNewChannel = !botChannelSet.has(guildId);
|
|
1528
|
+
botChannelSet.add(guildId);
|
|
1525
1529
|
this.botChannels.set(session.selfId, botChannelSet);
|
|
1526
|
-
const channelBots = this.allChannels.get(
|
|
1530
|
+
const channelBots = this.allChannels.get(guildId) || /* @__PURE__ */ new Set();
|
|
1527
1531
|
channelBots.add(session.selfId);
|
|
1528
|
-
this.allChannels.set(
|
|
1529
|
-
this.logger.info(`Bot ${session.selfId} 加入群 ${
|
|
1532
|
+
this.allChannels.set(guildId, channelBots);
|
|
1533
|
+
this.logger.info(`Bot ${session.selfId} 加入群 ${guildId}`);
|
|
1530
1534
|
if (isNewChannel) {
|
|
1531
1535
|
this.scheduleLoadBalancing(1e4);
|
|
1532
1536
|
}
|
|
@@ -1534,20 +1538,22 @@ var LoadBalancer = class {
|
|
|
1534
1538
|
this.listenerDisposers.push(this.ctx.on("guild-removed", (session) => {
|
|
1535
1539
|
if (!this.config.enabled) return;
|
|
1536
1540
|
if (session.platform !== "onebot") return;
|
|
1541
|
+
const guildId = String(session.guildId || "").trim();
|
|
1542
|
+
if (!guildId) return;
|
|
1537
1543
|
const botChannelSet = this.botChannels.get(session.selfId);
|
|
1538
1544
|
if (botChannelSet) {
|
|
1539
|
-
botChannelSet.delete(
|
|
1545
|
+
botChannelSet.delete(guildId);
|
|
1540
1546
|
}
|
|
1541
|
-
const channelBots = this.allChannels.get(
|
|
1547
|
+
const channelBots = this.allChannels.get(guildId);
|
|
1542
1548
|
const hadOtherBots = channelBots && channelBots.size > 1;
|
|
1543
1549
|
if (channelBots) {
|
|
1544
1550
|
channelBots.delete(session.selfId);
|
|
1545
1551
|
if (channelBots.size === 0) {
|
|
1546
|
-
this.allChannels.delete(
|
|
1547
|
-
this.lastAssignees.delete(
|
|
1552
|
+
this.allChannels.delete(guildId);
|
|
1553
|
+
this.lastAssignees.delete(guildId);
|
|
1548
1554
|
}
|
|
1549
1555
|
}
|
|
1550
|
-
this.logger.info(`Bot ${session.selfId} 退出群 ${
|
|
1556
|
+
this.logger.info(`Bot ${session.selfId} 退出群 ${guildId}`);
|
|
1551
1557
|
if (hadOtherBots) {
|
|
1552
1558
|
this.scheduleLoadBalancing(5e3);
|
|
1553
1559
|
}
|
|
@@ -1591,7 +1597,7 @@ var LoadBalancer = class {
|
|
|
1591
1597
|
}
|
|
1592
1598
|
const guilds = await bot.getGuildList();
|
|
1593
1599
|
const channelIds = new Set(
|
|
1594
|
-
Array.from(guilds.data || []).map((g) => g
|
|
1600
|
+
Array.from(guilds.data || []).map((g) => String(g?.id || "").trim()).filter(Boolean)
|
|
1595
1601
|
);
|
|
1596
1602
|
this.botChannels.set(bot.selfId, channelIds);
|
|
1597
1603
|
for (const channelId of channelIds) {
|
|
@@ -1642,7 +1648,7 @@ var LoadBalancer = class {
|
|
|
1642
1648
|
return;
|
|
1643
1649
|
}
|
|
1644
1650
|
const channels = [];
|
|
1645
|
-
const prioritySet = new Set(this.config.priorityChannels || []);
|
|
1651
|
+
const prioritySet = new Set((this.config.priorityChannels || []).map((id) => String(id).trim()).filter(Boolean));
|
|
1646
1652
|
for (const [channelId, bots] of this.allChannels.entries()) {
|
|
1647
1653
|
channels.push({
|
|
1648
1654
|
channelId,
|
|
@@ -1800,7 +1806,7 @@ var LoadBalancer = class {
|
|
|
1800
1806
|
if (!this.config.enabled) return true;
|
|
1801
1807
|
if (session.platform !== "onebot") return true;
|
|
1802
1808
|
if (session.type !== "message") return true;
|
|
1803
|
-
const channelId = session.guildId || session.channelId;
|
|
1809
|
+
const channelId = String(session.guildId || session.channelId || "").trim();
|
|
1804
1810
|
if (!channelId) return true;
|
|
1805
1811
|
if (!this.shouldManageChannel(channelId)) return true;
|
|
1806
1812
|
const assignee = this.lastAssignees.get(channelId);
|