@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 +7 -7
- package/lib/adapter.js +225 -234
- package/lib/api.js +144 -116
- package/lib/elements.js +60 -25
- package/lib/index.js +35 -3
- package/lib/types.js +26 -8
- package/package.json +2 -5
- package/lib/services/wsserver.d.ts +0 -4
- package/lib/services/wsserver.js +0 -27
package/lib/adapter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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").
|
|
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
|
|
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
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,
|
|
37
|
-
class OnebotAdapter extends
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
195
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @Author
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
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
|
-
|
|
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": "
|
|
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.
|
|
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
|
}
|
package/lib/services/wsserver.js
DELETED
|
@@ -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;
|