forked from hczhcz/telegram-kuso-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.roll.js
48 lines (37 loc) · 1.21 KB
/
plugin.roll.js
1
2
3
4
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const config = require('./config');
module.exports = (bot, event, playerEvent, env) => {
bot.onText(/^\/roll(@\w+)?(( (?:(?!_)\w+))*)$/, event((msg, match) => {
const title = config.rollGroupTitle[msg.chat.id];
const args = match[2].split(' ').slice(1);
if (title) {
let text = '';
for (const i in title) {
if (title[i][0] === '/') {
let chosen = null;
if (args.length) {
chosen = env.command.tryGet(msg, args.shift(), [], false, true);
}
if (!chosen) {
chosen = env.command.tryGet(msg, title[i].slice(1), [], false, true);
}
if (!chosen) {
text = '';
break;
}
text += chosen.text;
} else {
text += title[i];
}
}
bot.setChatTitle(
msg.chat.id,
text
);
}
}, 1));
env.info.addPluginHelp(
'roll',
'/roll <trigger(s)> 更换群标题'
);
};