-
Notifications
You must be signed in to change notification settings - Fork 13
/
plugin.repeat.js
51 lines (38 loc) · 1.27 KB
/
plugin.repeat.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
'use strict';
const fs = require('fs');
const config = require('./config');
module.exports = (bot, event, playerEvent, env) => {
const fd = fs.openSync('log.repeat', 'a');
const lastText = {};
bot.on('message', (msg) => {
if (!msg.text || config.ban[msg.from.id] || config.threesomeSilent[msg.chat.id]) {
return;
}
if (!lastText[msg.chat.id]) {
lastText[msg.chat.id] = [msg.text, 1];
if (Object.keys(lastText).length > config.repeatMaxEntry) {
for (const i in lastText) {
delete lastText[i];
break;
}
}
} else if (lastText[msg.chat.id][0] === msg.text) {
lastText[msg.chat.id][1] += 1;
if (lastText[msg.chat.id][1] === 3) {
const text = lastText[msg.chat.id];
delete lastText[msg.chat.id];
fs.write(fd, JSON.stringify(text) + '\n', () => {
// nothing
});
env.command.get(msg, 'repeat', []);
}
} else {
lastText[msg.chat.id] = [msg.text, 1];
}
});
env.info.addPluginHelp(
'repeat',
'插件 repeat\n'
+ '插件 repeat'
);
};