@onebots/adapter-discord 1.0.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/LICENSE +21 -0
- package/README.md +202 -0
- package/lib/adapter.d.ts +175 -0
- package/lib/adapter.js +897 -0
- package/lib/bot.d.ts +293 -0
- package/lib/bot.js +526 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +8 -0
- package/lib/lite/bot.d.ts +305 -0
- package/lib/lite/bot.js +527 -0
- package/lib/lite/gateway.d.ts +119 -0
- package/lib/lite/gateway.js +349 -0
- package/lib/lite/index.d.ts +148 -0
- package/lib/lite/index.js +244 -0
- package/lib/lite/interactions.d.ts +134 -0
- package/lib/lite/interactions.js +238 -0
- package/lib/lite/rest.d.ts +102 -0
- package/lib/lite/rest.js +292 -0
- package/lib/types.d.ts +106 -0
- package/lib/types.js +64 -0
- package/package.json +65 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord REST API 轻量封装
|
|
3
|
+
* Node.js 使用原生 https 模块,Cloudflare Workers 使用 fetch
|
|
4
|
+
*/
|
|
5
|
+
export interface RESTOptions {
|
|
6
|
+
token: string;
|
|
7
|
+
proxy?: {
|
|
8
|
+
url: string;
|
|
9
|
+
username?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface RequestOptions {
|
|
14
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
15
|
+
body?: any;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
query?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 轻量版 Discord REST 客户端
|
|
21
|
+
*/
|
|
22
|
+
export declare class DiscordREST {
|
|
23
|
+
private token;
|
|
24
|
+
private proxyUrl?;
|
|
25
|
+
private agent;
|
|
26
|
+
private initialized;
|
|
27
|
+
constructor(options: RESTOptions);
|
|
28
|
+
/**
|
|
29
|
+
* 初始化代理 Agent(延迟加载)
|
|
30
|
+
*/
|
|
31
|
+
private initAgent;
|
|
32
|
+
/**
|
|
33
|
+
* Node.js 原生 HTTPS 请求
|
|
34
|
+
*/
|
|
35
|
+
private nodeRequest;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch 请求(Cloudflare Workers 等环境)
|
|
38
|
+
*/
|
|
39
|
+
private fetchRequest;
|
|
40
|
+
/**
|
|
41
|
+
* 发送请求
|
|
42
|
+
*/
|
|
43
|
+
request<T = any>(endpoint: string, options?: RequestOptions): Promise<T>;
|
|
44
|
+
/** 获取当前用户 */
|
|
45
|
+
getCurrentUser(): Promise<any>;
|
|
46
|
+
/** 获取用户 */
|
|
47
|
+
getUser(userId: string): Promise<any>;
|
|
48
|
+
/** 获取频道 */
|
|
49
|
+
getChannel(channelId: string): Promise<any>;
|
|
50
|
+
/** 发送消息 */
|
|
51
|
+
createMessage(channelId: string, content: string | {
|
|
52
|
+
content?: string;
|
|
53
|
+
embeds?: any[];
|
|
54
|
+
components?: any[];
|
|
55
|
+
}): Promise<any>;
|
|
56
|
+
/** 编辑消息 */
|
|
57
|
+
editMessage(channelId: string, messageId: string, content: string | {
|
|
58
|
+
content?: string;
|
|
59
|
+
embeds?: any[];
|
|
60
|
+
}): Promise<any>;
|
|
61
|
+
/** 删除消息 */
|
|
62
|
+
deleteMessage(channelId: string, messageId: string): Promise<any>;
|
|
63
|
+
/** 获取消息 */
|
|
64
|
+
getMessage(channelId: string, messageId: string): Promise<any>;
|
|
65
|
+
/** 获取消息历史 */
|
|
66
|
+
getMessages(channelId: string, options?: {
|
|
67
|
+
limit?: number;
|
|
68
|
+
before?: string;
|
|
69
|
+
after?: string;
|
|
70
|
+
around?: string;
|
|
71
|
+
}): Promise<any>;
|
|
72
|
+
/** 获取服务器 */
|
|
73
|
+
getGuild(guildId: string): Promise<any>;
|
|
74
|
+
/** 获取服务器列表 */
|
|
75
|
+
getGuilds(): Promise<any>;
|
|
76
|
+
/** 获取服务器成员 */
|
|
77
|
+
getGuildMember(guildId: string, userId: string): Promise<any>;
|
|
78
|
+
/** 获取服务器成员列表 */
|
|
79
|
+
getGuildMembers(guildId: string, options?: {
|
|
80
|
+
limit?: number;
|
|
81
|
+
after?: string;
|
|
82
|
+
}): Promise<any>;
|
|
83
|
+
/** 踢出成员 */
|
|
84
|
+
removeGuildMember(guildId: string, userId: string): Promise<any>;
|
|
85
|
+
/** 封禁成员 */
|
|
86
|
+
banGuildMember(guildId: string, userId: string, options?: {
|
|
87
|
+
delete_message_seconds?: number;
|
|
88
|
+
}): Promise<any>;
|
|
89
|
+
/** 回复 Interaction */
|
|
90
|
+
createInteractionResponse(interactionId: string, interactionToken: string, response: any): Promise<any>;
|
|
91
|
+
/** 获取原始 Interaction 回复 */
|
|
92
|
+
getOriginalInteractionResponse(applicationId: string, interactionToken: string): Promise<any>;
|
|
93
|
+
/** 编辑原始 Interaction 回复 */
|
|
94
|
+
editOriginalInteractionResponse(applicationId: string, interactionToken: string, content: any): Promise<any>;
|
|
95
|
+
/** 创建后续消息 */
|
|
96
|
+
createFollowupMessage(applicationId: string, interactionToken: string, content: any): Promise<any>;
|
|
97
|
+
/** 获取 Gateway URL */
|
|
98
|
+
getGateway(): Promise<any>;
|
|
99
|
+
/** 获取 Gateway Bot URL(带分片信息) */
|
|
100
|
+
getGatewayBot(): Promise<any>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=rest.d.ts.map
|
package/lib/lite/rest.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord REST API 轻量封装
|
|
3
|
+
* Node.js 使用原生 https 模块,Cloudflare Workers 使用 fetch
|
|
4
|
+
*/
|
|
5
|
+
const DISCORD_API_BASE = 'https://discord.com/api/v10';
|
|
6
|
+
/**
|
|
7
|
+
* 检测是否为 Node.js 环境
|
|
8
|
+
*/
|
|
9
|
+
function isNode() {
|
|
10
|
+
return typeof process !== 'undefined' && process.versions?.node !== undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 轻量版 Discord REST 客户端
|
|
14
|
+
*/
|
|
15
|
+
export class DiscordREST {
|
|
16
|
+
token;
|
|
17
|
+
proxyUrl;
|
|
18
|
+
agent = null;
|
|
19
|
+
initialized = false;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.token = options.token;
|
|
22
|
+
if (options.proxy?.url) {
|
|
23
|
+
const proxyUrl = new URL(options.proxy.url);
|
|
24
|
+
if (options.proxy.username)
|
|
25
|
+
proxyUrl.username = options.proxy.username;
|
|
26
|
+
if (options.proxy.password)
|
|
27
|
+
proxyUrl.password = options.proxy.password;
|
|
28
|
+
this.proxyUrl = proxyUrl.toString();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 初始化代理 Agent(延迟加载)
|
|
33
|
+
*/
|
|
34
|
+
async initAgent() {
|
|
35
|
+
if (this.initialized)
|
|
36
|
+
return;
|
|
37
|
+
this.initialized = true;
|
|
38
|
+
if (!this.proxyUrl || !isNode())
|
|
39
|
+
return;
|
|
40
|
+
try {
|
|
41
|
+
// @ts-ignore - https-proxy-agent 是可选依赖
|
|
42
|
+
const { HttpsProxyAgent } = await import('https-proxy-agent');
|
|
43
|
+
this.agent = new HttpsProxyAgent(this.proxyUrl);
|
|
44
|
+
console.log(`[DiscordREST] 已配置代理: ${this.proxyUrl.replace(/:[^:@]+@/, ':***@')}`);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
console.warn('[DiscordREST] https-proxy-agent 未安装,将直接连接');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Node.js 原生 HTTPS 请求
|
|
52
|
+
*/
|
|
53
|
+
nodeRequest(url, options) {
|
|
54
|
+
return new Promise(async (resolve, reject) => {
|
|
55
|
+
const https = await import('https');
|
|
56
|
+
const urlObj = new URL(url);
|
|
57
|
+
const reqOptions = {
|
|
58
|
+
hostname: urlObj.hostname,
|
|
59
|
+
port: urlObj.port || 443,
|
|
60
|
+
path: urlObj.pathname + urlObj.search,
|
|
61
|
+
method: options.method,
|
|
62
|
+
headers: options.headers,
|
|
63
|
+
};
|
|
64
|
+
// 添加代理 agent
|
|
65
|
+
if (this.agent) {
|
|
66
|
+
reqOptions.agent = this.agent;
|
|
67
|
+
}
|
|
68
|
+
const req = https.request(reqOptions, (res) => {
|
|
69
|
+
let data = '';
|
|
70
|
+
res.on('data', (chunk) => {
|
|
71
|
+
data += chunk;
|
|
72
|
+
});
|
|
73
|
+
res.on('end', () => {
|
|
74
|
+
if (res.statusCode === 204) {
|
|
75
|
+
resolve(undefined);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
79
|
+
try {
|
|
80
|
+
resolve(data ? JSON.parse(data) : undefined);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
resolve(data);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
let errorMsg = `Discord API Error: ${res.statusCode}`;
|
|
88
|
+
try {
|
|
89
|
+
const errorData = JSON.parse(data);
|
|
90
|
+
errorMsg += ` - ${JSON.stringify(errorData)}`;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
errorMsg += ` - ${data}`;
|
|
94
|
+
}
|
|
95
|
+
reject(new Error(errorMsg));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
req.on('error', (error) => {
|
|
100
|
+
reject(error);
|
|
101
|
+
});
|
|
102
|
+
// 设置超时
|
|
103
|
+
req.setTimeout(30000, () => {
|
|
104
|
+
req.destroy();
|
|
105
|
+
reject(new Error('Request timeout'));
|
|
106
|
+
});
|
|
107
|
+
if (options.body) {
|
|
108
|
+
req.write(options.body);
|
|
109
|
+
}
|
|
110
|
+
req.end();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Fetch 请求(Cloudflare Workers 等环境)
|
|
115
|
+
*/
|
|
116
|
+
async fetchRequest(url, options) {
|
|
117
|
+
const response = await fetch(url, {
|
|
118
|
+
method: options.method,
|
|
119
|
+
headers: options.headers,
|
|
120
|
+
body: options.body,
|
|
121
|
+
});
|
|
122
|
+
if (response.status === 204) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
127
|
+
throw new Error(`Discord API Error: ${response.status} - ${JSON.stringify(error)}`);
|
|
128
|
+
}
|
|
129
|
+
return response.json();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 发送请求
|
|
133
|
+
*/
|
|
134
|
+
async request(endpoint, options = {}) {
|
|
135
|
+
// 初始化代理
|
|
136
|
+
await this.initAgent();
|
|
137
|
+
const { method = 'GET', body, headers = {}, query } = options;
|
|
138
|
+
let url = `${DISCORD_API_BASE}${endpoint}`;
|
|
139
|
+
if (query) {
|
|
140
|
+
const filteredQuery = Object.fromEntries(Object.entries(query).filter(([_, v]) => v !== undefined));
|
|
141
|
+
if (Object.keys(filteredQuery).length > 0) {
|
|
142
|
+
const params = new URLSearchParams(filteredQuery);
|
|
143
|
+
url += `?${params.toString()}`;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const requestHeaders = {
|
|
147
|
+
'Authorization': `Bot ${this.token}`,
|
|
148
|
+
'Content-Type': 'application/json',
|
|
149
|
+
'User-Agent': 'OneBots Discord Lite (https://github.com/lc-cn/onebots)',
|
|
150
|
+
...headers,
|
|
151
|
+
};
|
|
152
|
+
const requestBody = body ? JSON.stringify(body) : undefined;
|
|
153
|
+
// Node.js 环境使用原生 https 模块(支持 agent)
|
|
154
|
+
if (isNode()) {
|
|
155
|
+
return this.nodeRequest(url, {
|
|
156
|
+
method,
|
|
157
|
+
headers: requestHeaders,
|
|
158
|
+
body: requestBody,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// 其他环境(Cloudflare Workers 等)使用 fetch
|
|
162
|
+
return this.fetchRequest(url, {
|
|
163
|
+
method,
|
|
164
|
+
headers: requestHeaders,
|
|
165
|
+
body: requestBody,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// ============================================
|
|
169
|
+
// 用户相关
|
|
170
|
+
// ============================================
|
|
171
|
+
/** 获取当前用户 */
|
|
172
|
+
async getCurrentUser() {
|
|
173
|
+
return this.request('/users/@me');
|
|
174
|
+
}
|
|
175
|
+
/** 获取用户 */
|
|
176
|
+
async getUser(userId) {
|
|
177
|
+
return this.request(`/users/${userId}`);
|
|
178
|
+
}
|
|
179
|
+
// ============================================
|
|
180
|
+
// 频道相关
|
|
181
|
+
// ============================================
|
|
182
|
+
/** 获取频道 */
|
|
183
|
+
async getChannel(channelId) {
|
|
184
|
+
return this.request(`/channels/${channelId}`);
|
|
185
|
+
}
|
|
186
|
+
/** 发送消息 */
|
|
187
|
+
async createMessage(channelId, content) {
|
|
188
|
+
const body = typeof content === 'string' ? { content } : content;
|
|
189
|
+
return this.request(`/channels/${channelId}/messages`, {
|
|
190
|
+
method: 'POST',
|
|
191
|
+
body,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** 编辑消息 */
|
|
195
|
+
async editMessage(channelId, messageId, content) {
|
|
196
|
+
const body = typeof content === 'string' ? { content } : content;
|
|
197
|
+
return this.request(`/channels/${channelId}/messages/${messageId}`, {
|
|
198
|
+
method: 'PATCH',
|
|
199
|
+
body,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/** 删除消息 */
|
|
203
|
+
async deleteMessage(channelId, messageId) {
|
|
204
|
+
return this.request(`/channels/${channelId}/messages/${messageId}`, {
|
|
205
|
+
method: 'DELETE',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/** 获取消息 */
|
|
209
|
+
async getMessage(channelId, messageId) {
|
|
210
|
+
return this.request(`/channels/${channelId}/messages/${messageId}`);
|
|
211
|
+
}
|
|
212
|
+
/** 获取消息历史 */
|
|
213
|
+
async getMessages(channelId, options) {
|
|
214
|
+
return this.request(`/channels/${channelId}/messages`, {
|
|
215
|
+
query: options,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// ============================================
|
|
219
|
+
// 服务器相关
|
|
220
|
+
// ============================================
|
|
221
|
+
/** 获取服务器 */
|
|
222
|
+
async getGuild(guildId) {
|
|
223
|
+
return this.request(`/guilds/${guildId}`);
|
|
224
|
+
}
|
|
225
|
+
/** 获取服务器列表 */
|
|
226
|
+
async getGuilds() {
|
|
227
|
+
return this.request('/users/@me/guilds');
|
|
228
|
+
}
|
|
229
|
+
/** 获取服务器成员 */
|
|
230
|
+
async getGuildMember(guildId, userId) {
|
|
231
|
+
return this.request(`/guilds/${guildId}/members/${userId}`);
|
|
232
|
+
}
|
|
233
|
+
/** 获取服务器成员列表 */
|
|
234
|
+
async getGuildMembers(guildId, options) {
|
|
235
|
+
return this.request(`/guilds/${guildId}/members`, {
|
|
236
|
+
query: options,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/** 踢出成员 */
|
|
240
|
+
async removeGuildMember(guildId, userId) {
|
|
241
|
+
return this.request(`/guilds/${guildId}/members/${userId}`, {
|
|
242
|
+
method: 'DELETE',
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** 封禁成员 */
|
|
246
|
+
async banGuildMember(guildId, userId, options) {
|
|
247
|
+
return this.request(`/guilds/${guildId}/bans/${userId}`, {
|
|
248
|
+
method: 'PUT',
|
|
249
|
+
body: options,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
// ============================================
|
|
253
|
+
// Interactions 相关
|
|
254
|
+
// ============================================
|
|
255
|
+
/** 回复 Interaction */
|
|
256
|
+
async createInteractionResponse(interactionId, interactionToken, response) {
|
|
257
|
+
return this.request(`/interactions/${interactionId}/${interactionToken}/callback`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
body: response,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** 获取原始 Interaction 回复 */
|
|
263
|
+
async getOriginalInteractionResponse(applicationId, interactionToken) {
|
|
264
|
+
return this.request(`/webhooks/${applicationId}/${interactionToken}/messages/@original`);
|
|
265
|
+
}
|
|
266
|
+
/** 编辑原始 Interaction 回复 */
|
|
267
|
+
async editOriginalInteractionResponse(applicationId, interactionToken, content) {
|
|
268
|
+
return this.request(`/webhooks/${applicationId}/${interactionToken}/messages/@original`, {
|
|
269
|
+
method: 'PATCH',
|
|
270
|
+
body: content,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/** 创建后续消息 */
|
|
274
|
+
async createFollowupMessage(applicationId, interactionToken, content) {
|
|
275
|
+
return this.request(`/webhooks/${applicationId}/${interactionToken}`, {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
body: content,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
// ============================================
|
|
281
|
+
// Gateway 相关
|
|
282
|
+
// ============================================
|
|
283
|
+
/** 获取 Gateway URL */
|
|
284
|
+
async getGateway() {
|
|
285
|
+
return this.request('/gateway');
|
|
286
|
+
}
|
|
287
|
+
/** 获取 Gateway Bot URL(带分片信息) */
|
|
288
|
+
async getGatewayBot() {
|
|
289
|
+
return this.request('/gateway/bot');
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=rest.js.map
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord 适配器类型定义
|
|
3
|
+
* 轻量版 - 不依赖 discord.js
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 代理配置
|
|
7
|
+
*/
|
|
8
|
+
export interface ProxyConfig {
|
|
9
|
+
/** 代理服务器地址,如 http://127.0.0.1:7890 */
|
|
10
|
+
url: string;
|
|
11
|
+
/** 代理用户名(可选) */
|
|
12
|
+
username?: string;
|
|
13
|
+
/** 代理密码(可选) */
|
|
14
|
+
password?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gateway Intents 名称
|
|
18
|
+
*/
|
|
19
|
+
export type GatewayIntentName = 'Guilds' | 'GuildMembers' | 'GuildModeration' | 'GuildEmojisAndStickers' | 'GuildIntegrations' | 'GuildWebhooks' | 'GuildInvites' | 'GuildVoiceStates' | 'GuildPresences' | 'GuildMessages' | 'GuildMessageReactions' | 'GuildMessageTyping' | 'DirectMessages' | 'DirectMessageReactions' | 'DirectMessageTyping' | 'MessageContent' | 'GuildScheduledEvents' | 'AutoModerationConfiguration' | 'AutoModerationExecution';
|
|
20
|
+
/**
|
|
21
|
+
* 在线状态
|
|
22
|
+
*/
|
|
23
|
+
export type PresenceStatus = 'online' | 'idle' | 'dnd' | 'invisible';
|
|
24
|
+
/**
|
|
25
|
+
* 活动类型
|
|
26
|
+
*/
|
|
27
|
+
export declare enum ActivityType {
|
|
28
|
+
Playing = 0,
|
|
29
|
+
Streaming = 1,
|
|
30
|
+
Listening = 2,
|
|
31
|
+
Watching = 3,
|
|
32
|
+
Custom = 4,
|
|
33
|
+
Competing = 5
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Discord 配置类型
|
|
37
|
+
*/
|
|
38
|
+
export interface DiscordConfig {
|
|
39
|
+
/** 账号标识 */
|
|
40
|
+
account_id: string;
|
|
41
|
+
/** Discord Bot Token */
|
|
42
|
+
token: string;
|
|
43
|
+
/** 代理配置(用于访问 Discord API) */
|
|
44
|
+
proxy?: ProxyConfig;
|
|
45
|
+
/** Gateway Intents - 可选,默认包含常用intents */
|
|
46
|
+
intents?: GatewayIntentName[];
|
|
47
|
+
/** 机器人初始状态 */
|
|
48
|
+
presence?: {
|
|
49
|
+
status?: PresenceStatus;
|
|
50
|
+
activities?: Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
type?: ActivityType;
|
|
53
|
+
url?: string;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 频道类型
|
|
59
|
+
*/
|
|
60
|
+
export declare enum ChannelType {
|
|
61
|
+
GuildText = 0,
|
|
62
|
+
DM = 1,
|
|
63
|
+
GuildVoice = 2,
|
|
64
|
+
GroupDM = 3,
|
|
65
|
+
GuildCategory = 4,
|
|
66
|
+
GuildAnnouncement = 5,
|
|
67
|
+
AnnouncementThread = 10,
|
|
68
|
+
PublicThread = 11,
|
|
69
|
+
PrivateThread = 12,
|
|
70
|
+
GuildStageVoice = 13,
|
|
71
|
+
GuildDirectory = 14,
|
|
72
|
+
GuildForum = 15,
|
|
73
|
+
GuildMedia = 16
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 消息类型
|
|
77
|
+
*/
|
|
78
|
+
export declare enum MessageType {
|
|
79
|
+
Default = 0,
|
|
80
|
+
RecipientAdd = 1,
|
|
81
|
+
RecipientRemove = 2,
|
|
82
|
+
Call = 3,
|
|
83
|
+
ChannelNameChange = 4,
|
|
84
|
+
ChannelIconChange = 5,
|
|
85
|
+
ChannelPinnedMessage = 6,
|
|
86
|
+
UserJoin = 7,
|
|
87
|
+
GuildBoost = 8,
|
|
88
|
+
GuildBoostTier1 = 9,
|
|
89
|
+
GuildBoostTier2 = 10,
|
|
90
|
+
GuildBoostTier3 = 11,
|
|
91
|
+
ChannelFollowAdd = 12,
|
|
92
|
+
GuildDiscoveryDisqualified = 14,
|
|
93
|
+
GuildDiscoveryRequalified = 15,
|
|
94
|
+
ThreadCreated = 18,
|
|
95
|
+
Reply = 19,
|
|
96
|
+
ChatInputCommand = 20,
|
|
97
|
+
ThreadStarterMessage = 21,
|
|
98
|
+
GuildInviteReminder = 22,
|
|
99
|
+
ContextMenuCommand = 23,
|
|
100
|
+
AutoModerationAction = 24
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Discord 事件类型
|
|
104
|
+
*/
|
|
105
|
+
export type DiscordEventType = 'ready' | 'messageCreate' | 'messageUpdate' | 'messageDelete' | 'guildMemberAdd' | 'guildMemberRemove' | 'guildMemberUpdate' | 'guildCreate' | 'guildDelete' | 'channelCreate' | 'channelDelete' | 'channelUpdate' | 'messageReactionAdd' | 'messageReactionRemove' | 'interactionCreate' | 'error';
|
|
106
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discord 适配器类型定义
|
|
3
|
+
* 轻量版 - 不依赖 discord.js
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 活动类型
|
|
7
|
+
*/
|
|
8
|
+
export var ActivityType;
|
|
9
|
+
(function (ActivityType) {
|
|
10
|
+
ActivityType[ActivityType["Playing"] = 0] = "Playing";
|
|
11
|
+
ActivityType[ActivityType["Streaming"] = 1] = "Streaming";
|
|
12
|
+
ActivityType[ActivityType["Listening"] = 2] = "Listening";
|
|
13
|
+
ActivityType[ActivityType["Watching"] = 3] = "Watching";
|
|
14
|
+
ActivityType[ActivityType["Custom"] = 4] = "Custom";
|
|
15
|
+
ActivityType[ActivityType["Competing"] = 5] = "Competing";
|
|
16
|
+
})(ActivityType || (ActivityType = {}));
|
|
17
|
+
/**
|
|
18
|
+
* 频道类型
|
|
19
|
+
*/
|
|
20
|
+
export var ChannelType;
|
|
21
|
+
(function (ChannelType) {
|
|
22
|
+
ChannelType[ChannelType["GuildText"] = 0] = "GuildText";
|
|
23
|
+
ChannelType[ChannelType["DM"] = 1] = "DM";
|
|
24
|
+
ChannelType[ChannelType["GuildVoice"] = 2] = "GuildVoice";
|
|
25
|
+
ChannelType[ChannelType["GroupDM"] = 3] = "GroupDM";
|
|
26
|
+
ChannelType[ChannelType["GuildCategory"] = 4] = "GuildCategory";
|
|
27
|
+
ChannelType[ChannelType["GuildAnnouncement"] = 5] = "GuildAnnouncement";
|
|
28
|
+
ChannelType[ChannelType["AnnouncementThread"] = 10] = "AnnouncementThread";
|
|
29
|
+
ChannelType[ChannelType["PublicThread"] = 11] = "PublicThread";
|
|
30
|
+
ChannelType[ChannelType["PrivateThread"] = 12] = "PrivateThread";
|
|
31
|
+
ChannelType[ChannelType["GuildStageVoice"] = 13] = "GuildStageVoice";
|
|
32
|
+
ChannelType[ChannelType["GuildDirectory"] = 14] = "GuildDirectory";
|
|
33
|
+
ChannelType[ChannelType["GuildForum"] = 15] = "GuildForum";
|
|
34
|
+
ChannelType[ChannelType["GuildMedia"] = 16] = "GuildMedia";
|
|
35
|
+
})(ChannelType || (ChannelType = {}));
|
|
36
|
+
/**
|
|
37
|
+
* 消息类型
|
|
38
|
+
*/
|
|
39
|
+
export var MessageType;
|
|
40
|
+
(function (MessageType) {
|
|
41
|
+
MessageType[MessageType["Default"] = 0] = "Default";
|
|
42
|
+
MessageType[MessageType["RecipientAdd"] = 1] = "RecipientAdd";
|
|
43
|
+
MessageType[MessageType["RecipientRemove"] = 2] = "RecipientRemove";
|
|
44
|
+
MessageType[MessageType["Call"] = 3] = "Call";
|
|
45
|
+
MessageType[MessageType["ChannelNameChange"] = 4] = "ChannelNameChange";
|
|
46
|
+
MessageType[MessageType["ChannelIconChange"] = 5] = "ChannelIconChange";
|
|
47
|
+
MessageType[MessageType["ChannelPinnedMessage"] = 6] = "ChannelPinnedMessage";
|
|
48
|
+
MessageType[MessageType["UserJoin"] = 7] = "UserJoin";
|
|
49
|
+
MessageType[MessageType["GuildBoost"] = 8] = "GuildBoost";
|
|
50
|
+
MessageType[MessageType["GuildBoostTier1"] = 9] = "GuildBoostTier1";
|
|
51
|
+
MessageType[MessageType["GuildBoostTier2"] = 10] = "GuildBoostTier2";
|
|
52
|
+
MessageType[MessageType["GuildBoostTier3"] = 11] = "GuildBoostTier3";
|
|
53
|
+
MessageType[MessageType["ChannelFollowAdd"] = 12] = "ChannelFollowAdd";
|
|
54
|
+
MessageType[MessageType["GuildDiscoveryDisqualified"] = 14] = "GuildDiscoveryDisqualified";
|
|
55
|
+
MessageType[MessageType["GuildDiscoveryRequalified"] = 15] = "GuildDiscoveryRequalified";
|
|
56
|
+
MessageType[MessageType["ThreadCreated"] = 18] = "ThreadCreated";
|
|
57
|
+
MessageType[MessageType["Reply"] = 19] = "Reply";
|
|
58
|
+
MessageType[MessageType["ChatInputCommand"] = 20] = "ChatInputCommand";
|
|
59
|
+
MessageType[MessageType["ThreadStarterMessage"] = 21] = "ThreadStarterMessage";
|
|
60
|
+
MessageType[MessageType["GuildInviteReminder"] = 22] = "GuildInviteReminder";
|
|
61
|
+
MessageType[MessageType["ContextMenuCommand"] = 23] = "ContextMenuCommand";
|
|
62
|
+
MessageType[MessageType["AutoModerationAction"] = 24] = "AutoModerationAction";
|
|
63
|
+
})(MessageType || (MessageType = {}));
|
|
64
|
+
//# sourceMappingURL=types.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onebots/adapter-discord",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "onebots Discord 适配器(轻量版,支持 Node.js 和 Cloudflare Workers)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./lite": {
|
|
14
|
+
"types": "./lib/lite/index.d.ts",
|
|
15
|
+
"default": "./lib/lite/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"onebots",
|
|
20
|
+
"discord",
|
|
21
|
+
"adapter",
|
|
22
|
+
"cloudflare-workers",
|
|
23
|
+
"serverless",
|
|
24
|
+
"lightweight"
|
|
25
|
+
],
|
|
26
|
+
"author": "凉菜",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"registry": "https://registry.npmjs.org"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"/lib/**/*.js",
|
|
34
|
+
"/lib/**/*.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsc-alias": "latest",
|
|
38
|
+
"typescript": "latest",
|
|
39
|
+
"@types/node": "^22.7.3"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"onebots": "1.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"ws": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"https-proxy-agent": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"socks-proxy-agent": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {},
|
|
56
|
+
"optionalDependencies": {
|
|
57
|
+
"ws": "^8.18.0",
|
|
58
|
+
"https-proxy-agent": "^7.0.6",
|
|
59
|
+
"socks-proxy-agent": "^8.0.5"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "rm -f *.tsbuildinfo && tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
|
63
|
+
"clean": "rm -rf lib *.tsbuildinfo"
|
|
64
|
+
}
|
|
65
|
+
}
|