Skip to content

Commit b4ff60e

Browse files
committed
分离小冰与 BabyQ
1 parent 216fbff commit b4ff60e

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

plugins/qqbabyq.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* BabyQ
3+
*
4+
* command: '!bbq'
5+
* types: [
6+
* 'qq/123456'
7+
* ]
8+
*/
9+
10+
'use strict';
11+
12+
const BridgeMsg = require('./transport/BridgeMsg.js');
13+
14+
module.exports = (pluginManager, options) => {
15+
const bridge = pluginManager.plugins.transport;
16+
17+
if (!bridge || !pluginManager.handlers.has('QQ')) {
18+
return;
19+
}
20+
21+
let qqHandler = pluginManager.handlers.get('QQ');
22+
let command = options.command || '!bbq';
23+
let types = [];
24+
25+
for (let t of (options.types || [])) {
26+
let client = BridgeMsg.parseUID(t);
27+
if (client.uid) {
28+
types.push(client.uid);
29+
}
30+
}
31+
32+
bridge.addCommand(command, (context) => {
33+
if (!context.isPrivate) {
34+
for (let c of context.extra.mapto) {
35+
let client = BridgeMsg.parseUID(c);
36+
if (client.client === 'QQ') {
37+
if (types.indexOf(client.uid) > -1) {
38+
qqHandler.say(client.id, `[CQ:at,qq=2854196300] ${qqHandler.escape(context.param)}`, {
39+
noEscape: true,
40+
});
41+
}
42+
}
43+
}
44+
}
45+
}, options);
46+
};

plugins/qqxiaoice.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* 小冰
33
*
44
* command: '!bing'
5-
* types: {
6-
* 'qq/123456': 'xiaoice' / 'babyq'
7-
* }
5+
* types: [
6+
* 'qq/123456'
7+
* ]
88
*/
99

1010
'use strict';
@@ -18,36 +18,24 @@ module.exports = (pluginManager, options) => {
1818
return;
1919
}
2020

21-
if (!options.disallowedClients) {
22-
options.disallowedClients = ['QQ'];
23-
} else {
24-
options.disallowedClients.push('QQ');
25-
}
26-
2721
let qqHandler = pluginManager.handlers.get('QQ');
2822
let command = options.command || '!bing';
29-
let types = {};
23+
let types = [];
3024

31-
for (let t in (options.types || {})) {
25+
for (let t of (options.types || [])) {
3226
let client = BridgeMsg.parseUID(t);
3327
if (client.uid) {
34-
types[client.uid] = options.types[t].toLowerCase();
28+
types.push(client.uid);
3529
}
3630
}
3731

3832
bridge.addCommand(command, (context) => {
3933
if (!context.isPrivate) {
4034
for (let c of context.extra.mapto) {
4135
let client = BridgeMsg.parseUID(c);
42-
let qq = null;
4336
if (client.client === 'QQ') {
44-
if (types[client.uid] === 'xiaobing' || types[client.uid] === 'xiaoice') {
45-
qq = '2854196306';
46-
} else if (types[client.uid] === 'babyq') {
47-
qq = '2854196300';
48-
}
49-
if (qq) {
50-
qqHandler.say(client.id, `[CQ:at,qq=${qq}] ${qqHandler.escape(context.param)}`, {
37+
if (types.indexOf(client.uid) > -1) {
38+
qqHandler.say(client.id, `[CQ:at,qq=2854196306] ${qqHandler.escape(context.param)}`, {
5139
noEscape: true,
5240
});
5341
}

0 commit comments

Comments
 (0)