@kotori-bot/kotori-plugin-adapter-onebot 1.2.1 → 2.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/lib/adapter.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Adapter, AdapterConfig, Context, EventDataApiBase, EventDataTargetId, Tsu } from 'kotori-bot';
1
+ import { Adapters, AdapterConfig, Context, EventDataApiBase, EventDataTargetId, Tsu } from 'kotori-bot';
2
+ import OnebotApi from './api';
2
3
  import { EventDataType } from './types';
3
4
  interface EventDataPoke extends EventDataApiBase {
4
5
  targetId: EventDataTargetId;
@@ -9,18 +10,18 @@ declare module 'kotori-bot' {
9
10
  poke(session: EventDataPoke): void;
10
11
  }
11
12
  }
12
- export declare const config: import("kotori-bot").IntersectionParser<[import("kotori-bot").ObjectParser<{
13
+ export declare const config: import("kotori-bot").UnionParser<[import("kotori-bot").ObjectParser<{
14
+ mode: import("kotori-bot").LiteralParser<"ws">;
13
15
  port: import("kotori-bot").NumberParser;
14
16
  address: import("kotori-bot").StringParser;
15
17
  retry: import("kotori-bot").NumberParser;
16
- }>, import("kotori-bot").UnionParser<[import("kotori-bot").ObjectParser<{
17
- mode: import("kotori-bot").LiteralParser<"ws">;
18
18
  }>, import("kotori-bot").ObjectParser<{
19
19
  mode: import("kotori-bot").LiteralParser<"ws-reverse">;
20
- }>]>]>;
20
+ }>]>;
21
21
  type OnebotConfig = Tsu.infer<typeof config> & AdapterConfig;
