@zhin.js/adapter-icqq 1.0.22 → 1.0.23
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/CHANGELOG.md +12 -0
- package/lib/index.d.ts +23 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +83 -79
- package/lib/index.js.map +1 -1
- package/package.json +6 -9
- package/src/index.ts +262 -235
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @zhin.js/adapter-icqq
|
|
2
2
|
|
|
3
|
+
## 1.0.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d16a69c: fix: test trust publish
|
|
8
|
+
- Updated dependencies [d16a69c]
|
|
9
|
+
- @zhin.js/client@1.0.6
|
|
10
|
+
- @zhin.js/core@1.0.18
|
|
11
|
+
- zhin.js@1.0.18
|
|
12
|
+
- @zhin.js/console@1.0.14
|
|
13
|
+
- @zhin.js/http@1.0.9
|
|
14
|
+
|
|
3
15
|
## 1.0.22
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { Config, Client, PrivateMessageEvent, GroupMessageEvent, Sendable } from "@icqqjs/icqq";
|
|
2
|
-
import { Bot, Adapter, Message, SendOptions, MessageSegment, SendContent } from "zhin.js";
|
|
3
|
-
|
|
2
|
+
import { Bot, Adapter, Plugin, Message, SendOptions, MessageSegment, SendContent } from "zhin.js";
|
|
3
|
+
import { Router } from "@zhin.js/http";
|
|
4
|
+
declare module "zhin.js" {
|
|
5
|
+
namespace Plugin {
|
|
6
|
+
interface Contexts {
|
|
7
|
+
icqq: IcqqAdapter;
|
|
8
|
+
web: any;
|
|
9
|
+
router: Router;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
4
12
|
interface RegisteredAdapters {
|
|
5
|
-
icqq:
|
|
13
|
+
icqq: IcqqAdapter;
|
|
6
14
|
}
|
|
7
15
|
}
|
|
8
|
-
export interface IcqqBotConfig extends
|
|
9
|
-
context:
|
|
16
|
+
export interface IcqqBotConfig extends Config {
|
|
17
|
+
context: "icqq";
|
|
10
18
|
name: `${number}`;
|
|
11
19
|
password?: string;
|
|
12
20
|
scope?: string;
|
|
@@ -14,9 +22,11 @@ export interface IcqqBotConfig extends Bot.Config, Config {
|
|
|
14
22
|
export interface IcqqBot {
|
|
15
23
|
$config: IcqqBotConfig;
|
|
16
24
|
}
|
|
17
|
-
export declare class IcqqBot extends Client implements Bot<PrivateMessageEvent | GroupMessageEvent
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
export declare class IcqqBot extends Client implements Bot<IcqqBotConfig, PrivateMessageEvent | GroupMessageEvent> {
|
|
26
|
+
adapter: IcqqAdapter;
|
|
27
|
+
$connected: boolean;
|
|
28
|
+
get $id(): `${number}`;
|
|
29
|
+
constructor(adapter: IcqqAdapter, config: IcqqBotConfig);
|
|
20
30
|
private handleIcqqMessage;
|
|
21
31
|
$connect(): Promise<void>;
|
|
22
32
|
$disconnect(): Promise<void>;
|
|
@@ -28,4 +38,9 @@ export declare namespace IcqqBot {
|
|
|
28
38
|
function toSegments(message: Sendable): MessageSegment[];
|
|
29
39
|
function toSendable(content: SendContent): Sendable;
|
|
30
40
|
}
|
|
41
|
+
declare class IcqqAdapter extends Adapter<IcqqBot> {
|
|
42
|
+
constructor(plugin: Plugin);
|
|
43
|
+
createBot(config: IcqqBotConfig): IcqqBot;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
31
46
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceR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CAAC,IAAI,CAAC;IAIzC,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAgB1D;AAED,yBAAiB,OAAO,CAAC;IAGvB,SAAgB,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,cAAc,EAAE,CAW9D;IAED,SAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,QAAQ,CASzD;CACF;AAED,cAAM,WAAY,SAAQ,OAAO,CAAC,OAAO,CAAC;gBAC5B,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;CAG1C"}
|
package/lib/index.js
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
import { Client } from "@icqqjs/icqq";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { usePlugin,
|
|
3
|
+
import { usePlugin, Adapter, Message, segment, } from "zhin.js";
|
|
4
4
|
const plugin = usePlugin();
|
|
5
|
+
const { useContext } = plugin;
|
|
5
6
|
export class IcqqBot extends Client {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
adapter;
|
|
8
|
+
$connected = false;
|
|
9
|
+
get $id() {
|
|
10
|
+
return this.$config.name;
|
|
11
|
+
}
|
|
12
|
+
constructor(adapter, config) {
|
|
8
13
|
if (!config.scope)
|
|
9
|
-
config.scope =
|
|
14
|
+
config.scope = "icqqjs";
|
|
10
15
|
if (!config.data_dir)
|
|
11
|
-
config.data_dir = path.join(process.cwd(),
|
|
12
|
-
if (config.scope.startsWith(
|
|
16
|
+
config.data_dir = path.join(process.cwd(), "data");
|
|
17
|
+
if (config.scope.startsWith("@"))
|
|
13
18
|
config.scope = config.scope.slice(1);
|
|
14
19
|
super(config);
|
|
20
|
+
this.adapter = adapter;
|
|
15
21
|
this.$config = config;
|
|
16
22
|
}
|
|
17
23
|
handleIcqqMessage(msg) {
|
|
18
24
|
const message = this.$formatMessage(msg);
|
|
19
|
-
|
|
20
|
-
plugin.logger.
|
|
21
|
-
plugin.dispatch(`message.${message.$channel.type}.receive`, message);
|
|
25
|
+
this.adapter.emit("message.receive", message);
|
|
26
|
+
plugin.logger.debug(`${this.$config.name} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
|
|
22
27
|
}
|
|
23
28
|
async $connect() {
|
|
24
|
-
this.on(
|
|
25
|
-
this.on(
|
|
29
|
+
this.on("message", this.handleIcqqMessage.bind(this));
|
|
30
|
+
this.on("system.login.device", async (e) => {
|
|
26
31
|
await this.sendSmsCode();
|
|
27
|
-
plugin.logger.info(
|
|
28
|
-
process.stdin.once(
|
|
32
|
+
plugin.logger.info("请输入短信验证码:");
|
|
33
|
+
process.stdin.once("data", (data) => {
|
|
29
34
|
this.submitSmsCode(data.toString().trim());
|
|
30
35
|
});
|
|
31
36
|
});
|
|
32
|
-
this.on(
|
|
37
|
+
this.on("system.login.qrcode", (e) => {
|
|
33
38
|
plugin.logger.info(`取码地址:${e.image}\n请扫码完成后回车继续:`);
|
|
34
|
-
process.stdin.once(
|
|
39
|
+
process.stdin.once("data", () => {
|
|
35
40
|
this.login();
|
|
36
41
|
});
|
|
37
42
|
});
|
|
38
|
-
this.on(
|
|
43
|
+
this.on("system.login.slider", (e) => {
|
|
39
44
|
plugin.logger.info(`取码地址:${e.url}\n请输入滑块验证ticket:`);
|
|
40
|
-
process.stdin.once(
|
|
45
|
+
process.stdin.once("data", (e) => {
|
|
41
46
|
this.submitSlider(e.toString().trim());
|
|
42
47
|
});
|
|
43
48
|
});
|
|
44
49
|
return new Promise((resolve) => {
|
|
45
|
-
this.once(
|
|
50
|
+
this.once("system.online", () => {
|
|
46
51
|
this.$connected = true;
|
|
47
52
|
resolve();
|
|
48
53
|
});
|
|
@@ -56,15 +61,15 @@ export class IcqqBot extends Client {
|
|
|
56
61
|
$formatMessage(msg) {
|
|
57
62
|
const result = Message.from(msg, {
|
|
58
63
|
$id: msg.message_id.toString(),
|
|
59
|
-
$adapter:
|
|
64
|
+
$adapter: "icqq",
|
|
60
65
|
$bot: `${this.$config.name}`,
|
|
61
66
|
$sender: {
|
|
62
67
|
id: msg.sender.user_id.toString(),
|
|
63
68
|
name: msg.sender.nickname.toString(),
|
|
64
69
|
},
|
|
65
70
|
$channel: {
|
|
66
|
-
id: msg.message_type ===
|
|
67
|
-
type: msg.message_type
|
|
71
|
+
id: msg.message_type === "group" ? msg.group_id.toString() : msg.from_id.toString(),
|
|
72
|
+
type: msg.message_type,
|
|
68
73
|
},
|
|
69
74
|
$content: IcqqBot.toSegments(msg.message),
|
|
70
75
|
$raw: msg.raw_message,
|
|
@@ -76,14 +81,14 @@ export class IcqqBot extends Client {
|
|
|
76
81
|
if (!Array.isArray(content))
|
|
77
82
|
content = [content];
|
|
78
83
|
if (quote)
|
|
79
|
-
content.unshift({ type:
|
|
84
|
+
content.unshift({ type: "reply", data: { id: typeof quote === "boolean" ? result.$id : quote } });
|
|
80
85
|
return await this.$sendMessage({
|
|
81
86
|
...result.$channel,
|
|
82
|
-
context:
|
|
87
|
+
context: "icqq",
|
|
83
88
|
bot: `${this.uin}`,
|
|
84
|
-
content
|
|
89
|
+
content,
|
|
85
90
|
});
|
|
86
|
-
}
|
|
91
|
+
},
|
|
87
92
|
});
|
|
88
93
|
return result;
|
|
89
94
|
}
|
|
@@ -91,19 +96,16 @@ export class IcqqBot extends Client {
|
|
|
91
96
|
await this.deleteMsg(id);
|
|
92
97
|
}
|
|
93
98
|
async $sendMessage(options) {
|
|
94
|
-
options = await plugin.app.handleBeforeSend(options);
|
|
95
99
|
switch (options.type) {
|
|
96
|
-
case
|
|
100
|
+
case "private": {
|
|
97
101
|
const result = await this.sendPrivateMsg(Number(options.id), IcqqBot.toSendable(options.content));
|
|
98
|
-
plugin.logger.
|
|
102
|
+
plugin.logger.debug(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`);
|
|
99
103
|
return result.message_id.toString();
|
|
100
|
-
break;
|
|
101
104
|
}
|
|
102
105
|
case "group": {
|
|
103
106
|
const result = await this.sendGroupMsg(Number(options.id), IcqqBot.toSendable(options.content));
|
|
104
|
-
plugin.logger.
|
|
107
|
+
plugin.logger.debug(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`);
|
|
105
108
|
return result.message_id.toString();
|
|
106
|
-
break;
|
|
107
109
|
}
|
|
108
110
|
default:
|
|
109
111
|
throw new Error(`unsupported channel type ${options.type}`);
|
|
@@ -111,34 +113,17 @@ export class IcqqBot extends Client {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
(function (IcqqBot) {
|
|
114
|
-
const allowTypes = [
|
|
115
|
-
'text',
|
|
116
|
-
'face',
|
|
117
|
-
'image',
|
|
118
|
-
'record',
|
|
119
|
-
'audio',
|
|
120
|
-
'dice',
|
|
121
|
-
'rps',
|
|
122
|
-
'video',
|
|
123
|
-
'file',
|
|
124
|
-
'location',
|
|
125
|
-
'share',
|
|
126
|
-
'json',
|
|
127
|
-
'at',
|
|
128
|
-
'reply',
|
|
129
|
-
'long_msg',
|
|
130
|
-
'button',
|
|
131
|
-
'markdown',
|
|
132
|
-
'xml',
|
|
133
|
-
];
|
|
116
|
+
const allowTypes = ["text", "face", "image", "record", "audio", "dice", "rps", "video", "file", "location", "share", "json", "at", "reply", "long_msg", "button", "markdown", "xml"];
|
|
134
117
|
function toSegments(message) {
|
|
135
118
|
if (!Array.isArray(message))
|
|
136
119
|
message = [message];
|
|
137
|
-
return message
|
|
138
|
-
|
|
139
|
-
|
|
120
|
+
return message
|
|
121
|
+
.filter((item, index) => {
|
|
122
|
+
return typeof item === "string" || item.type !== "long_msg" || index !== 0;
|
|
123
|
+
})
|
|
124
|
+
.map((item) => {
|
|
140
125
|
if (typeof item === "string")
|
|
141
|
-
return { type:
|
|
126
|
+
return { type: "text", data: { text: item } };
|
|
142
127
|
const { type, ...data } = item;
|
|
143
128
|
return { type, data };
|
|
144
129
|
});
|
|
@@ -149,39 +134,60 @@ export class IcqqBot extends Client {
|
|
|
149
134
|
content = [content];
|
|
150
135
|
return content.map((seg) => {
|
|
151
136
|
if (typeof seg === "string")
|
|
152
|
-
return { type:
|
|
137
|
+
return { type: "text", text: seg };
|
|
153
138
|
let { type, data } = seg;
|
|
154
|
-
if (typeof type ===
|
|
139
|
+
if (typeof type === "function")
|
|
155
140
|
type = type.name;
|
|
156
141
|
if (!allowTypes.includes(type))
|
|
157
|
-
return { type:
|
|
142
|
+
return { type: "text", text: segment.toString(seg) };
|
|
158
143
|
return { type, ...data };
|
|
159
144
|
});
|
|
160
145
|
}
|
|
161
146
|
IcqqBot.toSendable = toSendable;
|
|
162
147
|
})(IcqqBot || (IcqqBot = {}));
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
class IcqqAdapter extends Adapter {
|
|
149
|
+
constructor(plugin) {
|
|
150
|
+
super(plugin, "icqq", []);
|
|
151
|
+
}
|
|
152
|
+
createBot(config) {
|
|
153
|
+
return new IcqqBot(this, config);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const { provide } = usePlugin();
|
|
157
|
+
provide({
|
|
158
|
+
name: "icqq",
|
|
159
|
+
description: "ICQQ Adapter",
|
|
160
|
+
mounted: async (p) => {
|
|
161
|
+
const adapter = new IcqqAdapter(p);
|
|
162
|
+
await adapter.start();
|
|
163
|
+
return adapter;
|
|
164
|
+
},
|
|
165
|
+
dispose: async (adapter) => {
|
|
166
|
+
await adapter.stop();
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
useContext("web", (web) => {
|
|
165
170
|
// 注册ICQQ适配器的客户端入口文件
|
|
166
171
|
const dispose = web.addEntry({
|
|
167
|
-
production: path.resolve(import.meta.dirname,
|
|
168
|
-
development: path.resolve(import.meta.dirname,
|
|
172
|
+
production: path.resolve(import.meta.dirname, "../dist/index.js"),
|
|
173
|
+
development: path.resolve(import.meta.dirname, "../client/index.tsx"),
|
|
169
174
|
});
|
|
170
175
|
return dispose;
|
|
171
176
|
});
|
|
172
|
-
useContext(
|
|
173
|
-
|
|
177
|
+
useContext("router", async (router) => {
|
|
178
|
+
const icqq = plugin.root.inject("icqq");
|
|
179
|
+
router.get("/api/icqq/bots", async (ctx) => {
|
|
174
180
|
try {
|
|
175
181
|
const bots = Array.from(icqq.bots.values());
|
|
176
182
|
if (bots.length === 0) {
|
|
177
183
|
ctx.body = {
|
|
178
184
|
success: true,
|
|
179
185
|
data: [],
|
|
180
|
-
message:
|
|
186
|
+
message: "暂无ICQQ机器人实例",
|
|
181
187
|
};
|
|
182
188
|
return;
|
|
183
189
|
}
|
|
184
|
-
const result = bots.map(bot => {
|
|
190
|
+
const result = bots.map((bot) => {
|
|
185
191
|
try {
|
|
186
192
|
return {
|
|
187
193
|
name: bot.$config.name,
|
|
@@ -190,14 +196,13 @@ useContext('router', 'icqq', (router, icqq) => {
|
|
|
190
196
|
friendCount: bot.fl?.size || 0,
|
|
191
197
|
receiveCount: bot.stat?.recv_msg_cnt || 0,
|
|
192
198
|
sendCount: bot.stat?.sent_msg_cnt || 0,
|
|
193
|
-
loginMode: bot.$config.password ?
|
|
194
|
-
status: bot.$connected ?
|
|
195
|
-
lastActivity: new Date().toISOString()
|
|
199
|
+
loginMode: bot.$config.password ? "password" : "qrcode",
|
|
200
|
+
status: bot.$connected ? "online" : "offline",
|
|
201
|
+
lastActivity: new Date().toISOString(),
|
|
196
202
|
};
|
|
197
203
|
}
|
|
198
204
|
catch (botError) {
|
|
199
205
|
// 单个机器人数据获取失败时的处理
|
|
200
|
-
// 获取机器人数据失败,返回错误状态
|
|
201
206
|
return {
|
|
202
207
|
name: bot.$config.name,
|
|
203
208
|
connected: false,
|
|
@@ -205,27 +210,26 @@ useContext('router', 'icqq', (router, icqq) => {
|
|
|
205
210
|
friendCount: 0,
|
|
206
211
|
receiveCount: 0,
|
|
207
212
|
sendCount: 0,
|
|
208
|
-
loginMode:
|
|
209
|
-
status:
|
|
210
|
-
error:
|
|
213
|
+
loginMode: "unknown",
|
|
214
|
+
status: "error",
|
|
215
|
+
error: "数据获取失败",
|
|
211
216
|
};
|
|
212
217
|
}
|
|
213
218
|
});
|
|
214
219
|
ctx.body = {
|
|
215
220
|
success: true,
|
|
216
221
|
data: result,
|
|
217
|
-
timestamp: new Date().toISOString()
|
|
222
|
+
timestamp: new Date().toISOString(),
|
|
218
223
|
};
|
|
219
224
|
}
|
|
220
225
|
catch (error) {
|
|
221
|
-
// ICQQ API调用失败
|
|
222
226
|
ctx.status = 500;
|
|
223
227
|
ctx.body = {
|
|
224
228
|
success: false,
|
|
225
|
-
error:
|
|
226
|
-
message:
|
|
227
|
-
details: process.env.NODE_ENV ===
|
|
228
|
-
timestamp: new Date().toISOString()
|
|
229
|
+
error: "ICQQ_API_ERROR",
|
|
230
|
+
message: "获取机器人数据失败",
|
|
231
|
+
details: process.env.NODE_ENV === "development" ? error.message : undefined,
|
|
232
|
+
timestamp: new Date().toISOString(),
|
|
229
233
|
};
|
|
230
234
|
}
|
|
231
235
|
});
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAiE,MAAM,cAAc,CAAC;AAC7G,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAEL,SAAS,EACT,OAAO,EAEP,OAAO,EAIP,OAAO,GACR,MAAM,SAAS,CAAC;AAiBjB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;AAa9B,MAAM,OAAO,OAAQ,SAAQ,MAAM;IAOd;IANnB,UAAU,GAAY,KAAK,CAAC;IAE5B,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,YAAmB,OAAoB,EAAE,MAAqB;QAC5D,IAAI,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ACT,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,gBAAgB;gBACvB,OAAO,EAAE,WAAW;gBACpB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;gBACtF,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-icqq",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "zhin adapter for icqq",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"typescript": "^5.3.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"zhin.js": "1.0.
|
|
47
|
-
"@zhin.js/
|
|
48
|
-
"@zhin.js/
|
|
49
|
-
"@zhin.js/
|
|
50
|
-
"
|
|
46
|
+
"@zhin.js/core": "1.0.18",
|
|
47
|
+
"@zhin.js/client": "1.0.6",
|
|
48
|
+
"@zhin.js/console": "1.0.14",
|
|
49
|
+
"@zhin.js/http": "1.0.9",
|
|
50
|
+
"zhin.js": "1.0.18"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"@zhin.js/client": {
|
|
@@ -58,9 +58,6 @@
|
|
|
58
58
|
},
|
|
59
59
|
"@zhin.js/console": {
|
|
60
60
|
"optional": true
|
|
61
|
-
},
|
|
62
|
-
"@zhin.js/types": {
|
|
63
|
-
"optional": true
|
|
64
61
|
}
|
|
65
62
|
},
|
|
66
63
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -1,250 +1,277 @@
|
|
|
1
|
-
import { Config, Client, PrivateMessageEvent, GroupMessageEvent, Sendable, MessageElem} from "@icqqjs/icqq";
|
|
1
|
+
import { Config, Client, PrivateMessageEvent, GroupMessageEvent, Sendable, MessageElem } from "@icqqjs/icqq";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
SendContent,
|
|
14
|
-
segment
|
|
4
|
+
Bot,
|
|
5
|
+
usePlugin,
|
|
6
|
+
Adapter,
|
|
7
|
+
Plugin,
|
|
8
|
+
Message,
|
|
9
|
+
SendOptions,
|
|
10
|
+
MessageSegment,
|
|
11
|
+
SendContent,
|
|
12
|
+
segment,
|
|
15
13
|
} from "zhin.js";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
import { Router } from "@zhin.js/http";
|
|
15
|
+
|
|
16
|
+
declare module "zhin.js" {
|
|
17
|
+
namespace Plugin {
|
|
18
|
+
interface Contexts {
|
|
19
|
+
icqq: IcqqAdapter;
|
|
20
|
+
web: any;
|
|
21
|
+
router: Router;
|
|
19
22
|
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface RegisteredAdapters {
|
|
26
|
+
icqq: IcqqAdapter;
|
|
27
|
+
}
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
|
|
30
|
+
const plugin = usePlugin();
|
|
31
|
+
const { useContext } = plugin;
|
|
32
|
+
|
|
33
|
+
export interface IcqqBotConfig extends Config {
|
|
34
|
+
context: "icqq";
|
|
35
|
+
name: `${number}`;
|
|
36
|
+
password?: string;
|
|
37
|
+
scope?: string;
|
|
27
38
|
}
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
|
|
40
|
+
export interface IcqqBot {
|
|
41
|
+
$config: IcqqBotConfig;
|
|
30
42
|
}
|
|
31
|
-
export class IcqqBot extends Client implements Bot<PrivateMessageEvent|GroupMessageEvent,IcqqBotConfig>{
|
|
32
|
-
$connected?:boolean
|
|
33
|
-
constructor(config:IcqqBotConfig) {
|
|
34
|
-
if(!config.scope) config.scope='icqqjs'
|
|
35
|
-
if(!config.data_dir) config.data_dir=path.join(process.cwd(),'data')
|
|
36
|
-
if(config.scope.startsWith('@')) config.scope=config.scope.slice(1)
|
|
37
|
-
super(config);
|
|
38
|
-
this.$config=config
|
|
39
|
-
}
|
|
40
|
-
private handleIcqqMessage(msg: PrivateMessageEvent|GroupMessageEvent): void {
|
|
41
|
-
const message =this.$formatMessage(msg) ;
|
|
42
|
-
plugin.dispatch('message.receive',message)
|
|
43
|
-
plugin.logger.info(`${this.$config.name} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`)
|
|
44
|
-
plugin.dispatch(`message.${message.$channel.type}.receive`,message)
|
|
45
|
-
}
|
|
46
|
-
async $connect(): Promise<void> {
|
|
47
|
-
this.on('message',this.handleIcqqMessage.bind(this))
|
|
48
|
-
this.on('system.login.device',async (e:unknown)=>{
|
|
49
|
-
await this.sendSmsCode()
|
|
50
|
-
plugin.logger.info('请输入短信验证码:')
|
|
51
|
-
process.stdin.once('data',(data)=>{
|
|
52
|
-
this.submitSmsCode(data.toString().trim())
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
this.on('system.login.qrcode',(e)=>{
|
|
56
|
-
plugin.logger.info(`取码地址:${e.image}\n请扫码完成后回车继续:`)
|
|
57
|
-
process.stdin.once('data',()=>{
|
|
58
|
-
this.login()
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
this.on('system.login.slider',(e)=>{
|
|
62
|
-
plugin.logger.info(`取码地址:${e.url}\n请输入滑块验证ticket:`)
|
|
63
|
-
process.stdin.once('data',(e)=>{
|
|
64
|
-
this.submitSlider(e.toString().trim())
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
return new Promise((resolve)=>{
|
|
68
|
-
this.once('system.online',()=>{
|
|
69
|
-
this.$connected=true;
|
|
70
|
-
resolve()
|
|
71
|
-
})
|
|
72
|
-
this.login(Number(this.$config.name),this.$config.password)
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
43
|
|
|
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
|
-
|
|
44
|
+
export class IcqqBot extends Client implements Bot<IcqqBotConfig, PrivateMessageEvent | GroupMessageEvent> {
|
|
45
|
+
$connected: boolean = false;
|
|
46
|
+
|
|
47
|
+
get $id() {
|
|
48
|
+
return this.$config.name;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
constructor(public adapter: IcqqAdapter, config: IcqqBotConfig) {
|
|
52
|
+
if (!config.scope) config.scope = "icqqjs";
|
|
53
|
+
if (!config.data_dir) config.data_dir = path.join(process.cwd(), "data");
|
|
54
|
+
if (config.scope.startsWith("@")) config.scope = config.scope.slice(1);
|
|
55
|
+
super(config);
|
|
56
|
+
this.$config = config;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private handleIcqqMessage(msg: PrivateMessageEvent | GroupMessageEvent): void {
|
|
60
|
+
const message = this.$formatMessage(msg);
|
|
61
|
+
this.adapter.emit("message.receive", message);
|
|
62
|
+
plugin.logger.debug(`${this.$config.name} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async $connect(): Promise<void> {
|
|
66
|
+
this.on("message", this.handleIcqqMessage.bind(this));
|
|
67
|
+
this.on("system.login.device", async (e: unknown) => {
|
|
68
|
+
await this.sendSmsCode();
|
|
69
|
+
plugin.logger.info("请输入短信验证码:");
|
|
70
|
+
process.stdin.once("data", (data) => {
|
|
71
|
+
this.submitSmsCode(data.toString().trim());
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
this.on("system.login.qrcode", (e) => {
|
|
75
|
+
plugin.logger.info(`取码地址:${e.image}\n请扫码完成后回车继续:`);
|
|
76
|
+
process.stdin.once("data", () => {
|
|
77
|
+
this.login();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
this.on("system.login.slider", (e) => {
|
|
81
|
+
plugin.logger.info(`取码地址:${e.url}\n请输入滑块验证ticket:`);
|
|
82
|
+
process.stdin.once("data", (e) => {
|
|
83
|
+
this.submitSlider(e.toString().trim());
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
this.once("system.online", () => {
|
|
88
|
+
this.$connected = true;
|
|
89
|
+
resolve();
|
|
90
|
+
});
|
|
91
|
+
this.login(Number(this.$config.name), this.$config.password);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async $disconnect(): Promise<void> {
|
|
96
|
+
await this.logout();
|
|
97
|
+
this.$connected = false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
$formatMessage(msg: PrivateMessageEvent | GroupMessageEvent) {
|
|
101
|
+
const result = Message.from(msg, {
|
|
102
|
+
$id: msg.message_id.toString(),
|
|
103
|
+
$adapter: "icqq" as const,
|
|
104
|
+
$bot: `${this.$config.name}`,
|
|
105
|
+
$sender: {
|
|
106
|
+
id: msg.sender.user_id.toString(),
|
|
107
|
+
name: msg.sender.nickname.toString(),
|
|
108
|
+
},
|
|
109
|
+
$channel: {
|
|
110
|
+
id: msg.message_type === "group" ? msg.group_id.toString() : msg.from_id.toString(),
|
|
111
|
+
type: msg.message_type,
|
|
112
|
+
},
|
|
113
|
+
$content: IcqqBot.toSegments(msg.message),
|
|
114
|
+
$raw: msg.raw_message,
|
|
115
|
+
$timestamp: msg.time,
|
|
116
|
+
$recall: async () => {
|
|
117
|
+
await this.$recallMessage(result.$id);
|
|
118
|
+
},
|
|
119
|
+
$reply: async (content: SendContent, quote?: boolean | string): Promise<string> => {
|
|
120
|
+
if (!Array.isArray(content)) content = [content];
|
|
121
|
+
if (quote) content.unshift({ type: "reply", data: { id: typeof quote === "boolean" ? result.$id : quote } });
|
|
122
|
+
return await this.$sendMessage({
|
|
123
|
+
...result.$channel,
|
|
124
|
+
context: "icqq",
|
|
125
|
+
bot: `${this.uin}`,
|
|
126
|
+
content,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async $recallMessage(id: string): Promise<void> {
|
|
134
|
+
await this.deleteMsg(id);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async $sendMessage(options: SendOptions): Promise<string> {
|
|
138
|
+
switch (options.type) {
|
|
139
|
+
case "private": {
|
|
140
|
+
const result = await this.sendPrivateMsg(Number(options.id), IcqqBot.toSendable(options.content));
|
|
141
|
+
plugin.logger.debug(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`);
|
|
142
|
+
return result.message_id.toString();
|
|
143
|
+
}
|
|
144
|
+
case "group": {
|
|
145
|
+
const result = await this.sendGroupMsg(Number(options.id), IcqqBot.toSendable(options.content));
|
|
146
|
+
plugin.logger.debug(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`);
|
|
147
|
+
return result.message_id.toString();
|
|
148
|
+
}
|
|
149
|
+
default:
|
|
150
|
+
throw new Error(`unsupported channel type ${options.type}`);
|
|
133
151
|
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export namespace IcqqBot {
|
|
156
|
+
const allowTypes = ["text", "face", "image", "record", "audio", "dice", "rps", "video", "file", "location", "share", "json", "at", "reply", "long_msg", "button", "markdown", "xml"];
|
|
134
157
|
|
|
158
|
+
export function toSegments(message: Sendable): MessageSegment[] {
|
|
159
|
+
if (!Array.isArray(message)) message = [message];
|
|
160
|
+
return message
|
|
161
|
+
.filter((item, index) => {
|
|
162
|
+
return typeof item === "string" || item.type !== "long_msg" || index !== 0;
|
|
163
|
+
})
|
|
164
|
+
.map((item): MessageSegment => {
|
|
165
|
+
if (typeof item === "string") return { type: "text", data: { text: item } };
|
|
166
|
+
const { type, ...data } = item;
|
|
167
|
+
return { type, data };
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function toSendable(content: SendContent): Sendable {
|
|
172
|
+
if (!Array.isArray(content)) content = [content];
|
|
173
|
+
return content.map((seg): MessageElem => {
|
|
174
|
+
if (typeof seg === "string") return { type: "text", text: seg };
|
|
175
|
+
let { type, data } = seg;
|
|
176
|
+
if (typeof type === "function") type = type.name;
|
|
177
|
+
if (!allowTypes.includes(type)) return { type: "text", text: segment.toString(seg) };
|
|
178
|
+
return { type, ...data } as MessageElem;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
135
181
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
'video',
|
|
146
|
-
'file',
|
|
147
|
-
'location',
|
|
148
|
-
'share',
|
|
149
|
-
'json',
|
|
150
|
-
'at',
|
|
151
|
-
'reply',
|
|
152
|
-
'long_msg',
|
|
153
|
-
'button',
|
|
154
|
-
'markdown',
|
|
155
|
-
'xml',
|
|
156
|
-
]
|
|
157
|
-
export function toSegments(message:Sendable):MessageSegment[]{
|
|
158
|
-
if(!Array.isArray(message)) message=[message]
|
|
159
|
-
return message.filter((item,index)=>{
|
|
160
|
-
return typeof item==="string"||(item.type!=='long_msg'||index!==0)
|
|
161
|
-
}).map((item):MessageSegment=>{
|
|
162
|
-
if(typeof item==="string") return {type:'text',data:{text:item}}
|
|
163
|
-
const {type,...data}=item
|
|
164
|
-
return {type,data}
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
export function toSendable(content:SendContent):Sendable{
|
|
168
|
-
if(!Array.isArray(content)) content=[content]
|
|
169
|
-
return content.map((seg):MessageElem=>{
|
|
170
|
-
if(typeof seg==="string") return {type:'text',text:seg}
|
|
171
|
-
let {type,data}=seg
|
|
172
|
-
if(typeof type==='function') type=type.name
|
|
173
|
-
if(!allowTypes.includes(type)) return {type:'text',text:segment.toString(seg)}
|
|
174
|
-
return {type,...data} as MessageElem
|
|
175
|
-
})
|
|
176
|
-
}
|
|
182
|
+
|
|
183
|
+
class IcqqAdapter extends Adapter<IcqqBot> {
|
|
184
|
+
constructor(plugin: Plugin) {
|
|
185
|
+
super(plugin, "icqq", []);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
createBot(config: IcqqBotConfig): IcqqBot {
|
|
189
|
+
return new IcqqBot(this, config);
|
|
190
|
+
}
|
|
177
191
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
|
|
193
|
+
const { provide } = usePlugin();
|
|
194
|
+
|
|
195
|
+
provide({
|
|
196
|
+
name: "icqq",
|
|
197
|
+
description: "ICQQ Adapter",
|
|
198
|
+
mounted: async (p) => {
|
|
199
|
+
const adapter = new IcqqAdapter(p);
|
|
200
|
+
await adapter.start();
|
|
201
|
+
return adapter;
|
|
202
|
+
},
|
|
203
|
+
dispose: async (adapter) => {
|
|
204
|
+
await adapter.stop();
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
useContext("web", (web: any) => {
|
|
209
|
+
// 注册ICQQ适配器的客户端入口文件
|
|
210
|
+
const dispose = web.addEntry({
|
|
211
|
+
production: path.resolve(import.meta.dirname, "../dist/index.js"),
|
|
212
|
+
development: path.resolve(import.meta.dirname, "../client/index.tsx"),
|
|
213
|
+
});
|
|
214
|
+
return dispose;
|
|
187
215
|
});
|
|
188
|
-
|
|
189
|
-
|
|
216
|
+
|
|
217
|
+
useContext("router", async (router: Router) => {
|
|
218
|
+
const icqq = plugin.root.inject("icqq") as IcqqAdapter;
|
|
219
|
+
router.get("/api/icqq/bots", async (ctx: any) => {
|
|
220
|
+
try {
|
|
221
|
+
const bots = Array.from(icqq.bots.values());
|
|
222
|
+
|
|
223
|
+
if (bots.length === 0) {
|
|
224
|
+
ctx.body = {
|
|
225
|
+
success: true,
|
|
226
|
+
data: [],
|
|
227
|
+
message: "暂无ICQQ机器人实例",
|
|
228
|
+
};
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const result = bots.map((bot) => {
|
|
190
233
|
try {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
} catch (botError) {
|
|
216
|
-
// 单个机器人数据获取失败时的处理
|
|
217
|
-
// 获取机器人数据失败,返回错误状态
|
|
218
|
-
return {
|
|
219
|
-
name: bot.$config.name,
|
|
220
|
-
connected: false,
|
|
221
|
-
groupCount: 0,
|
|
222
|
-
friendCount: 0,
|
|
223
|
-
receiveCount: 0,
|
|
224
|
-
sendCount: 0,
|
|
225
|
-
loginMode: 'unknown',
|
|
226
|
-
status: 'error',
|
|
227
|
-
error: '数据获取失败'
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
ctx.body = {
|
|
233
|
-
success: true,
|
|
234
|
-
data: result,
|
|
235
|
-
timestamp: new Date().toISOString()
|
|
236
|
-
}
|
|
237
|
-
} catch (error) {
|
|
238
|
-
// ICQQ API调用失败
|
|
239
|
-
|
|
240
|
-
ctx.status = 500
|
|
241
|
-
ctx.body = {
|
|
242
|
-
success: false,
|
|
243
|
-
error: 'ICQQ_API_ERROR',
|
|
244
|
-
message: '获取机器人数据失败',
|
|
245
|
-
details: process.env.NODE_ENV === 'development' ? (error as Error).message : undefined,
|
|
246
|
-
timestamp: new Date().toISOString()
|
|
247
|
-
}
|
|
234
|
+
return {
|
|
235
|
+
name: bot.$config.name,
|
|
236
|
+
connected: bot.$connected || false,
|
|
237
|
+
groupCount: bot.gl?.size || 0,
|
|
238
|
+
friendCount: bot.fl?.size || 0,
|
|
239
|
+
receiveCount: bot.stat?.recv_msg_cnt || 0,
|
|
240
|
+
sendCount: bot.stat?.sent_msg_cnt || 0,
|
|
241
|
+
loginMode: bot.$config.password ? "password" : "qrcode",
|
|
242
|
+
status: bot.$connected ? "online" : "offline",
|
|
243
|
+
lastActivity: new Date().toISOString(),
|
|
244
|
+
};
|
|
245
|
+
} catch (botError) {
|
|
246
|
+
// 单个机器人数据获取失败时的处理
|
|
247
|
+
return {
|
|
248
|
+
name: bot.$config.name,
|
|
249
|
+
connected: false,
|
|
250
|
+
groupCount: 0,
|
|
251
|
+
friendCount: 0,
|
|
252
|
+
receiveCount: 0,
|
|
253
|
+
sendCount: 0,
|
|
254
|
+
loginMode: "unknown",
|
|
255
|
+
status: "error",
|
|
256
|
+
error: "数据获取失败",
|
|
257
|
+
};
|
|
248
258
|
}
|
|
249
|
-
|
|
250
|
-
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
ctx.body = {
|
|
262
|
+
success: true,
|
|
263
|
+
data: result,
|
|
264
|
+
timestamp: new Date().toISOString(),
|
|
265
|
+
};
|
|
266
|
+
} catch (error) {
|
|
267
|
+
ctx.status = 500;
|
|
268
|
+
ctx.body = {
|
|
269
|
+
success: false,
|
|
270
|
+
error: "ICQQ_API_ERROR",
|
|
271
|
+
message: "获取机器人数据失败",
|
|
272
|
+
details: process.env.NODE_ENV === "development" ? (error as Error).message : undefined,
|
|
273
|
+
timestamp: new Date().toISOString(),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
});
|