@satorijs/adapter-discord 3.4.3 → 3.5.0
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 +43 -25
- package/lib/index.js.map +2 -2
- package/lib/types/application.d.ts +2 -0
- package/lib/types/gateway.d.ts +11 -2
- package/lib/ws.d.ts +1 -2
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1493,8 +1493,12 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
|
|
|
1493
1493
|
this._d = 0;
|
|
1494
1494
|
this._sessionId = "";
|
|
1495
1495
|
}
|
|
1496
|
-
prepare() {
|
|
1497
|
-
|
|
1496
|
+
async prepare() {
|
|
1497
|
+
if (this._resumeUrl) {
|
|
1498
|
+
return this.bot.http.ws(this._resumeUrl);
|
|
1499
|
+
}
|
|
1500
|
+
const { url } = await this.bot.internal.getGatewayBot();
|
|
1501
|
+
return this.bot.http.ws(url);
|
|
1498
1502
|
}
|
|
1499
1503
|
heartbeat() {
|
|
1500
1504
|
logger.debug(`heartbeat d ${this._d}`);
|
|
@@ -1504,19 +1508,8 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
|
|
|
1504
1508
|
}));
|
|
1505
1509
|
}
|
|
1506
1510
|
accept() {
|
|
1507
|
-
if (this._sessionId) {
|
|
1508
|
-
logger.debug("resuming");
|
|
1509
|
-
this.bot.socket.send(JSON.stringify({
|
|
1510
|
-
op: 6 /* RESUME */,
|
|
1511
|
-
d: {
|
|
1512
|
-
token: this.bot.config.token,
|
|
1513
|
-
session_id: this._sessionId,
|
|
1514
|
-
seq: this._d
|
|
1515
|
-
}
|
|
1516
|
-
}));
|
|
1517
|
-
this.bot.online();
|
|
1518
|
-
}
|
|
1519
1511
|
this.bot.socket.on("message", async (data) => {
|
|
1512
|
+
var _a, _b;
|
|
1520
1513
|
let parsed;
|
|
1521
1514
|
try {
|
|
1522
1515
|
parsed = JSON.parse(data.toString());
|
|
@@ -1529,17 +1522,35 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
|
|
|
1529
1522
|
}
|
|
1530
1523
|
if (parsed.op === 10 /* HELLO */) {
|
|
1531
1524
|
this._ping = setInterval(() => this.heartbeat(), parsed.d.heartbeat_interval);
|
|
1532
|
-
if (this._sessionId)
|
|
1525
|
+
if (this._sessionId) {
|
|
1526
|
+
logger.debug("resuming");
|
|
1527
|
+
this.bot.socket.send(JSON.stringify({
|
|
1528
|
+
op: 6 /* RESUME */,
|
|
1529
|
+
d: {
|
|
1530
|
+
token: this.bot.config.token,
|
|
1531
|
+
session_id: this._sessionId,
|
|
1532
|
+
seq: this._d
|
|
1533
|
+
}
|
|
1534
|
+
}));
|
|
1535
|
+
} else {
|
|
1536
|
+
this.bot.socket.send(JSON.stringify({
|
|
1537
|
+
op: 2 /* IDENTIFY */,
|
|
1538
|
+
d: {
|
|
1539
|
+
token: this.bot.config.token,
|
|
1540
|
+
properties: {},
|
|
1541
|
+
compress: false,
|
|
1542
|
+
intents: this.bot.config.intents
|
|
1543
|
+
}
|
|
1544
|
+
}));
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (parsed.op === 9 /* INVALID_SESSION */) {
|
|
1548
|
+
if (parsed.d)
|
|
1533
1549
|
return;
|
|
1534
|
-
this.
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
properties: {},
|
|
1539
|
-
compress: false,
|
|
1540
|
-
intents: this.bot.config.intents
|
|
1541
|
-
}
|
|
1542
|
-
}));
|
|
1550
|
+
this._sessionId = "";
|
|
1551
|
+
logger.warn("offline: invalid session");
|
|
1552
|
+
this.bot.offline();
|
|
1553
|
+
(_a = this.bot.socket) == null ? void 0 : _a.close();
|
|
1543
1554
|
}
|
|
1544
1555
|
if (parsed.op === 0 /* DISPATCH */) {
|
|
1545
1556
|
if (parsed.t === "READY") {
|
|
@@ -1552,10 +1563,18 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
|
|
|
1552
1563
|
logger.debug("session_id " + this._sessionId);
|
|
1553
1564
|
return this.bot.online();
|
|
1554
1565
|
}
|
|
1566
|
+
if (parsed.t === "RESUMED") {
|
|
1567
|
+
return this.bot.online();
|
|
1568
|
+
}
|
|
1555
1569
|
const session = await adaptSession(this.bot, parsed);
|
|
1556
1570
|
if (session)
|
|
1557
1571
|
this.bot.dispatch(session);
|
|
1558
1572
|
}
|
|
1573
|
+
if (parsed.op === 7 /* RECONNECT */) {
|
|
1574
|
+
this.bot.offline();
|
|
1575
|
+
logger.warn("offline: discord request reconnect");
|
|
1576
|
+
(_b = this.bot.socket) == null ? void 0 : _b.close();
|
|
1577
|
+
}
|
|
1559
1578
|
});
|
|
1560
1579
|
this.bot.socket.on("close", () => {
|
|
1561
1580
|
clearInterval(this._ping);
|
|
@@ -1566,7 +1585,6 @@ __name(WsClient, "WsClient");
|
|
|
1566
1585
|
((WsClient2) => {
|
|
1567
1586
|
WsClient2.Config = import_satori3.Schema.intersect([
|
|
1568
1587
|
import_satori3.Schema.object({
|
|
1569
|
-
gateway: import_satori3.Schema.string().default("wss://gateway.discord.gg/?v=10&encoding=json").description("要连接的 WebSocket 网关。"),
|
|
1570
1588
|
intents: import_satori3.Schema.bitset(GatewayIntent).description("需要订阅的机器人事件。").default(0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */ | 32768 /* MESSAGE_CONTENT */)
|
|
1571
1589
|
}).description("推送设置"),
|
|
1572
1590
|
import_satori3.Adapter.WsClient.Config
|