22
- export declare class OnebotAdapter extends Adapter {
22
+ export declare class OnebotAdapter extends Adapters.WebSocket<OnebotApi> {
23
23
  private readonly address;
24
+ private readonly isReverse;
24
25
  readonly config: OnebotConfig;
25
26
  constructor(ctx: Context, config: OnebotConfig, identity: string);
26
27
  handle(data: EventDataType): void;
@@ -28,7 +29,6 @@ export declare class OnebotAdapter extends Adapter {
28
29
  stop(): void;
29
30
  send(action: string, params?: object): void;
30
31
  private socket;
31
- private connectWss;
32
32
  private onlineTimerId;
33
33
  }
34
34
  export {};
package/lib/adapter.js CHANGED
@@ -1,241 +1,232 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/kotori-plugin-adapter-onebot
4
+ * @Version 2.0.0
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/7 21:36:06
10
+ */
11
+
1
12
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ var __create = Object.create;
14
+ var __defProp = Object.defineProperty;
15
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
16
+ var __getOwnPropNames = Object.getOwnPropertyNames;
17
+ var __getProtoOf = Object.getPrototypeOf;
18
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
4
22
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OnebotAdapter = exports.config = void 0;
7
- /*
8
- * @Author: Hotaru biyuehuya@gmail.com
9
- * @Blog: https://hotaru.icu
10
- * @Date: 2023-09-29 14:31:09
11
- * @LastEditors: Hotaru biyuehuya@gmail.com
12
- * @LastEditTime: 2024-02-16 15:33:09
13
- */
14
- const kotori_bot_1 = require("kotori-bot");
15
- const ws_1 = __importDefault(require("ws"));
16
- const api_1 = __importDefault(require("./api"));
17
- const wsserver_1 = __importDefault(require("./services/wsserver"));
18
- const elements_1 = __importDefault(require("./elements"));
19
- exports.config = kotori_bot_1.Tsu.Intersection([
20
- kotori_bot_1.Tsu.Object({
21
- port: kotori_bot_1.Tsu.Number().int().range(1, 65535),
22
- address: kotori_bot_1.Tsu.String()
23
- .regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)
24
- .default('ws://127.0.0.1'),
25
- retry: kotori_bot_1.Tsu.Number().int().min(1).default(10)
26
- }),
27
- kotori_bot_1.Tsu.Union([
28
- kotori_bot_1.Tsu.Object({
29
- mode: kotori_bot_1.Tsu.Literal('ws')
30
- }),
31
- kotori_bot_1.Tsu.Object({
32
- mode: kotori_bot_1.Tsu.Literal('ws-reverse')
33
- })
34
- ])
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+ var adapter_exports = {};
41
+ __export(adapter_exports, {
42
+ OnebotAdapter: () => OnebotAdapter,
43
+ config: () => config
44
+ });
45
+ module.exports = __toCommonJS(adapter_exports);
46
+ var import_kotori_bot = require("kotori-bot");
47
+ var import_ws = __toESM(require("ws"));
48
+ var import_api = __toESM(require("./api"));
49
+ var import_elements = __toESM(require("./elements"));
50
+ const config = import_kotori_bot.Tsu.Union([
51
+ import_kotori_bot.Tsu.Object({
52
+ mode: import_kotori_bot.Tsu.Literal("ws"),
53
+ port: import_kotori_bot.Tsu.Number().int().range(1, 65535),
54
+ address: import_kotori_bot.Tsu.String().regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/).default("ws://127.0.0.1"),
55
+ retry: import_kotori_bot.Tsu.Number().int().min(1).default(10)
56
+ }),
57
+ import_kotori_bot.Tsu.Object({
58
+ mode: import_kotori_bot.Tsu.Literal("ws-reverse")
59
+ })
35
60
  ]);
36
- const handleMsg = (msg) => msg.replace(/\[CQ:at,qq=(.*?)\]/g, '$1');
37
- class OnebotAdapter extends kotori_bot_1.Adapter {
38
- address;
39
- config;
40
- constructor(ctx, config, identity) {
41
- super(ctx, config, identity, api_1.default, new elements_1.default());
42
- this.config = config;
43
- this.address = `${this.config.address ?? 'ws://127.0.0.1'}:${this.config.port}`;
44
- }
45
- handle(data) {
46
- if (data.post_type === 'message' && data.message_type === 'private') {
47
- this.session('on_message', {
48
- type: kotori_bot_1.MessageScope.PRIVATE,
49
- userId: data.user_id,
50
- messageId: data.message_id,
51
- message: handleMsg(data.message),
52
- sender: {
53
- nickname: data.sender.nickname,
54
- age: data.sender.age,
55
- sex: data.sender.sex
56
- },
57
- groupId: data.group_id
58
- });
59
- }
60
- else if (data.post_type === 'message' && data.message_type === 'group') {
61
- this.session('on_message', {
62
- type: kotori_bot_1.MessageScope.GROUP,
63
- userId: data.user_id,
64
- messageId: data.message_id,
65
- message: handleMsg(data.message),
66
- sender: {
67
- nickname: data.sender.nickname,
68
- age: data.sender.age,
69
- sex: data.sender.sex,
70
- level: data.sender.level,
71
- role: data.sender.role,
72
- title: data.sender.title
73
- },
74
- groupId: data.group_id
75
- });
76
- }
77
- else if (data.post_type === 'notice' && data.notice_type === 'private_recall') {
78
- this.session('on_recall', {
79
- type: kotori_bot_1.MessageScope.PRIVATE,
80
- userId: data.user_id,
81
- messageId: data.message_id
82
- });
83
- }
84
- else if (data.post_type === 'notice' && data.notice_type === 'group_recall') {
85
- this.session('on_recall', {
86
- type: kotori_bot_1.MessageScope.GROUP,
87
- userId: data.user_id,
88
- messageId: data.message_id,
89
- groupId: data.group_id,
90
- operatorId: data.user_id
91
- });
92
- }
93
- else if (data.post_type === 'request' && data.request_type === 'private') {
94
- this.session('on_request', {
95
- type: kotori_bot_1.MessageScope.PRIVATE,
96
- userId: data.user_id
97
- });
98
- }
99
- else if (data.post_type === 'request' && data.request_type === 'group') {
100
- this.session('on_request', {
101
- type: kotori_bot_1.MessageScope.GROUP,
102
- userId: data.user_id,
103
- groupId: data.group_id,
104
- operatorId: data.operator_id || data.user_id
105
- });
106
- }
107
- else if (data.post_type === 'notice' && data.notice_type === 'private_add') {
108
- this.session('on_private_add', {
109
- userId: data.user_id
110
- });
111
- }
112
- else if (data.post_type === 'notice' && data.notice_type === 'group_increase') {
113
- this.session('on_group_increase', {
114
- userId: data.user_id,
115
- groupId: data.group_id,
116
- operatorId: data.operator_id || data.user_id
117
- });
118
- }
119
- else if (data.post_type === 'notice' && data.notice_type === 'group_decrease') {
120
- this.session('on_group_decrease', {
121
- userId: data.user_id,
122
- groupId: data.group_id,
123
- operatorId: data.operator_id || data.user_id
124
- });
125
- }
126
- else if (data.post_type === 'notice' && data.notice_type === 'group_admin') {
127
- this.session('on_group_admin', {
128
- userId: data.user_id,
129
- groupId: data.group_id,
130
- operation: data.sub_type === 'set' ? 'set' : 'unset'
131
- });
132
- }
133
- else if (data.post_type === 'notice' && data.notice_type === 'group_ban') {
134
- this.session('on_group_ban', {
135
- userId: data.user_id,
136
- groupId: data.group_id,
137
- operatorId: data.operator_id,
138
- time: data.duration
139
- });
140
- }
141
- else if (data.post_type === 'meta_event' && data.meta_event_type === 'heartbeat') {
142
- if (data.status.online) {
143
- this.online();
144
- if (this.onlineTimerId)
145
- clearTimeout(this.onlineTimerId);
146
- }
147
- if (this.selfId === -1 && typeof data.self_id === 'number') {
148
- this.selfId = data.self_id;
149
- // this.avatar = `https://q.qlogo.cn/g?b=qq&s=640&nk=${this.selfId}`;
150
- }
151
- }
152
- else if (data.data instanceof Object && typeof data.data.message_id === 'number') {
153
- this.ctx.emit('send', {
154
- api: this.api,
155
- messageId: data.data.message_id
156
- });
157
- }
158
- else if (data.post_type === 'notice' &&
159
- data.notice_type === 'notify' &&
160
- data.sub_type === 'poke' &&
161
- data.target_id) {
162
- this.session('poke', {
163
- userId: data.user_id,
164
- targetId: data.target_id,
165
- groupId: data.group_id
166
- });
167
- }
168
- if (!this.onlineTimerId)
169
- this.onlineTimerId = setTimeout(() => this.offline, 50 * 1000);
170
- }
171
- start() {
172
- if (this.config.mode === 'ws-reverse') {
173
- this.ctx.emit('connect', {
174
- type: 'connect',
175
- mode: 'ws-reverse',
176
- adapter: this,
177
- normal: true,
178
- address: this.address
179
- });
180
- }
181
- this.connectWss();
182
- }
183
- stop() {
184
- this.ctx.emit('connect', {
185
- type: 'disconnect',
186
- adapter: this,
187
- normal: true,
188
- address: this.address,
189
- mode: this.config.mode
190
- });
191
- this.socket?.close();
192
- this.offline();
61
+ const handleMsg = (msg) => msg.replace(/\[CQ:at,qq=(.*?)\]/g, "$1");
62
+ class OnebotAdapter extends import_kotori_bot.Adapters.WebSocket {
63
+ address;
64
+ isReverse;
65
+ config;
66
+ constructor(ctx, config2, identity) {
67
+ super(ctx, config2, identity, import_api.default, new import_elements.default());
68
+ this.config = config2;
69
+ this.address = this.config.mode === "ws" ? `${this.config.address ?? "ws://127.0.0.1"}:${this.config.port}` : "";
70
+ this.isReverse = !this.address;
71
+ if (!this.isReverse) return;
72
+ this.connection = (ws) => {
73
+ this.socket = ws;
74
+ };
75
+ }
76
+ handle(data) {
77
+ if (data.post_type === "message" && data.message_type === "private") {
78
+ this.session("on_message", {
79
+ type: import_kotori_bot.MessageScope.PRIVATE,
80
+ userId: data.user_id,
81
+ messageId: data.message_id,
82
+ message: handleMsg(data.message),
83
+ sender: {
84
+ nickname: data.sender.nickname,
85
+ age: data.sender.age,
86
+ sex: data.sender.sex
87
+ },
88
+ groupId: data.group_id
89
+ });
90
+ } else if (data.post_type === "message" && data.message_type === "group") {
91
+ this.session("on_message", {
92
+ type: import_kotori_bot.MessageScope.GROUP,
93
+ userId: data.user_id,
94
+ messageId: data.message_id,
95
+ message: handleMsg(data.message),
96
+ sender: {
97
+ nickname: data.sender.nickname,
98
+ age: data.sender.age,
99
+ sex: data.sender.sex,
100
+ level: data.sender.level,
101
+ role: data.sender.role,
102
+ title: data.sender.title
103
+ },
104
+ groupId: data.group_id
105
+ });
106
+ } else if (data.post_type === "notice" && data.notice_type === "private_recall") {
107
+ this.session("on_recall", {
108
+ type: import_kotori_bot.MessageScope.PRIVATE,
109
+ userId: data.user_id,
110
+ messageId: data.message_id
111
+ });
112
+ } else if (data.post_type === "notice" && data.notice_type === "group_recall") {
113
+ this.session("on_recall", {
114
+ type: import_kotori_bot.MessageScope.GROUP,
115
+ userId: data.user_id,
116
+ messageId: data.message_id,
117
+ groupId: data.group_id,
118
+ operatorId: data.user_id
119
+ });
120
+ } else if (data.post_type === "request" && data.request_type === "private") {
121
+ this.session("on_request", {
122
+ type: import_kotori_bot.MessageScope.PRIVATE,
123
+ userId: data.user_id
124
+ });
125
+ } else if (data.post_type === "request" && data.request_type === "group") {
126
+ this.session("on_request", {
127
+ type: import_kotori_bot.MessageScope.GROUP,
128
+ userId: data.user_id,
129
+ groupId: data.group_id,
130
+ operatorId: data.operator_id || data.user_id
131
+ });
132
+ } else if (data.post_type === "notice" && data.notice_type === "private_add") {
133
+ this.session("on_private_add", {
134
+ userId: data.user_id
135
+ });
136
+ } else if (data.post_type === "notice" && data.notice_type === "group_increase") {
137
+ this.session("on_group_increase", {
138
+ userId: data.user_id,
139
+ groupId: data.group_id,
140
+ operatorId: data.operator_id || data.user_id
141
+ });
142
+ } else if (data.post_type === "notice" && data.notice_type === "group_decrease") {
143
+ this.session("on_group_decrease", {
144
+ userId: data.user_id,
145
+ groupId: data.group_id,
146
+ operatorId: data.operator_id || data.user_id
147
+ });
148
+ } else if (data.post_type === "notice" && data.notice_type === "group_admin") {
149
+ this.session("on_group_admin", {
150
+ userId: data.user_id,
151
+ groupId: data.group_id,
152
+ operation: data.sub_type === "set" ? "set" : "unset"
153
+ });
154
+ } else if (data.post_type === "notice" && data.notice_type === "group_ban") {
155
+ this.session("on_group_ban", {
156
+ userId: data.user_id,
157
+ groupId: data.group_id,
158
+ operatorId: data.operator_id,
159
+ time: data.duration
160
+ });
161
+ } else if (data.post_type === "meta_event" && data.meta_event_type === "heartbeat") {
162
+ if (data.status.online) {
163
+ this.online();
164
+ if (this.onlineTimerId) clearTimeout(this.onlineTimerId);
165
+ }
166
+ if (this.selfId === -1 && typeof data.self_id === "number") {
167
+ this.selfId = data.self_id;
168
+ }
169
+ } else if (data.data instanceof Object && typeof data.data.message_id === "number") {
170
+ this.ctx.emit("send", {
171
+ api: this.api,
172
+ messageId: data.data.message_id
173
+ });
174
+ } else if (data.post_type === "notice" && data.notice_type === "notify" && data.sub_type === "poke" && data.target_id) {
175
+ this.session("poke", {
176
+ userId: data.user_id,
177
+ targetId: data.target_id,
178
+ groupId: data.group_id
179
+ });
193
180
  }
194
- send(action, params) {
195
- this.socket?.send(JSON.stringify({ action, params }));
181
+ if (!this.onlineTimerId) this.onlineTimerId = setTimeout(() => this.offline(), 50 * 1e3);
182
+ }
183
+ start() {
184
+ if (this.isReverse) {
185
+ this.setup();
186
+ return;
196
187
  }
197
- socket = null;
198
- async connectWss() {
199
- if (this.config.mode === 'ws-reverse') {
200
- const wss = await (0, wsserver_1.default)(this.config.port);
201
- const [socket] = wss;
202
- this.socket = socket;
203
- }
204
- else {
205
- this.ctx.emit('connect', {
206
- type: 'connect',
207
- mode: 'ws',
208
- adapter: this,
209
- normal: true,
210
- address: this.address
211
- });
212
- this.socket = new ws_1.default(`${this.address}`);
213
- this.socket.on('close', () => {
214
- this.ctx.emit('connect', {
215
- type: 'disconnect',
216
- adapter: this,
217
- normal: false,
218
- mode: 'ws',
219
- address: this.address
220
- });
221
- setTimeout(() => {
222
- if (!this.socket)
223
- return;
224
- this.socket.close();
225
- this.ctx.emit('connect', {
226
- type: 'connect',
227
- mode: 'ws-reverse',
228
- adapter: this,
229
- normal: false,
230
- address: this.address
231
- });
232
- this.connectWss();
233
- }, this.config.retry * 1000);
234
- });
235
- }
236
- this.socket.on('message', (data) => this.handle(JSON.parse(data.toString())));
188
+ this.ctx.emit("connect", {
189
+ type: "connect",
190
+ mode: "ws",
191
+ adapter: this,
192
+ normal: true,
193
+ address: this.address
194
+ });
195
+ this.socket = new import_ws.default(`${this.address}`);
196
+ this.socket.on("close", () => {
197
+ this.ctx.emit("connect", {
198
+ type: "disconnect",
199
+ adapter: this,
200
+ normal: false,
201
+ mode: "ws",
202
+ address: this.address
203
+ });
204
+ });
205
+ this.socket.on("message", (raw) => this.handle(JSON.parse(raw.toString())));
206
+ }
207
+ stop() {
208
+ if (this.isReverse) {
209
+ super.stop();
210
+ return;
237
211
  }
238
- /* global NodeJS */
239
- onlineTimerId = null;
212
+ this.ctx.emit("connect", {
213
+ type: "disconnect",
214
+ adapter: this,
215
+ normal: true,
216
+ address: this.address,
217
+ mode: "ws"
218
+ });
219
+ this.socket?.close();
220
+ }
221
+ send(action, params) {
222
+ this.socket?.send(JSON.stringify({ action, params }));
223
+ }
224
+ socket = null;
225
+ /* global NodeJS */
226
+ onlineTimerId = null;
240
227
  }
241
- exports.OnebotAdapter = OnebotAdapter;
228
+ // Annotate the CommonJS export names for ESM import in node:
229
+ 0 && (module.exports = {
230
+ OnebotAdapter,
231
+ config
232
+ });
package/lib/api.js CHANGED
@@ -1,119 +1,147 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnebotApi = void 0;
4
- /*
5
- * @Author: Hotaru biyuehuya@gmail.com
6
- * @Blog: https://hotaru.icu
7
- * @Date: 2023-09-29 14:31:13
8
- * @LastEditors: Hotaru biyuehuya@gmail.com
9
- * @LastEditTime: 2024-02-21 10:40:20
1
+
2
+ /**
3
+ * @Package @kotori-bot/kotori-plugin-adapter-onebot
4
+ * @Version 2.0.0
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/7 21:36:06
10
10
  */
11
- const kotori_bot_1 = require("kotori-bot");
12
- class OnebotApi extends kotori_bot_1.Api {
13
- sendPrivateMsg(message, userId) {
14
- this.adapter.status.lastMsgTime = new Date();
15
- this.adapter.status.sentMsg += 1;
16
- this.adapter.send('send_private_msg', { user_id: userId, message, auto_escape: false });
17
- }
18
- /**
19
- * @description: 发送私聊消息
20
- * @param {Msg} message 要发送的内容
21
- * @param {groupId} groupId 群号
22
- * @return {void}
23
- */
24
- sendGroupMsg(message, groupId) {
25
- this.adapter.status.lastMsgTime = new Date();
26
- this.adapter.status.sentMsg += 1;
27
- this.adapter.send('send_group_msg', { group_id: groupId, message, auto_escape: false });
28
- }
29
- /**
30
- * @description: 撤回消息
31
- * @param {number} messageId 消息id
32
- * @return {void}
33
- */
34
- deleteMsg(messageId) {
35
- this.adapter.send('delete_msg', { messageId });
36
- }
37
- /**
38
- * @description: 设置群名
39
- * @param {number} groupId 群号
40
- * @param {string} groupName 新群名
41
- * @return {void}
42
- */
43
- setGroupName(groupId, groupName) {
44
- this.adapter.send('set_group_name', { group_id: groupId, group_name: groupName });
45
- }
46
- /**
47
- * @description: 设置群头像
48
- * @param {number} groupId 群号
49
- * @param {string} image 图片路径
50
- * @return {void}
51
- */
52
- setGroupAvatar(groupId, image) {
53
- this.adapter.send('set_group_portrait', { group_id: groupId, file: image, cache: false });
54
- }
55
- /**
56
- * @description: 设置群管理员
57
- * @param {number} groupId 群号
58
- * @param {number} userId 要设置的管理员的QQ号
59
- * @param {boolean} enable true为设置,false取消,默认true
60
- * @return {void}
61
- */
62
- setGroupAdmin(groupId, userId, enable = true) {
63
- this.adapter.send('set_group_admin', { group_id: groupId, user_id: userId, enable });
64
- }
65
- /**
66
- * @description: 设置群名片(群备注)
67
- * @param {number} groupId 群号
68
- * @param {number} userId 要设置的QQ号
69
- * @param {string} card 群名片内容,不填或空字符串表示删除群名片
70
- * @return {void}
71
- */
72
- setGroupCard(groupId, userId, card) {
73
- this.adapter.send('set_group_card', { group_id: groupId, user_id: userId, card });
74
- }
75
- /**
76
- * @description: 群禁言
77
- * @param {number} groupId 群号
78
- * @param {number} userId 要禁言的QQ号,不填则为群禁言
79
- * @param {number} time 禁言时长,单位秒,0表示取消禁言
80
- * @return {void}
81
- */
82
- setGroupBan(groupId, userId, time = 0) {
83
- if (userId) {
84
- this.adapter.send('setGroupBan', { group_id: groupId, user_id: userId, duration: time });
85
- }
86
- else {
87
- this.adapter.send('set_group_whole_ban', { group_id: groupId, enable: !!time });
88
- }
89
- }
90
- /**
91
- * @description: 发送群公告
92
- * @param {number} groupId 群号
93
- * @param {string} content 公告内容
94
- * @param {string} image 图片路径(可选)
95
- * @return {void}
96
- */
97
- sendGroupNotice(groupId, content, image) {
98
- this.adapter.send('_sendGroupNotice', { group_id: groupId, content, image });
99
- }
100
- /**
101
- * @description: 群组踢人
102
- * @param {number} groupId 群号
103
- * @param {number} userId 要踢的QQ
104
- * @return {void}
105
- */
106
- setGroupKick(groupId, userId) {
107
- this.adapter.send('setGroupKick', { group_id: groupId, user_id: userId, reject_add_request: false });
108
- }
109
- /**
110
- * @description: 退出群组
111
- * @param {number} groupId 群号
112
- * @return {void}
113
- */
114
- setGroupLeave(groupId) {
115
- this.adapter.send('setGroupLeave', { group_id: groupId, is_dismiss: false });
11
+
12
+ "use strict";
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var api_exports = {};
31
+ __export(api_exports, {
32
+ OnebotApi: () => OnebotApi,
33
+ default: () => api_default
34
+ });
35
+ module.exports = __toCommonJS(api_exports);
36
+ var import_kotori_bot = require("kotori-bot");
37
+ class OnebotApi extends import_kotori_bot.Api {
38
+ sendPrivateMsg(message, userId) {
39
+ this.adapter.status.lastMsgTime = /* @__PURE__ */ new Date();
40
+ this.adapter.status.sentMsg += 1;
41
+ this.adapter.send("send_private_msg", { user_id: userId, message, auto_escape: false });
42
+ }
43
+ /**
44
+ * @description: 发送私聊消息
45
+ * @param {Msg} message 要发送的内容
46
+ * @param {groupId} groupId 群号
47
+ * @return {void}
48
+ */
49
+ sendGroupMsg(message, groupId) {
50
+ this.adapter.status.lastMsgTime = /* @__PURE__ */ new Date();
51
+ this.adapter.status.sentMsg += 1;
52
+ this.adapter.send("send_group_msg", { group_id: groupId, message, auto_escape: false });
53
+ }
54
+ /**
55
+ * @description: 撤回消息
56
+ * @param {number} messageId 消息id
57
+ * @return {void}
58
+ */
59
+ deleteMsg(messageId) {
60
+ this.adapter.send("delete_msg", { messageId });
61
+ }
62
+ /**
63
+ * @description: 设置群名
64
+ * @param {number} groupId 群号
65
+ * @param {string} groupName 新群名
66
+ * @return {void}
67
+ */
68
+ setGroupName(groupId, groupName) {
69
+ this.adapter.send("set_group_name", { group_id: groupId, group_name: groupName });
70
+ }
71
+ /**
72
+ * @description: 设置群头像
73
+ * @param {number} groupId 群号
74
+ * @param {string} image 图片路径
75
+ * @return {void}
76
+ */
77
+ setGroupAvatar(groupId, image) {
78
+ this.adapter.send("set_group_portrait", { group_id: groupId, file: image, cache: false });
79
+ }
80
+ /**
81
+ * @description: 设置群管理员
82
+ * @param {number} groupId 群号
83
+ * @param {number} userId 要设置的管理员的QQ号
84
+ * @param {boolean} enable true为设置,false取消,默认true
85
+ * @return {void}
86
+ */
87
+ setGroupAdmin(groupId, userId, enable = true) {
88
+ this.adapter.send("set_group_admin", { group_id: groupId, user_id: userId, enable });
89
+ }
90
+ /**
91
+ * @description: 设置群名片(群备注)
92
+ * @param {number} groupId 群号
93
+ * @param {number} userId 要设置的QQ号
94
+ * @param {string} card 群名片内容,不填或空字符串表示删除群名片
95
+ * @return {void}
96
+ */
97
+ setGroupCard(groupId, userId, card) {
98
+ this.adapter.send("set_group_card", { group_id: groupId, user_id: userId, card });
99
+ }
100
+ /**
101
+ * @description: 群禁言
102
+ * @param {number} groupId 群号
103
+ * @param {number} userId 要禁言的QQ号,不填则为群禁言
104
+ * @param {number} time 禁言时长,单位秒,0表示取消禁言
105
+ * @return {void}
106
+ */
107
+ setGroupBan(groupId, userId, time = 0) {
108
+ if (userId) {
109
+ this.adapter.send("setGroupBan", { group_id: groupId, user_id: userId, duration: time });
110
+ } else {
111
+ this.adapter.send("set_group_whole_ban", { group_id: groupId, enable: !!time });
116
112
  }
113
+ }
114
+ /**
115
+ * @description: 发送群公告
116
+ * @param {number} groupId 群号
117
+ * @param {string} content 公告内容
118
+ * @param {string} image 图片路径(可选)
119
+ * @return {void}
120
+ */
121
+ sendGroupNotice(groupId, content, image) {
122
+ this.adapter.send("_sendGroupNotice", { group_id: groupId, content, image });
123
+ }
124
+ /**
125
+ * @description: 群组踢人
126
+ * @param {number} groupId 群号
127
+ * @param {number} userId 要踢的QQ号
128
+ * @return {void}
129
+ */
130
+ setGroupKick(groupId, userId) {
131
+ this.adapter.send("setGroupKick", { group_id: groupId, user_id: userId, reject_add_request: false });
132
+ }
133
+ /**
134
+ * @description: 退出群组
135
+ * @param {number} groupId 群号
136
+ * @return {void}
137
+ */
138
+ setGroupLeave(groupId) {
139
+ this.adapter.send("setGroupLeave", { group_id: groupId, is_dismiss: false });
140
+ }
141
+ /* extra: ApiExtraValue = { type: 'onebot', image, at, poke }; */
117
142
  }
118
- exports.OnebotApi = OnebotApi;
119
- exports.default = OnebotApi;
143
+ var api_default = OnebotApi;
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ OnebotApi
147
+ });
package/lib/elements.js CHANGED
@@ -1,27 +1,62 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/kotori-plugin-adapter-onebot
4
+ * @Version 2.0.0
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/7 21:36:06
10
+ */
11
+
1
12
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OnebotElements = void 0;
4
- const kotori_bot_1 = require("kotori-bot");
5
- class OnebotElements extends kotori_bot_1.Elements {
6
- cq(type, data) {
7
- (0, kotori_bot_1.none)(this);
8
- return `[CQ:${type},${data}]`;
9
- }
10
- at(target) {
11
- return this.cq('at', `qq=${target}`);
12
- }
13
- image(url) {
14
- return this.cq('image', `file=${url},cache=0`);
15
- }
16
- voice(url) {
17
- return this.cq('record', `file=${url}`);
18
- }
19
- video(url) {
20
- return this.cq('video', `file=${url}`);
21
- }
22
- face(id) {
23
- return this.cq('face', `id=${id}`);
24
- }
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var elements_exports = {};
31
+ __export(elements_exports, {
32
+ OnebotElements: () => OnebotElements,
33
+ default: () => elements_default
34
+ });
35
+ module.exports = __toCommonJS(elements_exports);
36
+ var import_kotori_bot = require("kotori-bot");
37
+ class OnebotElements extends import_kotori_bot.Elements {
38
+ cq(type, data) {
39
+ (0, import_kotori_bot.none)(this);
40
+ return `[CQ:${type},${data}]`;
41
+ }
42
+ at(target) {
43
+ return this.cq("at", `qq=${target}`);
44
+ }
45
+ image(url) {
46
+ return this.cq("image", `file=${url},cache=0`);
47
+ }
48
+ voice(url) {
49
+ return this.cq("record", `file=${url}`);
50
+ }
51
+ video(url) {
52
+ return this.cq("video", `file=${url}`);
53
+ }
54
+ face(id) {
55
+ return this.cq("face", `id=${id}`);
56
+ }
25
57
  }
26
- exports.OnebotElements = OnebotElements;
27
- exports.default = OnebotElements;
58
+ var elements_default = OnebotElements;
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ OnebotElements
62
+ });
package/lib/index.js CHANGED
@@ -1,4 +1,36 @@
1
+
2
+ /**
3
+ * @Package @kotori-bot/kotori-plugin-adapter-onebot
4
+ * @Version 2.0.0
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/7 21:36:06
10
+ */
11
+
1
12
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const adapter_1 = require("./adapter");
4
- exports.default = adapter_1.OnebotAdapter;
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ default: () => src_default
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+ var import_adapter = require("./adapter");
36
+ var src_default = import_adapter.OnebotAdapter;
package/lib/types.js CHANGED
@@ -1,9 +1,27 @@
1
- "use strict";
2
- /*
3
- * @Author: hotaru biyuehuya@gmail.com
4
- * @Blog: https://hotaru.icu
5
- * @Date: 2023-07-12 15:42:18
6
- * @LastEditors: Hotaru biyuehuya@gmail.com
7
- * @LastEditTime: 2024-02-04 16:13:40
1
+
2
+ /**
3
+ * @Package @kotori-bot/kotori-plugin-adapter-onebot
4
+ * @Version 2.0.0
5
+ * @Author Hotaru <biyuehuya@gmail.com>
6
+ * @Copyright 2024 Hotaru. All rights reserved.
7
+ * @License GPL-3.0
8
+ * @Link https://github.com/kotorijs/kotori
9
+ * @Date 2024/6/7 21:36:06
8
10
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
11
+
12
+ "use strict";
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
+ var __getOwnPropNames = Object.getOwnPropertyNames;
16
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var types_exports = {};
27
+ module.exports = __toCommonJS(types_exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kotori-bot/kotori-plugin-adapter-onebot",
3
- "version": "1.2.1",
3
+ "version": "2.0.0",
4
4
  "description": "Adapter For Onebot (go-cqhttp)",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -17,13 +17,10 @@
17
17
  ],
18
18
  "author": "Hotaru <biyuehuya@gmail.com>",
19
19
  "peerDependencies": {
20
- "kotori-bot": "^1.3.0"
20
+ "kotori-bot": "^1.5.4"
21
21
  },
22
22
  "dependencies": {
23
23
  "@types/ws": "^8.5.8",
24
24
  "ws": "^8.14.2"
25
- },
26
- "scripts": {
27
- "build": "tsc --build"
28
25
  }
29
26
  }
@@ -1,4 +0,0 @@
1
- /// <reference types="node" />
2
- import WebSocket from 'ws';
3
- export declare const WsServer: (port: number) => Promise<[WebSocket, WebSocket.Server<typeof WebSocket, typeof import("http").IncomingMessage>]>;
4
- export default WsServer;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WsServer = void 0;
7
- /*
8
- * @Author: hotaru biyuehuya@gmail.com
9
- * @Blog: https://hotaru.icu
10
- * @Date: 2023-06-24 15:12:55
11
- * @LastEditors: Hotaru biyuehuya@gmail.com
12
- * @LastEditTime: 2024-02-20 20:17:46
13
- */
14
- const ws_1 = __importDefault(require("ws"));
15
- const WsServer = async (port) => new Promise((resolve, reject) => {
16
- try {
17
- const WebSocketServer = new ws_1.default.Server({ port });
18
- WebSocketServer.on('connection', (ws) => {
19
- resolve([ws, WebSocketServer]);
20
- });
21
- }
22
- catch (e) {
23
- reject(e);
24
- }
25
- });
26
- exports.WsServer = WsServer;
27
- exports.default = exports.WsServer;