@satorijs/adapter-discord 3.8.3 → 3.8.5
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/bot.d.ts +1 -1
- package/lib/index.js +55 -31
- package/lib/index.js.map +2 -2
- package/lib/message.d.ts +1 -0
- package/package.json +2 -2
package/lib/bot.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
|
|
|
11
11
|
webhookLock: Record<string, Promise<Webhook>>;
|
|
12
12
|
commands: Universal.Command[];
|
|
13
13
|
constructor(ctx: Context, config: DiscordBot.Config);
|
|
14
|
-
session(payload?:
|
|
14
|
+
session(payload?: any, input?: any): import("@satorijs/core").Session;
|
|
15
15
|
private _ensureWebhook;
|
|
16
16
|
ensureWebhook(channelId: string): Promise<Discord.Webhook>;
|
|
17
17
|
getSelf(): Promise<Universal.User>;
|
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
var __export = (target, all) => {
|
|
9
10
|
for (var name in all)
|
|
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
27
|
mod
|
|
27
28
|
));
|
|
28
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
29
34
|
|
|
30
35
|
// satori/adapters/discord/src/index.ts
|
|
31
36
|
var src_exports = {};
|
|
@@ -1315,7 +1320,7 @@ function setupReaction(session, data) {
|
|
|
1315
1320
|
}
|
|
1316
1321
|
__name(setupReaction, "setupReaction");
|
|
1317
1322
|
async function adaptSession(bot, input) {
|
|
1318
|
-
const session = bot.session();
|
|
1323
|
+
const session = bot.session({}, input);
|
|
1319
1324
|
if (input.t === "MESSAGE_CREATE") {
|
|
1320
1325
|
if (input.d.webhook_id) {
|
|
1321
1326
|
const webhook = await bot.ensureWebhook(input.d.channel_id);
|
|
@@ -1471,25 +1476,23 @@ var _State = class _State {
|
|
|
1471
1476
|
// forward: send the first message and create a thread
|
|
1472
1477
|
constructor(type) {
|
|
1473
1478
|
this.type = type;
|
|
1474
|
-
this.author = {};
|
|
1475
|
-
this.quote = {};
|
|
1476
|
-
this.channel = {};
|
|
1477
|
-
this.fakeMessageMap = {};
|
|
1478
|
-
// [userInput] = discord messages
|
|
1479
|
-
this.threadCreated = false;
|
|
1480
1479
|
}
|
|
1480
|
+
author = {};
|
|
1481
|
+
quote = {};
|
|
1482
|
+
channel = {};
|
|
1483
|
+
fakeMessageMap = {};
|
|
1484
|
+
// [userInput] = discord messages
|
|
1485
|
+
threadCreated = false;
|
|
1481
1486
|
};
|
|
1482
1487
|
__name(_State, "State");
|
|
1483
1488
|
var State = _State;
|
|
1484
1489
|
var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3.MessageEncoder {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
this.mode = "default";
|
|
1492
|
-
}
|
|
1490
|
+
stack = [new State("message")];
|
|
1491
|
+
buffer = "";
|
|
1492
|
+
addition = {};
|
|
1493
|
+
figure = null;
|
|
1494
|
+
mode = "default";
|
|
1495
|
+
listType = null;
|
|
1493
1496
|
async getUrl() {
|
|
1494
1497
|
var _a, _b, _c, _d;
|
|
1495
1498
|
const input = (_b = (_a = this.options) == null ? void 0 : _a.session) == null ? void 0 : _b.discord;
|
|
@@ -1633,8 +1636,30 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
|
|
|
1633
1636
|
this.buffer += ` (<${attrs.href}>) `;
|
|
1634
1637
|
}
|
|
1635
1638
|
} else if (type === "p") {
|
|
1639
|
+
if (!this.buffer.endsWith("\n"))
|
|
1640
|
+
this.buffer += "\n";
|
|
1636
1641
|
await this.render(children);
|
|
1637
1642
|
this.buffer += "\n";
|
|
1643
|
+
} else if (type === "blockquote") {
|
|
1644
|
+
if (!this.buffer.endsWith("\n"))
|
|
1645
|
+
this.buffer += "\n";
|
|
1646
|
+
this.buffer += "> ";
|
|
1647
|
+
await this.render(children);
|
|
1648
|
+
this.buffer += "\n";
|
|
1649
|
+
} else if (type === "ul" || type === "ol") {
|
|
1650
|
+
this.listType = type;
|
|
1651
|
+
await this.render(children);
|
|
1652
|
+
this.listType = null;
|
|
1653
|
+
} else if (type === "li") {
|
|
1654
|
+
if (!this.buffer.endsWith("\n"))
|
|
1655
|
+
this.buffer += "\n";
|
|
1656
|
+
if (this.listType === "ol") {
|
|
1657
|
+
this.buffer += "0. ";
|
|
1658
|
+
} else if (this.listType === "ul") {
|
|
1659
|
+
this.buffer += "- ";
|
|
1660
|
+
}
|
|
1661
|
+
this.render(children);
|
|
1662
|
+
this.buffer += "\n";
|
|
1638
1663
|
} else if (type === "at") {
|
|
1639
1664
|
if (attrs.id) {
|
|
1640
1665
|
this.buffer += `<@${attrs.id}>`;
|
|
@@ -1778,11 +1803,10 @@ var DiscordMessageEncoder = _DiscordMessageEncoder;
|
|
|
1778
1803
|
var import_satori4 = require("@satorijs/satori");
|
|
1779
1804
|
var logger2 = new import_satori4.Logger("discord");
|
|
1780
1805
|
var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
}
|
|
1806
|
+
_d = 0;
|
|
1807
|
+
_ping;
|
|
1808
|
+
_sessionId = "";
|
|
1809
|
+
_resumeUrl;
|
|
1786
1810
|
async prepare() {
|
|
1787
1811
|
if (this._resumeUrl) {
|
|
1788
1812
|
return this.bot.http.ws(this._resumeUrl + "/?v=10&encoding=json");
|
|
@@ -1847,10 +1871,8 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
1847
1871
|
if (parsed.t === "READY") {
|
|
1848
1872
|
this._sessionId = parsed.d.session_id;
|
|
1849
1873
|
this._resumeUrl = parsed.d.resume_gateway_url;
|
|
1850
|
-
const
|
|
1851
|
-
|
|
1852
|
-
delete self.userId;
|
|
1853
|
-
Object.assign(this.bot, self);
|
|
1874
|
+
const user = decodeUser(parsed.d.user);
|
|
1875
|
+
Object.assign(this.bot, user);
|
|
1854
1876
|
logger2.debug("session_id " + this._sessionId);
|
|
1855
1877
|
return this.bot.online();
|
|
1856
1878
|
}
|
|
@@ -1887,11 +1909,14 @@ var WsClient = _WsClient;
|
|
|
1887
1909
|
var import_package = require("../package.json");
|
|
1888
1910
|
var logger3 = new import_satori5.Logger("discord");
|
|
1889
1911
|
var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
1912
|
+
http;
|
|
1913
|
+
internal;
|
|
1914
|
+
webhooks = {};
|
|
1915
|
+
webhookLock = {};
|
|
1916
|
+
commands = [];
|
|
1890
1917
|
constructor(ctx, config) {
|
|
1891
1918
|
super(ctx, config);
|
|
1892
|
-
this.
|
|
1893
|
-
this.webhookLock = {};
|
|
1894
|
-
this.commands = [];
|
|
1919
|
+
this.platform = "discord";
|
|
1895
1920
|
this.http = ctx.http.extend({
|
|
1896
1921
|
...config,
|
|
1897
1922
|
headers: {
|
|
@@ -1903,8 +1928,8 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
1903
1928
|
this.internal = new Internal(this.http);
|
|
1904
1929
|
ctx.plugin(WsClient, this);
|
|
1905
1930
|
}
|
|
1906
|
-
session(payload
|
|
1907
|
-
return (0, import_satori5.defineProperty)(super.session(), "discord", Object.assign(Object.create(this.internal),
|
|
1931
|
+
session(payload, input) {
|
|
1932
|
+
return (0, import_satori5.defineProperty)(super.session(payload), "discord", Object.assign(Object.create(this.internal), input));
|
|
1908
1933
|
}
|
|
1909
1934
|
async _ensureWebhook(channelId) {
|
|
1910
1935
|
let webhook;
|
|
@@ -2061,7 +2086,7 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
|
|
|
2061
2086
|
}
|
|
2062
2087
|
};
|
|
2063
2088
|
__name(_DiscordBot, "DiscordBot");
|
|
2064
|
-
_DiscordBot
|
|
2089
|
+
__publicField(_DiscordBot, "MessageEncoder", DiscordMessageEncoder);
|
|
2065
2090
|
var DiscordBot = _DiscordBot;
|
|
2066
2091
|
function shapeEqual(a, b, strict = false) {
|
|
2067
2092
|
if (a === b)
|
|
@@ -2094,7 +2119,6 @@ __name(shapeEqual, "shapeEqual");
|
|
|
2094
2119
|
import_satori5.Quester.createConfig("https://discord.com/api/v10")
|
|
2095
2120
|
]);
|
|
2096
2121
|
})(DiscordBot || (DiscordBot = {}));
|
|
2097
|
-
DiscordBot.prototype.platform = "discord";
|
|
2098
2122
|
|
|
2099
2123
|
// satori/adapters/discord/src/index.ts
|
|
2100
2124
|
var src_default = DiscordBot;
|