@im-more/dsh-onebot 0.0.0-stage → 0.1.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/cordis.patch.yml +11 -0
- package/lib/index.js +2003 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +55 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +140 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +40 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +33 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/cqcode.d.ts +29 -0
- package/lib/types/cqcode.d.ts.map +1 -0
- package/lib/types/cqcode.js +73 -0
- package/lib/types/cqcode.js.map +1 -0
- package/lib/types/decode.d.ts +106 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +433 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +32 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +117 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +18 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +27 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +6 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/modes/segment.d.ts +16 -0
- package/lib/types/modes/segment.d.ts.map +1 -0
- package/lib/types/modes/segment.js +80 -0
- package/lib/types/modes/segment.js.map +1 -0
- package/lib/types/modes/shared.d.ts +101 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +208 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/request.d.ts +64 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +108 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +93 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +161 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/transport/http.d.ts +29 -0
- package/lib/types/transport/http.d.ts.map +1 -0
- package/lib/types/transport/http.js +158 -0
- package/lib/types/transport/http.js.map +1 -0
- package/lib/types/transport/shared.d.ts +48 -0
- package/lib/types/transport/shared.d.ts.map +1 -0
- package/lib/types/transport/shared.js +75 -0
- package/lib/types/transport/shared.js.map +1 -0
- package/lib/types/transport/ws-reverse.d.ts +42 -0
- package/lib/types/transport/ws-reverse.d.ts.map +1 -0
- package/lib/types/transport/ws-reverse.js +178 -0
- package/lib/types/transport/ws-reverse.js.map +1 -0
- package/lib/types/transport/ws.d.ts +40 -0
- package/lib/types/transport/ws.d.ts.map +1 -0
- package/lib/types/transport/ws.js +233 -0
- package/lib/types/transport/ws.js.map +1 -0
- package/lib/types/types.d.ts +495 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +191 -0
- package/lib/types/types.js.map +1 -0
- package/package.json +68 -3
- package/src/bot.ts +230 -0
- package/src/config.ts +66 -0
- package/src/cqcode.ts +85 -0
- package/src/decode.ts +524 -0
- package/src/errors.ts +134 -0
- package/src/identity.ts +34 -0
- package/src/index.ts +18 -0
- package/src/modes/segment.ts +109 -0
- package/src/modes/shared.ts +277 -0
- package/src/request.ts +128 -0
- package/src/send.ts +233 -0
- package/src/transport/http.ts +221 -0
- package/src/transport/shared.ts +98 -0
- package/src/transport/ws-reverse.ts +236 -0
- package/src/transport/ws.ts +286 -0
- package/src/types.ts +743 -0
- package/README.md +0 -3
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { camelize } from '@deepseek-ai/cosmokit';
|
|
3
|
+
export var SafetyLevel;
|
|
4
|
+
(function (SafetyLevel) {
|
|
5
|
+
SafetyLevel[SafetyLevel["safe"] = 0] = "safe";
|
|
6
|
+
SafetyLevel[SafetyLevel["unknown"] = 1] = "unknown";
|
|
7
|
+
SafetyLevel[SafetyLevel["danger"] = 2] = "danger";
|
|
8
|
+
})(SafetyLevel || (SafetyLevel = {}));
|
|
9
|
+
export class TimeoutError extends Error {
|
|
10
|
+
constructor(args, url) {
|
|
11
|
+
super(`Timeout with request ${url}, args: ${JSON.stringify(args)}`);
|
|
12
|
+
Object.defineProperties(this, {
|
|
13
|
+
args: { value: args },
|
|
14
|
+
url: { value: url },
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class SenderError extends Error {
|
|
19
|
+
constructor(args, url, retcode) {
|
|
20
|
+
super(`Error with request ${url}, args: ${JSON.stringify(args)}, retcode: ${retcode}`);
|
|
21
|
+
Object.defineProperties(this, {
|
|
22
|
+
code: { value: retcode },
|
|
23
|
+
args: { value: args },
|
|
24
|
+
url: { value: url },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class Internal {
|
|
29
|
+
bot;
|
|
30
|
+
constructor(bot) {
|
|
31
|
+
this.bot = bot;
|
|
32
|
+
}
|
|
33
|
+
async _get(action, params = {}) {
|
|
34
|
+
this.bot.ctx.logger.debug('[request] %s %o', action, params);
|
|
35
|
+
const response = await this._request(action, params);
|
|
36
|
+
this.bot.ctx.logger.debug('[response] %o', response);
|
|
37
|
+
const { data, retcode } = response;
|
|
38
|
+
if (retcode === 0)
|
|
39
|
+
return data;
|
|
40
|
+
throw new SenderError(params, action, retcode);
|
|
41
|
+
}
|
|
42
|
+
async setGroupAnonymousBan(group_id, meta, duration) {
|
|
43
|
+
const args = { group_id, duration };
|
|
44
|
+
args[typeof meta === 'string' ? 'flag' : 'anonymous'] = meta;
|
|
45
|
+
await this._get('set_group_anonymous_ban', args);
|
|
46
|
+
}
|
|
47
|
+
async setGroupAnonymousBanAsync(group_id, meta, duration) {
|
|
48
|
+
const args = { group_id, duration };
|
|
49
|
+
args[typeof meta === 'string' ? 'flag' : 'anonymous'] = meta;
|
|
50
|
+
await this._get('set_group_anonymous_ban_async', args);
|
|
51
|
+
}
|
|
52
|
+
static asyncPrefixes = ['set', 'send', 'delete', 'create', 'upload', 'move', 'rename'];
|
|
53
|
+
static prepareMethod(name) {
|
|
54
|
+
const prop = camelize(name.replace(/^[_.]/, ''));
|
|
55
|
+
const isAsync = Internal.asyncPrefixes.some(prefix => prop.startsWith(prefix));
|
|
56
|
+
return [prop, isAsync];
|
|
57
|
+
}
|
|
58
|
+
static prepareArg(name, params, args) {
|
|
59
|
+
const fixedArg = Object.fromEntries(params.map((name, index) => [name, args[index]]));
|
|
60
|
+
for (const key in fixedArg) {
|
|
61
|
+
if (!name.includes('guild') && key.endsWith('_id')) {
|
|
62
|
+
const value = +fixedArg[key];
|
|
63
|
+
if (Math.abs(value) < 4294967296) {
|
|
64
|
+
fixedArg[key] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return fixedArg;
|
|
69
|
+
}
|
|
70
|
+
static define(name, ...params) {
|
|
71
|
+
const [prop, isAsync] = Internal.prepareMethod(name);
|
|
72
|
+
Internal.prototype[prop] = async function (...args) {
|
|
73
|
+
const data = await this._get(name, Internal.prepareArg(name, params, args));
|
|
74
|
+
if (!isAsync)
|
|
75
|
+
return data;
|
|
76
|
+
};
|
|
77
|
+
isAsync && (Internal.prototype[prop + 'Async'] = async function (...args) {
|
|
78
|
+
await this._get(name + '_async', Internal.prepareArg(name, params, args));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
static defineExtract(name, key, ...params) {
|
|
82
|
+
const [prop, isAsync] = Internal.prepareMethod(name);
|
|
83
|
+
Internal.prototype[prop] = async function (...args) {
|
|
84
|
+
const data = await this._get(name, Internal.prepareArg(name, params, args));
|
|
85
|
+
return data[key];
|
|
86
|
+
};
|
|
87
|
+
isAsync && (Internal.prototype[prop + 'Async'] = async function (...args) {
|
|
88
|
+
await this._get(name + '_async', Internal.prepareArg(name, params, args));
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// messages
|
|
93
|
+
Internal.defineExtract('send_msg', 'message_id', 'user_id', 'group_id', 'message', 'auto_escape');
|
|
94
|
+
Internal.defineExtract('send_private_msg', 'message_id', 'user_id', 'message', 'auto_escape');
|
|
95
|
+
Internal.defineExtract('send_group_msg', 'message_id', 'group_id', 'message', 'auto_escape');
|
|
96
|
+
Internal.defineExtract('send_group_forward_msg', 'message_id', 'group_id', 'messages');
|
|
97
|
+
Internal.defineExtract('send_private_forward_msg', 'message_id', 'user_id', 'messages');
|
|
98
|
+
Internal.define('delete_msg', 'message_id');
|
|
99
|
+
Internal.define('mark_msg_as_read', 'message_id');
|
|
100
|
+
Internal.define('set_essence_msg', 'message_id');
|
|
101
|
+
Internal.define('delete_essence_msg', 'message_id');
|
|
102
|
+
Internal.define('send_group_sign', 'group_id');
|
|
103
|
+
Internal.define('send_like', 'user_id', 'times');
|
|
104
|
+
Internal.define('get_msg', 'message_id');
|
|
105
|
+
Internal.define('get_essence_msg_list', 'group_id');
|
|
106
|
+
Internal.define('ocr_image', 'image');
|
|
107
|
+
Internal.defineExtract('get_forward_msg', 'messages', 'message_id');
|
|
108
|
+
Internal.defineExtract('.get_word_slices', 'slices', 'content');
|
|
109
|
+
Internal.define('get_group_msg_history', 'group_id', 'message_seq');
|
|
110
|
+
Internal.defineExtract('get_friend_msg_history', 'messages', 'user_id', 'message_seq', 'count', 'reverseOrder');
|
|
111
|
+
Internal.define('set_friend_add_request', 'flag', 'approve', 'remark');
|
|
112
|
+
Internal.define('set_group_add_request', 'flag', 'sub_type', 'approve', 'reason');
|
|
113
|
+
Internal.defineExtract('_get_model_show', 'variants', 'model');
|
|
114
|
+
Internal.define('_set_model_show', 'model', 'model_show');
|
|
115
|
+
// group operations
|
|
116
|
+
Internal.define('set_group_kick', 'group_id', 'user_id', 'reject_add_request');
|
|
117
|
+
Internal.define('set_group_ban', 'group_id', 'user_id', 'duration');
|
|
118
|
+
Internal.define('set_group_whole_ban', 'group_id', 'enable');
|
|
119
|
+
Internal.define('set_group_admin', 'group_id', 'user_id', 'enable');
|
|
120
|
+
Internal.define('set_group_anonymous', 'group_id', 'enable');
|
|
121
|
+
Internal.define('set_group_card', 'group_id', 'user_id', 'card');
|
|
122
|
+
Internal.define('set_group_leave', 'group_id', 'is_dismiss');
|
|
123
|
+
Internal.define('set_group_special_title', 'group_id', 'user_id', 'special_title', 'duration');
|
|
124
|
+
Internal.define('set_group_name', 'group_id', 'group_name');
|
|
125
|
+
Internal.define('set_group_portrait', 'group_id', 'file', 'cache');
|
|
126
|
+
Internal.define('_send_group_notice', 'group_id', 'content', 'image', 'pinned', 'confirm_required');
|
|
127
|
+
Internal.define('_get_group_notice', 'group_id');
|
|
128
|
+
Internal.define('_del_group_notice', 'group_id', 'notice_id');
|
|
129
|
+
Internal.define('get_group_at_all_remain', 'group_id');
|
|
130
|
+
// accounts
|
|
131
|
+
Internal.define('get_login_info');
|
|
132
|
+
Internal.define('qidian_get_login_info');
|
|
133
|
+
Internal.define('set_qq_profile', 'nickname', 'company', 'email', 'college', 'personal_note');
|
|
134
|
+
Internal.define('set_qq_avatar', 'file');
|
|
135
|
+
Internal.define('set_online_status', 'status', 'ext_status', 'battery_status');
|
|
136
|
+
Internal.define('get_stranger_info', 'user_id', 'no_cache');
|
|
137
|
+
Internal.define('_get_vip_info', 'user_id');
|
|
138
|
+
Internal.define('get_friend_list');
|
|
139
|
+
Internal.define('get_unidirectional_friend_list');
|
|
140
|
+
Internal.define('delete_friend', 'user_id');
|
|
141
|
+
Internal.define('delete_unidirectional_friend', 'user_id');
|
|
142
|
+
Internal.define('get_group_info', 'group_id', 'no_cache');
|
|
143
|
+
Internal.define('get_group_list', 'no_cache');
|
|
144
|
+
Internal.define('get_group_member_info', 'group_id', 'user_id', 'no_cache');
|
|
145
|
+
Internal.define('get_group_member_list', 'group_id');
|
|
146
|
+
Internal.define('get_group_honor_info', 'group_id', 'type');
|
|
147
|
+
Internal.define('get_group_system_msg');
|
|
148
|
+
Internal.define('get_group_file_system_info', 'group_id');
|
|
149
|
+
Internal.define('get_group_root_files', 'group_id');
|
|
150
|
+
Internal.define('get_group_files_by_folder', 'group_id', 'folder_id');
|
|
151
|
+
Internal.define('upload_private_file', 'user_id', 'file', 'name');
|
|
152
|
+
Internal.define('upload_group_file', 'group_id', 'file', 'name', 'folder');
|
|
153
|
+
Internal.define('create_group_file_folder', 'group_id', 'folder_id', 'name');
|
|
154
|
+
Internal.define('delete_group_folder', 'group_id', 'folder_id');
|
|
155
|
+
Internal.define('delete_group_file', 'group_id', 'folder_id', 'file_id', 'busid');
|
|
156
|
+
Internal.defineExtract('get_group_file_url', 'url', 'group_id', 'file_id', 'busid');
|
|
157
|
+
Internal.defineExtract('download_file', 'file', 'url', 'headers', 'thread_count');
|
|
158
|
+
Internal.defineExtract('get_online_clients', 'clients', 'no_cache');
|
|
159
|
+
Internal.defineExtract('check_url_safely', 'level', 'url');
|
|
160
|
+
Internal.define('get_group_signed_list', 'group_id');
|
|
161
|
+
Internal.defineExtract('get_cookies', 'cookies', 'domain');
|
|
162
|
+
Internal.defineExtract('get_csrf_token', 'token');
|
|
163
|
+
Internal.define('get_credentials', 'domain');
|
|
164
|
+
Internal.define('get_record', 'file', 'out_format', 'full_path');
|
|
165
|
+
Internal.define('get_image', 'file');
|
|
166
|
+
Internal.defineExtract('can_send_image', 'yes');
|
|
167
|
+
Internal.defineExtract('can_send_record', 'yes');
|
|
168
|
+
Internal.define('get_status');
|
|
169
|
+
Internal.define('get_version_info');
|
|
170
|
+
Internal.define('set_restart', 'delay');
|
|
171
|
+
Internal.define('reload_event_filter');
|
|
172
|
+
Internal.define('clean_cache');
|
|
173
|
+
Internal.define('get_guild_service_profile');
|
|
174
|
+
Internal.define('get_guild_list');
|
|
175
|
+
Internal.define('get_guild_meta_by_guest', 'guild_id');
|
|
176
|
+
Internal.define('get_guild_channel_list', 'guild_id', 'no_cache');
|
|
177
|
+
Internal.define('get_guild_member_list', 'guild_id', 'next_token');
|
|
178
|
+
Internal.define('get_guild_member_profile', 'guild_id', 'user_id');
|
|
179
|
+
Internal.defineExtract('send_guild_channel_msg', 'message_id', 'guild_id', 'channel_id', 'message');
|
|
180
|
+
// lagrange
|
|
181
|
+
// TODO lagrange 和 gocqhttp 接口并不一致,目前就按照参数多的来写了
|
|
182
|
+
Internal.define('upload_image', 'file');
|
|
183
|
+
Internal.defineExtract('get_private_file_url', 'url', 'user_id', 'file_id', 'file_hash');
|
|
184
|
+
Internal.define('move_group_file', 'group_id', 'file_id', 'parent_directory', 'target_directory');
|
|
185
|
+
// Internal.define('delete_group_file', 'group_id', 'file_id')
|
|
186
|
+
// Internal.define('create_group_file_folder', 'group_id', 'name', 'parent_id')
|
|
187
|
+
Internal.define('delete_group_file_folder', 'group_id', 'folder_id');
|
|
188
|
+
Internal.define('rename_group_file_folder', 'group_id', 'folder_id', 'new_folder_name');
|
|
189
|
+
// reaction
|
|
190
|
+
Internal.define('set_msg_emoji_like', 'message_id', 'emoji_id', 'set');
|
|
191
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,yDAAyD;AAEzD,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAA;AA+RtD,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,6CAAI,CAAA;IACJ,mDAAO,CAAA;IACP,iDAAM,CAAA;AACR,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AA2PD,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,IAAU,EAAE,GAAW;QACjC,KAAK,CAAC,wBAAwB,GAAG,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACnE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC5B,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;YACr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AA+E;AAC/E,QAAQ,CAAC,MAAM,CAAC,0BAA0B,EAAE,UAAU,EAAE,WAAW,CAAC,CAAA;AACpE,QAAQ,CAAC,MAAM,CAAC,0BAA0B,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAA;AAEvF,WAAW;AACX,QAAQ,CAAC,MAAM,CAAC,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@im-more/dsh-onebot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OneBot 11 adapter for official dsh-im of DeepSeek Harness",
|
|
5
|
+
"homepage": "https://github.com/ilharp/dsh-im-more",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/ilharp/dsh-im-more.git",
|
|
9
|
+
"directory": "packages/onebot"
|
|
10
|
+
},
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Il Harper",
|
|
13
|
+
"email": "hi@ilharper.com",
|
|
14
|
+
"url": "https://ilharper.com"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "lib/index.js",
|
|
19
|
+
"types": "lib/types/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./lib/types/index.d.ts",
|
|
23
|
+
"default": "./lib/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json",
|
|
26
|
+
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"src",
|
|
31
|
+
"cordis.patch.yml"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"dsh": ">=0.2.3-alpha.3"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@deepseek-ai/cordis": ">=4.2.0-alpha.2",
|
|
38
|
+
"@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
|
|
39
|
+
"@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
|
|
40
|
+
"@deepseek-ai/cosmokit": ">=1.10.0-alpha.2",
|
|
41
|
+
"@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
|
|
42
|
+
"@deepseek-ai/schemastery": ">=3.20.0-alpha.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@deepseek-ai/cordis": ">=4.2.0-alpha.2",
|
|
46
|
+
"@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
|
|
47
|
+
"@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
|
|
48
|
+
"@deepseek-ai/cosmokit": ">=1.10.0-alpha.2",
|
|
49
|
+
"@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
|
|
50
|
+
"@deepseek-ai/schemastery": ">=3.20.0-alpha.2",
|
|
51
|
+
"@types/node": "^22.20.1",
|
|
52
|
+
"@types/ws": "^8.18.2",
|
|
53
|
+
"tsdown": "^0.22.2",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vitest": "^4.1.11",
|
|
56
|
+
"ws": "^8.21.3"
|
|
57
|
+
},
|
|
58
|
+
"dsh": {
|
|
59
|
+
"bundle": {
|
|
60
|
+
"patch": "./cordis.patch.yml"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"ws": "^8.21.3"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsc -p tsconfig.json && tsdown",
|
|
68
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
69
|
+
"test": "vitest run"
|
|
70
|
+
}
|
|
6
71
|
}
|
package/src/bot.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
2
|
+
import {
|
|
3
|
+
Adapter,
|
|
4
|
+
PlatformError,
|
|
5
|
+
type ChatRef,
|
|
6
|
+
type InboundMessage,
|
|
7
|
+
type MembersPage,
|
|
8
|
+
type MessageRef,
|
|
9
|
+
type Mode,
|
|
10
|
+
type PrepareContext,
|
|
11
|
+
type ResolvedResource,
|
|
12
|
+
type ResourceKind,
|
|
13
|
+
type ResourceRef,
|
|
14
|
+
type SendContext,
|
|
15
|
+
type SentPart,
|
|
16
|
+
type Target,
|
|
17
|
+
} from '@deepseek-ai/cordis-plugin-im-core'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
import { Config } from './config.ts'
|
|
20
|
+
import { classifyOneBotError } from './errors.ts'
|
|
21
|
+
import { createSegmentMode } from './modes/segment.ts'
|
|
22
|
+
import type { OneBotModeTypes, OneBotPayload } from './modes/shared.ts'
|
|
23
|
+
import {
|
|
24
|
+
createReaction,
|
|
25
|
+
deletePart,
|
|
26
|
+
deleteReaction,
|
|
27
|
+
getMessage,
|
|
28
|
+
members,
|
|
29
|
+
normalizeSource,
|
|
30
|
+
sendPayload,
|
|
31
|
+
type OneBotSendDeps,
|
|
32
|
+
} from './send.ts'
|
|
33
|
+
import { OneBotHttp } from './transport/http.ts'
|
|
34
|
+
import { OneBotWsServer } from './transport/ws-reverse.ts'
|
|
35
|
+
import { OneBotWsClient } from './transport/ws.ts'
|
|
36
|
+
import { Internal } from './types.ts'
|
|
37
|
+
|
|
38
|
+
/** The single mode this adapter always registers. */
|
|
39
|
+
export interface OneBotModes {
|
|
40
|
+
[mode: string]: Mode<OneBotModeTypes>
|
|
41
|
+
segment: Mode<OneBotModeTypes>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** A transport `connect` starts and `disconnect` stops. */
|
|
45
|
+
interface OneBotTransport {
|
|
46
|
+
start(): Promise<void>
|
|
47
|
+
stop(): Promise<void>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* OneBot 11 adapter.
|
|
52
|
+
*
|
|
53
|
+
* The implementation is a third-party process; this adapter is the framework side of the protocol. Identity is the
|
|
54
|
+
* configured `selfId`, verified with `get_login_info` on the forward WebSocket, and the transports are the three
|
|
55
|
+
* `protocol` values of the upstream plugin.
|
|
56
|
+
*/
|
|
57
|
+
export class OneBotBot extends Adapter<Config, OneBotModes> {
|
|
58
|
+
/** The adapter needs the Satori service and the isolated `http` service. */
|
|
59
|
+
static override inject = ['satori', 'http']
|
|
60
|
+
/** The Loader applies this schema to a profile row's `config` before the constructor runs. */
|
|
61
|
+
static readonly Config = Config
|
|
62
|
+
|
|
63
|
+
readonly modes: OneBotModes
|
|
64
|
+
readonly modeOrder = ['segment'] as const
|
|
65
|
+
|
|
66
|
+
/** Full typed OneBot 11 action surface registered by the migrated declarations. */
|
|
67
|
+
override readonly internal: Internal
|
|
68
|
+
|
|
69
|
+
private transport: OneBotTransport | undefined
|
|
70
|
+
|
|
71
|
+
constructor(ctx: Context, config: Config) {
|
|
72
|
+
super(ctx, config, {
|
|
73
|
+
id: `onebot:${config.selfId}`,
|
|
74
|
+
platform: 'onebot',
|
|
75
|
+
adapter: 'onebot',
|
|
76
|
+
})
|
|
77
|
+
this.selfId = config.selfId
|
|
78
|
+
this.modes = {
|
|
79
|
+
segment: createSegmentMode(config.advanced.splitMixedContent),
|
|
80
|
+
}
|
|
81
|
+
this.internal = new Internal(this)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
override async connect(): Promise<void> {
|
|
85
|
+
this.validate()
|
|
86
|
+
const transport = this.createTransport()
|
|
87
|
+
this.transport = transport
|
|
88
|
+
try {
|
|
89
|
+
await transport.start()
|
|
90
|
+
} catch (error) {
|
|
91
|
+
this.transport = undefined
|
|
92
|
+
throw error
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
override async disconnect(): Promise<void> {
|
|
97
|
+
const transport = this.transport
|
|
98
|
+
this.transport = undefined
|
|
99
|
+
await transport?.stop()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolve one outbound resource.
|
|
104
|
+
*
|
|
105
|
+
* OneBot has no upload endpoint: an image, record or video segment carries its source, which the implementation
|
|
106
|
+
* fetches itself. A `<file>` needs a path on the implementation's host, so a local `file:` source is used directly
|
|
107
|
+
* and anything else is handed to `download_file`.
|
|
108
|
+
*/
|
|
109
|
+
override async upload(
|
|
110
|
+
ref: ResourceRef,
|
|
111
|
+
_scope: string,
|
|
112
|
+
_ctx: PrepareContext,
|
|
113
|
+
): Promise<ResolvedResource> {
|
|
114
|
+
if (ref.kind !== 'file') return { key: normalizeSource(ref.src) }
|
|
115
|
+
if (ref.src.startsWith('file:')) {
|
|
116
|
+
return { key: fileURLToPath(ref.src) }
|
|
117
|
+
}
|
|
118
|
+
const downloaded: string | undefined = await this.internal.downloadFile(
|
|
119
|
+
ref.src,
|
|
120
|
+
)
|
|
121
|
+
if (downloaded === undefined) {
|
|
122
|
+
throw new PlatformError(
|
|
123
|
+
'not-found',
|
|
124
|
+
`onebot: download_file returned no path for ${ref.src}`,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
return { key: downloaded }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override resourceScope(_target: Target, _kind: ResourceKind): string {
|
|
131
|
+
return this.id
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
override async sendPayload(
|
|
135
|
+
payload: unknown,
|
|
136
|
+
target: Target,
|
|
137
|
+
ctx: SendContext,
|
|
138
|
+
): Promise<SentPart> {
|
|
139
|
+
return await sendPayload(
|
|
140
|
+
this.sendDeps(),
|
|
141
|
+
payload as OneBotPayload,
|
|
142
|
+
target,
|
|
143
|
+
ctx,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
override async deletePart(part: SentPart): Promise<void> {
|
|
148
|
+
await deletePart(this.sendDeps(), part)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
override async members(
|
|
152
|
+
chat: ChatRef,
|
|
153
|
+
_cursor?: string,
|
|
154
|
+
_limit?: number,
|
|
155
|
+
): Promise<MembersPage> {
|
|
156
|
+
return await members(this.sendDeps(), chat)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
override async getMessage(
|
|
160
|
+
chat: ChatRef,
|
|
161
|
+
id: string,
|
|
162
|
+
): Promise<InboundMessage> {
|
|
163
|
+
return await getMessage(this.sendDeps(), this, chat, id)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override async createReaction(
|
|
167
|
+
message: MessageRef,
|
|
168
|
+
emoji: string,
|
|
169
|
+
): Promise<void> {
|
|
170
|
+
await createReaction(this.sendDeps(), message, emoji)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
override async deleteReaction(
|
|
174
|
+
message: MessageRef,
|
|
175
|
+
emoji: string,
|
|
176
|
+
): Promise<void> {
|
|
177
|
+
await deleteReaction(this.sendDeps(), message, emoji)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override classify(error: unknown) {
|
|
181
|
+
return classifyOneBotError(error)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private sendDeps(): OneBotSendDeps {
|
|
185
|
+
return { internal: this.internal }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Reject a configuration the selected transport cannot work from; such a failure is not retryable. */
|
|
189
|
+
private validate(): void {
|
|
190
|
+
const { protocol, endpoint } = this.config
|
|
191
|
+
if (protocol === 'ws-reverse') return
|
|
192
|
+
if (endpoint === '') {
|
|
193
|
+
throw this.fail(
|
|
194
|
+
`onebot: protocol "${protocol}" needs endpoint (the implementation's ${protocol === 'ws' ? 'ws' : 'http'}:// URL)`,
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
let url: URL
|
|
198
|
+
try {
|
|
199
|
+
url = new URL(endpoint)
|
|
200
|
+
} catch {
|
|
201
|
+
throw this.fail(`onebot: endpoint "${endpoint}" is not a valid URL`)
|
|
202
|
+
}
|
|
203
|
+
const accepted = protocol === 'ws' ? ['ws:', 'wss:'] : ['http:', 'https:']
|
|
204
|
+
if (!accepted.includes(url.protocol)) {
|
|
205
|
+
throw this.fail(
|
|
206
|
+
`onebot: endpoint "${endpoint}" must be a ${accepted.join(' or ')} URL for protocol "${protocol}"`,
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private fail(message: string): Error {
|
|
212
|
+
this.ctx.logger.error(message)
|
|
213
|
+
return new Error(message)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private createTransport(): OneBotTransport {
|
|
217
|
+
switch (this.config.protocol) {
|
|
218
|
+
case 'ws':
|
|
219
|
+
return new OneBotWsClient(this)
|
|
220
|
+
case 'ws-reverse':
|
|
221
|
+
return new OneBotWsServer(this)
|
|
222
|
+
case 'http':
|
|
223
|
+
return new OneBotHttp(this)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { Config }
|
|
229
|
+
|
|
230
|
+
export default OneBotBot
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery'
|
|
2
|
+
|
|
3
|
+
/** How the adapter carries OneBot 11: which side opens the connection. */
|
|
4
|
+
export type OneBotProtocol = 'http' | 'ws' | 'ws-reverse'
|
|
5
|
+
|
|
6
|
+
/** One OneBot 11 account. */
|
|
7
|
+
export interface Config {
|
|
8
|
+
/** The account the implementation reports as `get_login_info.user_id`. */
|
|
9
|
+
selfId: string
|
|
10
|
+
/** Access token: `Authorization: Bearer` outbound, checked on inbound transports. */
|
|
11
|
+
token: string
|
|
12
|
+
/** HMAC-SHA1 key of the `X-Signature` header of `protocol: 'http'` event reports. */
|
|
13
|
+
secret: string
|
|
14
|
+
protocol: OneBotProtocol
|
|
15
|
+
/** Implementation endpoint of the `ws` / `http` transports. */
|
|
16
|
+
endpoint: string
|
|
17
|
+
/** Inbound route of the `ws-reverse` / `http` transports. */
|
|
18
|
+
path: string
|
|
19
|
+
ws: {
|
|
20
|
+
/** Fast-retry budget of the forward WebSocket reconnect loop; it never gives up. */
|
|
21
|
+
retryTimes: number
|
|
22
|
+
/** Delay between dials while the fast-retry budget lasts. */
|
|
23
|
+
retryInterval: number
|
|
24
|
+
/** Delay between dials once the fast-retry budget is spent. */
|
|
25
|
+
retryLazy: number
|
|
26
|
+
/** How long one action waits for its answer. */
|
|
27
|
+
responseTimeout: number
|
|
28
|
+
}
|
|
29
|
+
advanced: {
|
|
30
|
+
/** Pad a space around mixed text and images, as the upstream adapter does. */
|
|
31
|
+
splitMixedContent: boolean
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Validated OneBot 11 adapter configuration. */
|
|
36
|
+
export const Config: z<Config> = z.object({
|
|
37
|
+
selfId: z.string().required(),
|
|
38
|
+
token: z.string().role('secret').default(''),
|
|
39
|
+
secret: z.string().role('secret').default(''),
|
|
40
|
+
protocol: z.union(['http', 'ws', 'ws-reverse']).default('ws-reverse'),
|
|
41
|
+
endpoint: z.string().role('url').default(''),
|
|
42
|
+
path: z.string().default('/onebot'),
|
|
43
|
+
ws: z
|
|
44
|
+
.object({
|
|
45
|
+
retryTimes: z.natural().default(6),
|
|
46
|
+
retryInterval: z.natural().role('ms').default(5_000),
|
|
47
|
+
retryLazy: z.natural().role('ms').default(60_000),
|
|
48
|
+
responseTimeout: z.natural().role('ms').default(60_000),
|
|
49
|
+
})
|
|
50
|
+
.default({}),
|
|
51
|
+
advanced: z
|
|
52
|
+
.object({
|
|
53
|
+
splitMixedContent: z.boolean().default(true),
|
|
54
|
+
})
|
|
55
|
+
.default({}),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Normalize an inbound route path: absolute, no trailing slash.
|
|
60
|
+
* @param path - the configured `path`.
|
|
61
|
+
* @returns the pathname to register.
|
|
62
|
+
*/
|
|
63
|
+
export function routePath(path: string): string {
|
|
64
|
+
const withSlash = path.startsWith('/') ? path : `/${path}`
|
|
65
|
+
return withSlash.length > 1 ? withSlash.replace(/\/+$/, '') : withSlash
|
|
66
|
+
}
|
package/src/cqcode.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Dict } from '@deepseek-ai/cosmokit'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One message segment of a string-format message.
|
|
5
|
+
*
|
|
6
|
+
* `data` is the segment's parameters, unescaped; a `text` segment carries `data.text`. `capture` is the match of the
|
|
7
|
+
* upstream parser and stays on the shape the migrated `types.ts` imports.
|
|
8
|
+
*/
|
|
9
|
+
export interface CQCode {
|
|
10
|
+
type: string
|
|
11
|
+
data: Dict<string>
|
|
12
|
+
capture?: RegExpExecArray
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Segment types are `\w+` in CQ code; anything else is literal text. */
|
|
16
|
+
const TYPE = /^[A-Za-z0-9_.-]+$/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Undo the CQ code escapes of text outside segments and of one parameter value.
|
|
20
|
+
* @param source - escaped text.
|
|
21
|
+
* @returns the text with `[`, `]`, `,` and `&` restored.
|
|
22
|
+
*/
|
|
23
|
+
export function unescapeCQ(source: string): string {
|
|
24
|
+
return source
|
|
25
|
+
.replaceAll('[', '[')
|
|
26
|
+
.replaceAll(']', ']')
|
|
27
|
+
.replaceAll(',', ',')
|
|
28
|
+
.replaceAll('&', '&')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Parse the parameter list after `[CQ:type`; a value may itself contain `=`. */
|
|
32
|
+
function parseParams(body: string): Dict<string> {
|
|
33
|
+
const data: Dict<string> = {}
|
|
34
|
+
if (body === '') return data
|
|
35
|
+
for (const pair of body.split(',')) {
|
|
36
|
+
const equals = pair.indexOf('=')
|
|
37
|
+
if (equals <= 0) continue
|
|
38
|
+
data[pair.slice(0, equals)] = unescapeCQ(pair.slice(equals + 1))
|
|
39
|
+
}
|
|
40
|
+
return data
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parse a string-format (CQ code) message into segments.
|
|
45
|
+
*
|
|
46
|
+
* Text outside segments becomes a `text` segment with its escapes undone. A `[CQ:` that does not open a well-formed
|
|
47
|
+
* segment stays literal text. Only the first `]` closes a segment: `]` inside a value is escaped as `]`.
|
|
48
|
+
*
|
|
49
|
+
* @param source - the raw `message` string (or `raw_message`).
|
|
50
|
+
* @returns the segments in order; empty for an empty input.
|
|
51
|
+
*/
|
|
52
|
+
export function parseCqCode(source: string): CQCode[] {
|
|
53
|
+
const segments: CQCode[] = []
|
|
54
|
+
let cursor = 0
|
|
55
|
+
let search = 0
|
|
56
|
+
|
|
57
|
+
const flushText = (end: number): void => {
|
|
58
|
+
if (end <= cursor) return
|
|
59
|
+
const text = unescapeCQ(source.slice(cursor, end))
|
|
60
|
+
if (text !== '') segments.push({ type: 'text', data: { text } })
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
while (search < source.length) {
|
|
64
|
+
const start = source.indexOf('[CQ:', search)
|
|
65
|
+
if (start < 0) break
|
|
66
|
+
const end = source.indexOf(']', start + 4)
|
|
67
|
+
if (end < 0) break
|
|
68
|
+
const body = source.slice(start + 4, end)
|
|
69
|
+
const comma = body.indexOf(',')
|
|
70
|
+
const type = comma < 0 ? body : body.slice(0, comma)
|
|
71
|
+
if (!TYPE.test(type)) {
|
|
72
|
+
search = start + 4
|
|
73
|
+
continue
|
|
74
|
+
}
|
|
75
|
+
flushText(start)
|
|
76
|
+
segments.push({
|
|
77
|
+
type,
|
|
78
|
+
data: parseParams(comma < 0 ? '' : body.slice(comma + 1)),
|
|
79
|
+
})
|
|
80
|
+
cursor = end + 1
|
|
81
|
+
search = cursor
|
|
82
|
+
}
|
|
83
|
+
flushText(source.length)
|
|
84
|
+
return segments
|
|
85
|
+
}
|