-
Notifications
You must be signed in to change notification settings - Fork 13
/
plugin.bionic.js
53 lines (45 loc) · 1.64 KB
/
plugin.bionic.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
49
50
51
52
53
'use strict';
module.exports = (bot, event, playerEvent, env) => {
bot.onText(/^\/bionic(@\w+)?$/, event((msg, match) => {
if (msg.reply_to_message && msg.reply_to_message.text) {
const originalEntities = msg.reply_to_message.entities || [];
const entities = [];
const re = /\w{2,}/g;
let wordMatch = re.exec(msg.reply_to_message.text);
while (wordMatch) {
let ok = true;
for (const i in originalEntities) {
const entity = originalEntities[i];
if (
wordMatch.index < entity.offset + entity.length
&& wordMatch.index + wordMatch[0].length >= entity.offset
) {
ok = false;
break;
}
}
if (ok) {
entities.push({
type: 'bold',
offset: wordMatch.index,
length: Math.floor(wordMatch[0].length / 2),
});
}
wordMatch = re.exec(msg.reply_to_message.text);
}
bot.sendMessage(
msg.chat.id,
msg.reply_to_message.text,
{
// workaround
entities: JSON.stringify(originalEntities.concat(entities)),
reply_to_message_id: msg.message_id,
}
);
}
}, 1));
env.info.addPluginHelp(
'bionic',
'/bionic 将回复消息转为 bionic 风格'
);
};