@onebots/adapter-discord 1.0.0 → 1.0.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/adapter.js +17 -14
- package/lib/index.js +16 -0
- package/package.json +10 -7
package/lib/adapter.js
CHANGED
|
@@ -23,9 +23,10 @@ export class DiscordAdapter extends Adapter {
|
|
|
23
23
|
if (!account)
|
|
24
24
|
throw new Error(`Account ${uin} not found`);
|
|
25
25
|
const bot = account.client;
|
|
26
|
-
const {
|
|
26
|
+
const { scene_type, message } = params;
|
|
27
|
+
const sceneId = this.coerceId(params.scene_id);
|
|
27
28
|
let messageId;
|
|
28
|
-
const channelId =
|
|
29
|
+
const channelId = sceneId.string;
|
|
29
30
|
// 构建消息内容
|
|
30
31
|
const { content, embeds } = this.buildDiscordMessage(message);
|
|
31
32
|
try {
|
|
@@ -59,8 +60,8 @@ export class DiscordAdapter extends Adapter {
|
|
|
59
60
|
if (!account)
|
|
60
61
|
throw new Error(`Account ${uin} not found`);
|
|
61
62
|
const bot = account.client;
|
|
62
|
-
const messageId = params.message_id.string;
|
|
63
|
-
const channelId = params.scene_id
|
|
63
|
+
const messageId = this.coerceId(params.message_id).string;
|
|
64
|
+
const channelId = params.scene_id != null ? this.coerceId(params.scene_id).string : '';
|
|
64
65
|
if (!channelId) {
|
|
65
66
|
throw new Error('删除消息需要提供 scene_id (频道ID)');
|
|
66
67
|
}
|
|
@@ -74,8 +75,8 @@ export class DiscordAdapter extends Adapter {
|
|
|
74
75
|
if (!account)
|
|
75
76
|
throw new Error(`Account ${uin} not found`);
|
|
76
77
|
const bot = account.client;
|
|
77
|
-
const messageId = params.message_id.string;
|
|
78
|
-
const channelId = params.scene_id
|
|
78
|
+
const messageId = this.coerceId(params.message_id).string;
|
|
79
|
+
const channelId = params.scene_id != null ? this.coerceId(params.scene_id).string : '';
|
|
79
80
|
if (!channelId) {
|
|
80
81
|
throw new Error('获取消息需要提供 scene_id (频道ID)');
|
|
81
82
|
}
|
|
@@ -90,7 +91,7 @@ export class DiscordAdapter extends Adapter {
|
|
|
90
91
|
if (!account)
|
|
91
92
|
throw new Error(`Account ${uin} not found`);
|
|
92
93
|
const bot = account.client;
|
|
93
|
-
const channelId = params.scene_id.string;
|
|
94
|
+
const channelId = this.coerceId(params.scene_id).string;
|
|
94
95
|
const limit = params.limit || 50;
|
|
95
96
|
const messages = await bot.getMessageHistory(channelId, limit);
|
|
96
97
|
return [...messages.values()].map(msg => this.convertMessageToInfo(msg));
|
|
@@ -286,8 +287,8 @@ export class DiscordAdapter extends Adapter {
|
|
|
286
287
|
if (!account)
|
|
287
288
|
throw new Error(`Account ${uin} not found`);
|
|
288
289
|
const bot = account.client;
|
|
289
|
-
const guildId = params.group_id.string;
|
|
290
|
-
const userId = params.user_id.string;
|
|
290
|
+
const guildId = this.coerceId(params.group_id).string;
|
|
291
|
+
const userId = this.coerceId(params.user_id).string;
|
|
291
292
|
await bot.setMemberNickname(guildId, userId, params.card || null);
|
|
292
293
|
}
|
|
293
294
|
/**
|
|
@@ -298,8 +299,8 @@ export class DiscordAdapter extends Adapter {
|
|
|
298
299
|
if (!account)
|
|
299
300
|
throw new Error(`Account ${uin} not found`);
|
|
300
301
|
const bot = account.client;
|
|
301
|
-
const channelId = params.group_id.string;
|
|
302
|
-
const messageId = params.message_id.string;
|
|
302
|
+
const channelId = this.coerceId(params.group_id).string;
|
|
303
|
+
const messageId = this.coerceId(params.message_id).string;
|
|
303
304
|
// Discord 使用 Unicode emoji 或自定义 emoji 格式
|
|
304
305
|
const emoji = String.fromCodePoint(params.face_id);
|
|
305
306
|
await bot.addReaction(channelId, messageId, emoji);
|
|
@@ -679,10 +680,12 @@ export class DiscordAdapter extends Adapter {
|
|
|
679
680
|
}
|
|
680
681
|
else {
|
|
681
682
|
messageType = 'channel';
|
|
682
|
-
|
|
683
|
+
// 使用 channel.id 作为 group.id,以便 OneBot send_group_msg 时 scene_id 为频道 ID(Discord 发消息必须用 channel_id,用 guild_id 会 404 Unknown Channel)
|
|
684
|
+
if (message.channel) {
|
|
685
|
+
const ch = message.channel;
|
|
683
686
|
group = {
|
|
684
|
-
id: this.createId(
|
|
685
|
-
name: message.guild
|
|
687
|
+
id: this.createId(ch.id),
|
|
688
|
+
name: ch.name || message.guild?.name || '',
|
|
686
689
|
};
|
|
687
690
|
}
|
|
688
691
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AdapterRegistry } from 'onebots';
|
|
1
2
|
export { ChannelType, MessageType, ActivityType } from './types.js';
|
|
2
3
|
// 导出适配器
|
|
3
4
|
export * from './adapter.js';
|
|
@@ -5,4 +6,19 @@ export * from './adapter.js';
|
|
|
5
6
|
export { DiscordBot } from './bot.js';
|
|
6
7
|
// 导出轻量版客户端(用于独立使用或 Serverless)
|
|
7
8
|
export * from './lite/index.js';
|
|
9
|
+
const discordSchema = {
|
|
10
|
+
account_id: { type: 'string', required: true, label: '账号标识' },
|
|
11
|
+
token: { type: 'string', required: true, label: 'Bot Token' },
|
|
12
|
+
proxy: {
|
|
13
|
+
url: { type: 'string', label: '代理地址' },
|
|
14
|
+
username: { type: 'string', label: '代理用户名' },
|
|
15
|
+
password: { type: 'string', label: '代理密码' },
|
|
16
|
+
},
|
|
17
|
+
intents: { type: 'array', label: 'Gateway Intents' },
|
|
18
|
+
presence: {
|
|
19
|
+
status: { type: 'string', enum: ['online', 'idle', 'dnd', 'invisible'], label: '状态' },
|
|
20
|
+
activities: { type: 'array', label: '活动列表' },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
AdapterRegistry.registerSchema('discord', discordSchema);
|
|
8
24
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onebots/adapter-discord",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "onebots Discord 适配器(轻量版,支持 Node.js 和 Cloudflare Workers)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"/lib/**/*.d.ts"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.7.3",
|
|
37
38
|
"tsc-alias": "latest",
|
|
38
|
-
"typescript": "latest"
|
|
39
|
-
"@types/node": "^22.7.3"
|
|
39
|
+
"typescript": "latest"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"onebots": "1.0.
|
|
42
|
+
"onebots": "1.0.5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"ws": {
|
|
@@ -52,11 +52,14 @@
|
|
|
52
52
|
"optional": true
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
"dependencies": {},
|
|
56
55
|
"optionalDependencies": {
|
|
57
|
-
"ws": "^8.18.0",
|
|
58
56
|
"https-proxy-agent": "^7.0.6",
|
|
59
|
-
"socks-proxy-agent": "^8.0.5"
|
|
57
|
+
"socks-proxy-agent": "^8.0.5",
|
|
58
|
+
"ws": "^8.18.0"
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/lc-cn/onebots.git"
|
|
60
63
|
},
|
|
61
64
|
"scripts": {
|
|
62
65
|
"build": "rm -f *.tsbuildinfo && tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|