@satorijs/adapter-discord 4.1.0 → 4.1.1
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 -12
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -100,6 +100,7 @@ var import_satori2 = require("@satorijs/satori");
|
|
|
100
100
|
|
|
101
101
|
// satori/adapters/discord/src/types/internal.ts
|
|
102
102
|
var import_satori = require("@satorijs/satori");
|
|
103
|
+
var logger = new import_satori.Logger("discord");
|
|
103
104
|
var _Internal = class _Internal {
|
|
104
105
|
constructor(http) {
|
|
105
106
|
this.http = http;
|
|
@@ -130,6 +131,7 @@ var _Internal = class _Internal {
|
|
|
130
131
|
throw new Error(`too many arguments for ${path}, received ${raw}`);
|
|
131
132
|
}
|
|
132
133
|
try {
|
|
134
|
+
logger.debug(`${method} ${url}`, config);
|
|
133
135
|
return await this.http(method, url, config);
|
|
134
136
|
} catch (error) {
|
|
135
137
|
if (!import_satori.Quester.isAxiosError(error) || !error.response)
|
|
@@ -1536,7 +1538,7 @@ __name(encodeCommandOptions, "encodeCommandOptions");
|
|
|
1536
1538
|
// satori/adapters/discord/src/message.ts
|
|
1537
1539
|
var import_satori3 = require("@satorijs/satori");
|
|
1538
1540
|
var import_form_data = __toESM(require("form-data"));
|
|
1539
|
-
var
|
|
1541
|
+
var logger2 = new import_satori3.Logger("discord");
|
|
1540
1542
|
var _State = class _State {
|
|
1541
1543
|
// forward: send the first message and create a thread
|
|
1542
1544
|
constructor(type) {
|
|
@@ -1606,7 +1608,7 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
|
|
|
1606
1608
|
} catch (e) {
|
|
1607
1609
|
if (import_satori3.Quester.isAxiosError(e) && e.response) {
|
|
1608
1610
|
if (((_a = e.response.data) == null ? void 0 : _a.code) === 10015) {
|
|
1609
|
-
|
|
1611
|
+
logger2.debug("webhook has been deleted, recreating..., %o", e.response.data);
|
|
1610
1612
|
if (!this.bot.webhookLock[this.channelId])
|
|
1611
1613
|
this.bot.webhooks[this.channelId] = null;
|
|
1612
1614
|
await this.ensureWebhook();
|
|
@@ -1930,7 +1932,7 @@ var DiscordMessageEncoder = _DiscordMessageEncoder;
|
|
|
1930
1932
|
|
|
1931
1933
|
// satori/adapters/discord/src/ws.ts
|
|
1932
1934
|
var import_satori4 = require("@satorijs/satori");
|
|
1933
|
-
var
|
|
1935
|
+
var logger3 = new import_satori4.Logger("discord");
|
|
1934
1936
|
var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
1935
1937
|
_d = 0;
|
|
1936
1938
|
_ping;
|
|
@@ -1944,7 +1946,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
1944
1946
|
return this.bot.http.ws(url + "/?v=10&encoding=json");
|
|
1945
1947
|
}
|
|
1946
1948
|
heartbeat() {
|
|
1947
|
-
|
|
1949
|
+
logger3.debug(`heartbeat d ${this._d}`);
|
|
1948
1950
|
this.socket.send(JSON.stringify({
|
|
1949
1951
|
op: Gateway.Opcode.HEARTBEAT,
|
|
1950
1952
|
d: this._d
|
|
@@ -1957,16 +1959,16 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
1957
1959
|
try {
|
|
1958
1960
|
parsed = JSON.parse(data.toString());
|
|
1959
1961
|
} catch (error) {
|
|
1960
|
-
return
|
|
1962
|
+
return logger3.warn("cannot parse message", data);
|
|
1961
1963
|
}
|
|
1962
|
-
|
|
1964
|
+
logger3.debug(require("util").inspect(parsed, false, null, true));
|
|
1963
1965
|
if (parsed.s) {
|
|
1964
1966
|
this._d = parsed.s;
|
|
1965
1967
|
}
|
|
1966
1968
|
if (parsed.op === Gateway.Opcode.HELLO) {
|
|
1967
1969
|
this._ping = setInterval(() => this.heartbeat(), parsed.d.heartbeat_interval);
|
|
1968
1970
|
if (this._sessionId) {
|
|
1969
|
-
|
|
1971
|
+
logger3.debug("resuming");
|
|
1970
1972
|
this.socket.send(JSON.stringify({
|
|
1971
1973
|
op: Gateway.Opcode.RESUME,
|
|
1972
1974
|
d: {
|
|
@@ -1991,7 +1993,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
1991
1993
|
if (parsed.d)
|
|
1992
1994
|
return;
|
|
1993
1995
|
this._sessionId = "";
|
|
1994
|
-
|
|
1996
|
+
logger3.warn("offline: invalid session");
|
|
1995
1997
|
(_a = this.socket) == null ? void 0 : _a.close();
|
|
1996
1998
|
}
|
|
1997
1999
|
if (parsed.op === Gateway.Opcode.DISPATCH) {
|
|
@@ -2004,7 +2006,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
2004
2006
|
this._sessionId = parsed.d.session_id;
|
|
2005
2007
|
this._resumeUrl = parsed.d.resume_gateway_url;
|
|
2006
2008
|
this.bot.user = decodeUser(parsed.d.user);
|
|
2007
|
-
|
|
2009
|
+
logger3.debug("session_id " + this._sessionId);
|
|
2008
2010
|
return this.bot.online();
|
|
2009
2011
|
}
|
|
2010
2012
|
if (parsed.t === "RESUMED") {
|
|
@@ -2015,7 +2017,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
2015
2017
|
this.bot.dispatch(session);
|
|
2016
2018
|
}
|
|
2017
2019
|
if (parsed.op === Gateway.Opcode.RECONNECT) {
|
|
2018
|
-
|
|
2020
|
+
logger3.warn("offline: discord request reconnect");
|
|
2019
2021
|
(_b = this.socket) == null ? void 0 : _b.close();
|
|
2020
2022
|
}
|
|
2021
2023
|
});
|
|
@@ -2037,7 +2039,7 @@ var WsClient = _WsClient;
|
|
|
2037
2039
|
|
|
2038
2040
|
// satori/adapters/discord/src/bot.ts
|
|
2039
2041
|
var import_package = require("../package.json");
|
|
2040
|
-
var
|
|
2042
|
+
var logger4 = new import_satori5.Logger("discord");
|
|
2041
2043
|
var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
2042
2044
|
http;
|
|
2043
2045
|
internal;
|
|
@@ -2199,7 +2201,7 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2199
2201
|
this.commands = commands;
|
|
2200
2202
|
const updates = commands.map(encodeCommand);
|
|
2201
2203
|
if (updates.length) {
|
|
2202
|
-
|
|
2204
|
+
logger4.debug("update %d command(s)", updates.length);
|
|
2203
2205
|
await this.internal.bulkOverwriteGlobalApplicationCommands(this.selfId, updates);
|
|
2204
2206
|
}
|
|
2205
2207
|
}
|