@mrlingxd/koishi-plugin-adapter-onebot 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/lib/types.js ADDED
@@ -0,0 +1,409 @@
1
+ export var SafetyLevel;
2
+ (function (SafetyLevel) {
3
+ SafetyLevel[SafetyLevel["safe"] = 0] = "safe";
4
+ SafetyLevel[SafetyLevel["unknown"] = 1] = "unknown";
5
+ SafetyLevel[SafetyLevel["danger"] = 2] = "danger";
6
+ })(SafetyLevel || (SafetyLevel = {}));
7
+ export class TimeoutError extends Error {
8
+ constructor(args, url) {
9
+ super(`Timeout with request ${url}, args: ${JSON.stringify(args)}`);
10
+ Object.defineProperties(this, {
11
+ args: { value: args },
12
+ url: { value: url }
13
+ });
14
+ }
15
+ }
16
+ class SenderError extends Error {
17
+ constructor(args, url, retcode) {
18
+ super(`Error with request ${url}, args: ${JSON.stringify(args)}, retcode: ${retcode}`);
19
+ Object.defineProperties(this, {
20
+ code: { value: retcode },
21
+ args: { value: args },
22
+ url: { value: url }
23
+ });
24
+ }
25
+ }
26
+ export class Internal {
27
+ bot;
28
+ constructor(bot) {
29
+ this.bot = bot;
30
+ }
31
+ async _get(action, params = {}) {
32
+ this.bot.logger.debug("[request] %s %o", action, params);
33
+ const response = await this._request(action, params);
34
+ this.bot.logger.debug("[response] %o", response);
35
+ const { data, retcode } = response;
36
+ if (retcode === 0)
37
+ return data;
38
+ throw new SenderError(params, action, retcode);
39
+ }
40
+ async setGroupAnonymousBan(group_id, meta, duration) {
41
+ const args = { group_id, duration };
42
+ args[typeof meta === "string" ? "flag" : "anonymous"] = meta;
43
+ await this._get("set_group_anonymous_ban", args);
44
+ }
45
+ async setGroupAnonymousBanAsync(group_id, meta, duration) {
46
+ const args = { group_id, duration };
47
+ args[typeof meta === "string" ? "flag" : "anonymous"] = meta;
48
+ await this._get("set_group_anonymous_ban_async", args);
49
+ }
50
+ // Messages
51
+ async sendPrivateMsg(user_id, message, auto_escape) {
52
+ const data = await this._get("send_private_msg", { user_id, message, auto_escape });
53
+ return data.message_id;
54
+ }
55
+ async sendPrivateMsgAsync(user_id, message, auto_escape) {
56
+ await this._get("send_private_msg_async", { user_id, message, auto_escape });
57
+ }
58
+ async sendGroupMsg(group_id, message, auto_escape) {
59
+ const data = await this._get("send_group_msg", { group_id, message, auto_escape });
60
+ return data.message_id;
61
+ }
62
+ async sendGroupMsgAsync(group_id, message, auto_escape) {
63
+ await this._get("send_group_msg_async", { group_id, message, auto_escape });
64
+ }
65
+ async sendGroupForwardMsg(group_id, messages) {
66
+ const data = await this._get("send_group_forward_msg", { group_id, messages });
67
+ return data.message_id;
68
+ }
69
+ async sendGroupForwardMsgAsync(group_id, messages) {
70
+ await this._get("send_group_forward_msg_async", { group_id, messages });
71
+ }
72
+ async sendPrivateForwardMsg(user_id, messages) {
73
+ const data = await this._get("send_private_forward_msg", { user_id, messages });
74
+ return data.message_id;
75
+ }
76
+ async sendPrivateForwardMsgAsync(user_id, messages) {
77
+ await this._get("send_private_forward_msg_async", { user_id, messages });
78
+ }
79
+ async deleteMsg(message_id) {
80
+ await this._get("delete_msg", { message_id });
81
+ }
82
+ async deleteMsgAsync(message_id) {
83
+ await this._get("delete_msg_async", { message_id });
84
+ }
85
+ async setEssenceMsg(message_id) {
86
+ await this._get("set_essence_msg", { message_id });
87
+ }
88
+ async setEssenceMsgAsync(message_id) {
89
+ await this._get("set_essence_msg_async", { message_id });
90
+ }
91
+ async deleteEssenceMsg(message_id) {
92
+ await this._get("delete_essence_msg", { message_id });
93
+ }
94
+ async deleteEssenceMsgAsync(message_id) {
95
+ await this._get("delete_essence_msg_async", { message_id });
96
+ }
97
+ async markMsgAsRead(message_id) {
98
+ await this._get("mark_msg_as_read", { message_id });
99
+ }
100
+ async sendLike(user_id, times) {
101
+ await this._get("send_like", { user_id, times });
102
+ }
103
+ async sendLikeAsync(user_id, times) {
104
+ await this._get("send_like_async", { user_id, times });
105
+ }
106
+ async sendGroupSign(group_id) {
107
+ await this._get("send_group_sign", { group_id });
108
+ }
109
+ async sendGroupSignAsync(group_id) {
110
+ await this._get("send_group_sign_async", { group_id });
111
+ }
112
+ async getMsg(message_id) {
113
+ return await this._get("get_msg", { message_id });
114
+ }
115
+ async getForwardMsg(message_id) {
116
+ const data = await this._get("get_forward_msg", { message_id });
117
+ return data.messages;
118
+ }
119
+ async getEssenceMsgList(group_id) {
120
+ return await this._get("get_essence_msg_list", { group_id });
121
+ }
122
+ async getWordSlices(content) {
123
+ const data = await this._get(".get_word_slices", { content });
124
+ return data.slices;
125
+ }
126
+ async ocrImage(image) {
127
+ return await this._get("ocr_image", { image });
128
+ }
129
+ async getGroupMsgHistory(group_id, message_seq) {
130
+ return await this._get("get_group_msg_history", { group_id, message_seq });
131
+ }
132
+ async deleteFriend(user_id) {
133
+ await this._get("delete_friend", { user_id });
134
+ }
135
+ async deleteFriendAsync(user_id) {
136
+ await this._get("delete_friend_async", { user_id });
137
+ }
138
+ async deleteUnidirectionalFriend(user_id) {
139
+ await this._get("delete_unidirectional_friend", { user_id });
140
+ }
141
+ async deleteUnidirectionalFriendAsync(user_id) {
142
+ await this._get("delete_unidirectional_friend_async", { user_id });
143
+ }
144
+ async setFriendAddRequest(flag, approve, remark) {
145
+ await this._get("set_friend_add_request", { flag, approve, remark });
146
+ }
147
+ async setFriendAddRequestAsync(flag, approve, remark) {
148
+ await this._get("set_friend_add_request_async", { flag, approve, remark });
149
+ }
150
+ async setGroupAddRequest(flag, subType, approve, reason) {
151
+ await this._get("set_group_add_request", { flag, sub_type: subType, approve, reason });
152
+ }
153
+ async setGroupAddRequestAsync(flag, subType, approve, reason) {
154
+ await this._get("set_group_add_request_async", { flag, sub_type: subType, approve, reason });
155
+ }
156
+ // Group operations
157
+ async setGroupKick(group_id, user_id, reject_add_request) {
158
+ await this._get("set_group_kick", { group_id, user_id, reject_add_request });
159
+ }
160
+ async setGroupKickAsync(group_id, user_id, reject_add_request) {
161
+ await this._get("set_group_kick_async", { group_id, user_id, reject_add_request });
162
+ }
163
+ async setGroupBan(group_id, user_id, duration) {
164
+ await this._get("set_group_ban", { group_id, user_id, duration });
165
+ }
166
+ async setGroupBanAsync(group_id, user_id, duration) {
167
+ await this._get("set_group_ban_async", { group_id, user_id, duration });
168
+ }
169
+ async setGroupWholeBan(group_id, enable) {
170
+ await this._get("set_group_whole_ban", { group_id, enable });
171
+ }
172
+ async setGroupWholeBanAsync(group_id, enable) {
173
+ await this._get("set_group_whole_ban_async", { group_id, enable });
174
+ }
175
+ async setGroupAdmin(group_id, user_id, enable) {
176
+ await this._get("set_group_admin", { group_id, user_id, enable });
177
+ }
178
+ async setGroupAdminAsync(group_id, user_id, enable) {
179
+ await this._get("set_group_admin_async", { group_id, user_id, enable });
180
+ }
181
+ async setGroupAnonymous(group_id, enable) {
182
+ await this._get("set_group_anonymous", { group_id, enable });
183
+ }
184
+ async setGroupAnonymousAsync(group_id, enable) {
185
+ await this._get("set_group_anonymous_async", { group_id, enable });
186
+ }
187
+ async setGroupCard(group_id, user_id, card) {
188
+ await this._get("set_group_card", { group_id, user_id, card });
189
+ }
190
+ async setGroupCardAsync(group_id, user_id, card) {
191
+ await this._get("set_group_card_async", { group_id, user_id, card });
192
+ }
193
+ async setGroupLeave(group_id, is_dismiss) {
194
+ await this._get("set_group_leave", { group_id, is_dismiss });
195
+ }
196
+ async setGroupLeaveAsync(group_id, is_dismiss) {
197
+ await this._get("set_group_leave_async", { group_id, is_dismiss });
198
+ }
199
+ async setGroupSpecialTitle(group_id, user_id, special_title, duration) {
200
+ await this._get("set_group_special_title", { group_id, user_id, special_title, duration });
201
+ }
202
+ async setGroupSpecialTitleAsync(group_id, user_id, special_title, duration) {
203
+ await this._get("set_group_special_title_async", { group_id, user_id, special_title, duration });
204
+ }
205
+ async setGroupName(group_id, name) {
206
+ await this._get("set_group_name", { group_id, group_name: name });
207
+ }
208
+ async setGroupNameAsync(group_id, name) {
209
+ await this._get("set_group_name_async", { group_id, group_name: name });
210
+ }
211
+ async setGroupPortrait(group_id, file, cache) {
212
+ await this._get("set_group_portrait", { group_id, file, cache });
213
+ }
214
+ async setGroupPortraitAsync(group_id, file, cache) {
215
+ await this._get("set_group_portrait_async", { group_id, file, cache });
216
+ }
217
+ async getGroupAtAllRemain(group_id) {
218
+ return await this._get("get_group_at_all_remain", { group_id });
219
+ }
220
+ async sendGroupNotice(group_id, content, image, pinned, confirm_required) {
221
+ await this._get("_send_group_notice", { group_id, content, image, pinned, confirm_required });
222
+ }
223
+ async sendGroupNoticeAsync(group_id, content, image, pinned, confirm_required) {
224
+ await this._get("_send_group_notice_async", { group_id, content, image, pinned, confirm_required });
225
+ }
226
+ async getGroupNotice(group_id) {
227
+ return await this._get("_get_group_notice", { group_id });
228
+ }
229
+ async delGroupNotice(group_id, notice_id) {
230
+ await this._get("_del_group_notice", { group_id, notice_id });
231
+ }
232
+ // Accounts
233
+ async getLoginInfo() {
234
+ return await this._get("get_login_info");
235
+ }
236
+ async qidianGetLoginInfo() {
237
+ return await this._get("qidian_get_login_info");
238
+ }
239
+ async setQqProfile(nickname, company, email, college, personal_note) {
240
+ await this._get("set_qq_profile", { nickname, company, email, college, personal_note });
241
+ }
242
+ async setQqProfileAsync(nickname, company, email, college, personal_note) {
243
+ await this._get("set_qq_profile_async", { nickname, company, email, college, personal_note });
244
+ }
245
+ async setQqAvatar(file) {
246
+ await this._get("set_qq_avatar", { file });
247
+ }
248
+ async setOnlineStatus(status, extStatus, batteryStatus) {
249
+ await this._get("set_online_status", { status, ext_status: extStatus, battery_status: batteryStatus });
250
+ }
251
+ async getVipInfo() {
252
+ return await this._get("_get_vip_info");
253
+ }
254
+ async getStrangerInfo(user_id, no_cache) {
255
+ return await this._get("get_stranger_info", { user_id, no_cache });
256
+ }
257
+ async getFriendList() {
258
+ return await this._get("get_friend_list");
259
+ }
260
+ async getUnidirectionalFriendList() {
261
+ return await this._get("get_unidirectional_friend_list");
262
+ }
263
+ async getGroupInfo(group_id, no_cache) {
264
+ return await this._get("get_group_info", { group_id, no_cache });
265
+ }
266
+ async getGroupList(no_cache) {
267
+ return await this._get("get_group_list", { no_cache });
268
+ }
269
+ async getGroupMemberInfo(group_id, user_id, no_cache) {
270
+ return await this._get("get_group_member_info", { group_id, user_id, no_cache });
271
+ }
272
+ async getGroupMemberList(group_id, no_cache) {
273
+ return await this._get("get_group_member_list", { group_id, no_cache });
274
+ }
275
+ async getGroupHonorInfo(group_id, type) {
276
+ return await this._get("get_group_honor_info", { group_id, type });
277
+ }
278
+ async getGroupSystemMsg() {
279
+ return await this._get("get_group_system_msg");
280
+ }
281
+ // Files
282
+ async getGroupFileSystemInfo(group_id) {
283
+ return await this._get("get_group_file_system_info", { group_id });
284
+ }
285
+ async getGroupRootFiles(group_id) {
286
+ return await this._get("get_group_root_files", { group_id });
287
+ }
288
+ async getGroupFilesByFolder(group_id, folder_id) {
289
+ return await this._get("get_group_files_by_folder", { group_id, folder_id });
290
+ }
291
+ async getGroupFileUrl(group_id, file_id, busid) {
292
+ const data = await this._get("get_group_file_url", { group_id, file_id, busid });
293
+ return data.url;
294
+ }
295
+ async downloadFile(url, headers, thread_count) {
296
+ const data = await this._get("download_file", { url, headers, thread_count });
297
+ return data.file;
298
+ }
299
+ async uploadPrivateFile(user_id, file, name) {
300
+ await this._get("upload_private_file", { user_id, file, name });
301
+ }
302
+ async uploadGroupFile(group_id, file, name, folder) {
303
+ await this._get("upload_group_file", { group_id, file, name, folder });
304
+ }
305
+ async createGroupFileFolder(group_id, folder_id, name) {
306
+ await this._get("create_group_file_folder", { group_id, folder_id, name });
307
+ }
308
+ async deleteGroupFolder(group_id, folder_id) {
309
+ await this._get("delete_group_folder", { group_id, folder_id });
310
+ }
311
+ async deleteGroupFile(group_id, folder_id, file_id, busid) {
312
+ await this._get("delete_group_file", { group_id, folder_id, file_id, busid });
313
+ }
314
+ async getOnlineClients(no_cache) {
315
+ const data = await this._get("get_online_clients", { no_cache });
316
+ return data.clients;
317
+ }
318
+ async checkUrlSafely(url) {
319
+ const data = await this._get("check_url_safely", { url });
320
+ return data.level;
321
+ }
322
+ async getModelShow(model) {
323
+ const data = await this._get("_get_model_show", { model });
324
+ return data.variants;
325
+ }
326
+ async setModelShow(model, model_show) {
327
+ await this._get("_set_model_show", { model, model_show });
328
+ }
329
+ async getCookies(domain) {
330
+ const data = await this._get("get_cookies", { domain });
331
+ return data.cookies;
332
+ }
333
+ async getCsrfToken() {
334
+ const data = await this._get("get_csrf_token");
335
+ return data.token;
336
+ }
337
+ async getCredentials(domain) {
338
+ return await this._get("get_credentials", { domain });
339
+ }
340
+ async getRecord(file, out_format, full_path) {
341
+ return await this._get("get_record", { file, out_format, full_path });
342
+ }
343
+ async getImage(file) {
344
+ return await this._get("get_image", { file });
345
+ }
346
+ async canSendImage() {
347
+ const data = await this._get("can_send_image");
348
+ return data.yes;
349
+ }
350
+ async canSendRecord() {
351
+ const data = await this._get("can_send_record");
352
+ return data.yes;
353
+ }
354
+ async getStatus() {
355
+ return await this._get("get_status");
356
+ }
357
+ async getVersionInfo() {
358
+ return await this._get("get_version_info");
359
+ }
360
+ async setRestart(delay) {
361
+ await this._get("set_restart", { delay });
362
+ }
363
+ async reloadEventFilter() {
364
+ await this._get("reload_event_filter");
365
+ }
366
+ async cleanCache() {
367
+ await this._get("clean_cache");
368
+ }
369
+ // Guild
370
+ async getGuildServiceProfile() {
371
+ return await this._get("get_guild_service_profile");
372
+ }
373
+ async getGuildList() {
374
+ return await this._get("get_guild_list");
375
+ }
376
+ async getGuildMetaByGuest(guild_id) {
377
+ return await this._get("get_guild_meta_by_guest", { guild_id });
378
+ }
379
+ async getGuildChannelList(guild_id, no_cache) {
380
+ return await this._get("get_guild_channel_list", { guild_id, no_cache });
381
+ }
382
+ async getGuildMemberList(guild_id, next_token) {
383
+ return await this._get("get_guild_member_list", { guild_id, next_token });
384
+ }
385
+ async getGuildMemberProfile(guild_id, user_id) {
386
+ return await this._get("get_guild_member_profile", { guild_id, user_id });
387
+ }
388
+ async sendGuildChannelMsg(guild_id, channel_id, message) {
389
+ const data = await this._get("send_guild_channel_msg", { guild_id, channel_id, message });
390
+ return data.message_id;
391
+ }
392
+ // Lagrange specific
393
+ async uploadImage(file) {
394
+ return await this._get("upload_image", { file });
395
+ }
396
+ async getPrivateFileUrl(user_id, file_id, file_hash) {
397
+ const data = await this._get("get_private_file_url", { user_id, file_id, file_hash });
398
+ return data.url;
399
+ }
400
+ async moveGroupFile(group_id, file_id, parent_directory, target_directory) {
401
+ await this._get("move_group_file", { group_id, file_id, parent_directory, target_directory });
402
+ }
403
+ async deleteGroupFileFolder(group_id, folder_id) {
404
+ await this._get("delete_group_file_folder", { group_id, folder_id });
405
+ }
406
+ async renameGroupFileFolder(group_id, folder_id, new_folder_name) {
407
+ await this._get("rename_group_file_folder", { group_id, folder_id, new_folder_name });
408
+ }
409
+ }
package/lib/utils.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { Universal } from "koishi";
2
+ import { BaseBot } from "./bot";
3
+ import * as OneBot from "./types";
4
+ export * from "./types";
5
+ export declare const decodeUser: (user: OneBot.AccountInfo) => Universal.User;
6
+ export declare const decodeGuildMember: (user: OneBot.SenderInfo) => Universal.GuildMember;
7
+ export declare const adaptQQGuildMemberInfo: (user: OneBot.GuildMemberInfo) => Universal.GuildMember;
8
+ export declare const adaptQQGuildMemberProfile: (user: OneBot.GuildMemberProfile) => Universal.GuildMember;
9
+ export declare function adaptMessage(bot: BaseBot, data: OneBot.Message, message?: Universal.Message, payload?: Universal.MessageLike): Promise<Universal.Message>;
10
+ export declare const adaptGuild: (info: OneBot.GroupInfo | OneBot.GuildBaseInfo) => Universal.Guild;
11
+ export declare const adaptChannel: (info: OneBot.GroupInfo | OneBot.ChannelInfo) => Universal.Channel;
12
+ export declare function dispatchSession(bot: BaseBot, data: OneBot.Payload): Promise<void>;
13
+ export declare function adaptSession(bot: BaseBot, data: OneBot.Payload): Promise<import("koishi").Session<never, never, import("koishi").Context>>;