@satorijs/adapter-discord 3.3.0 → 3.3.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/bot.d.ts +8 -8
- package/lib/index.d.ts +1 -1
- package/lib/index.js +17 -16
- package/lib/index.js.map +4 -4
- package/lib/{modulator.d.ts → message.d.ts} +4 -4
- package/package.json +2 -2
- package/lib/sender.d.ts +0 -42
package/lib/bot.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Bot, Context, Quester, Schema
|
|
2
|
-
import {
|
|
1
|
+
import { Bot, Context, Fragment, Quester, Schema } from '@satorijs/satori';
|
|
2
|
+
import { DiscordMessenger } from './message';
|
|
3
3
|
import { Internal } from './types';
|
|
4
4
|
import { WsClient } from './ws';
|
|
5
|
-
export declare class DiscordBot
|
|
5
|
+
export declare class DiscordBot extends Bot<DiscordBot.Config> {
|
|
6
6
|
http: Quester;
|
|
7
7
|
internal: Internal;
|
|
8
|
-
constructor(ctx:
|
|
8
|
+
constructor(ctx: Context, config: DiscordBot.Config);
|
|
9
9
|
getSelf(): Promise<import("@satorijs/core").Universal.User>;
|
|
10
|
-
sendMessage(channelId: string, content:
|
|
11
|
-
sendPrivateMessage(channelId: string, content:
|
|
10
|
+
sendMessage(channelId: string, content: Fragment, guildId?: string): Promise<string[]>;
|
|
11
|
+
sendPrivateMessage(channelId: string, content: Fragment): Promise<string[]>;
|
|
12
12
|
deleteMessage(channelId: string, messageId: string): Promise<void>;
|
|
13
|
-
editMessage(channelId: string, messageId: string, content:
|
|
13
|
+
editMessage(channelId: string, messageId: string, content: Fragment): Promise<void>;
|
|
14
14
|
getMessage(channelId: string, messageId: string): Promise<import("@satorijs/core").Universal.Message>;
|
|
15
15
|
getMessageList(channelId: string, before?: string): Promise<import("@satorijs/core").Universal.Message[]>;
|
|
16
16
|
getUser(userId: string): Promise<import("@satorijs/core").Universal.User>;
|
|
@@ -30,7 +30,7 @@ export declare class DiscordBot<C extends Context = Context> extends Bot<Discord
|
|
|
30
30
|
getChannelList(guildId: string): Promise<import("@satorijs/core").Universal.Channel[]>;
|
|
31
31
|
}
|
|
32
32
|
export declare namespace DiscordBot {
|
|
33
|
-
interface Config extends Bot.Config, Quester.Config,
|
|
33
|
+
interface Config extends Bot.Config, Quester.Config, DiscordMessenger.Config, WsClient.Config {
|
|
34
34
|
token: string;
|
|
35
35
|
}
|
|
36
36
|
const Config: Schema<Config>;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var src_exports = {};
|
|
|
28
28
|
__export(src_exports, {
|
|
29
29
|
Discord: () => types_exports,
|
|
30
30
|
DiscordBot: () => DiscordBot,
|
|
31
|
-
|
|
31
|
+
DiscordMessenger: () => DiscordMessenger,
|
|
32
32
|
WsClient: () => WsClient,
|
|
33
33
|
adaptAuthor: () => adaptAuthor,
|
|
34
34
|
adaptChannel: () => adaptChannel,
|
|
@@ -94,7 +94,9 @@ async function adaptMessage(bot, meta, session = {}) {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
if ((_c = meta.attachments) == null ? void 0 : _c.length) {
|
|
97
|
-
session.content
|
|
97
|
+
if (session.content)
|
|
98
|
+
session.content += " ";
|
|
99
|
+
session.content += meta.attachments.map((v) => {
|
|
98
100
|
var _a2, _b2, _c2;
|
|
99
101
|
if (v.height && v.width && ((_a2 = v.content_type) == null ? void 0 : _a2.startsWith("image/"))) {
|
|
100
102
|
return (0, import_satori.segment)("image", {
|
|
@@ -200,11 +202,11 @@ async function adaptSession(bot, input) {
|
|
|
200
202
|
}
|
|
201
203
|
__name(adaptSession, "adaptSession");
|
|
202
204
|
|
|
203
|
-
// adapters/discord/src/
|
|
205
|
+
// adapters/discord/src/message.ts
|
|
204
206
|
var import_satori2 = require("@satorijs/satori");
|
|
205
207
|
var import_file_type = require("file-type");
|
|
206
208
|
var import_form_data = __toESM(require("form-data"));
|
|
207
|
-
var
|
|
209
|
+
var DiscordMessenger = class extends import_satori2.Messenger {
|
|
208
210
|
constructor() {
|
|
209
211
|
super(...arguments);
|
|
210
212
|
this.buffer = "";
|
|
@@ -376,9 +378,9 @@ var DiscordModulator = class extends import_satori2.Modulator {
|
|
|
376
378
|
}
|
|
377
379
|
}
|
|
378
380
|
};
|
|
379
|
-
__name(
|
|
380
|
-
((
|
|
381
|
-
|
|
381
|
+
__name(DiscordMessenger, "DiscordMessenger");
|
|
382
|
+
((DiscordMessenger2) => {
|
|
383
|
+
DiscordMessenger2.Config = import_satori2.Schema.object({
|
|
382
384
|
handleExternalAsset: import_satori2.Schema.union([
|
|
383
385
|
import_satori2.Schema.const("download").description("先下载后发送"),
|
|
384
386
|
import_satori2.Schema.const("direct").description("直接发送链接"),
|
|
@@ -390,7 +392,7 @@ __name(DiscordModulator, "DiscordModulator");
|
|
|
390
392
|
import_satori2.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
|
|
391
393
|
]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
|
|
392
394
|
}).description("发送设置");
|
|
393
|
-
})(
|
|
395
|
+
})(DiscordMessenger || (DiscordMessenger = {}));
|
|
394
396
|
|
|
395
397
|
// adapters/discord/src/types/index.ts
|
|
396
398
|
var types_exports = {};
|
|
@@ -1519,19 +1521,18 @@ var DiscordBot = class extends import_satori4.Bot {
|
|
|
1519
1521
|
return adaptUser(data);
|
|
1520
1522
|
}
|
|
1521
1523
|
async sendMessage(channelId, content, guildId) {
|
|
1522
|
-
return new
|
|
1524
|
+
return new DiscordMessenger(this, channelId, guildId).send(content);
|
|
1523
1525
|
}
|
|
1524
1526
|
async sendPrivateMessage(channelId, content) {
|
|
1525
|
-
return new
|
|
1527
|
+
return new DiscordMessenger(this, channelId).send(content);
|
|
1526
1528
|
}
|
|
1527
1529
|
async deleteMessage(channelId, messageId) {
|
|
1528
1530
|
await this.internal.deleteMessage(channelId, messageId);
|
|
1529
1531
|
}
|
|
1530
1532
|
async editMessage(channelId, messageId, content) {
|
|
1531
|
-
const
|
|
1532
|
-
content =
|
|
1533
|
-
const
|
|
1534
|
-
const image = chain.find((v) => v.type === "image");
|
|
1533
|
+
const elements = import_satori4.segment.normalize(content);
|
|
1534
|
+
content = elements.toString();
|
|
1535
|
+
const image = elements.find((v) => v.type === "image");
|
|
1535
1536
|
if (image) {
|
|
1536
1537
|
throw new Error("You can't include embed object(s) while editing message.");
|
|
1537
1538
|
}
|
|
@@ -1589,7 +1590,7 @@ __name(DiscordBot, "DiscordBot");
|
|
|
1589
1590
|
token: import_satori4.Schema.string().description("机器人的用户令牌。").role("secret").required()
|
|
1590
1591
|
}),
|
|
1591
1592
|
WsClient.Config,
|
|
1592
|
-
|
|
1593
|
+
DiscordMessenger.Config,
|
|
1593
1594
|
import_satori4.Quester.createConfig("https://discord.com/api/v10")
|
|
1594
1595
|
]);
|
|
1595
1596
|
})(DiscordBot || (DiscordBot = {}));
|
|
@@ -1601,7 +1602,7 @@ var src_default = DiscordBot;
|
|
|
1601
1602
|
0 && (module.exports = {
|
|
1602
1603
|
Discord,
|
|
1603
1604
|
DiscordBot,
|
|
1604
|
-
|
|
1605
|
+
DiscordMessenger,
|
|
1605
1606
|
WsClient,
|
|
1606
1607
|
adaptAuthor,
|
|
1607
1608
|
adaptChannel,
|