-
Notifications
You must be signed in to change notification settings - Fork 13
/
block.js
49 lines (38 loc) · 989 Bytes
/
block.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
'use strict';
const fs = require('fs');
const config = require('./config');
const bot = require('./bot.' + config.bot)(config.blockToken);
const fd = fs.openSync('log_block', 'a');
const log = (head, body) => {
fs.write(fd, '[' + Date() + '] ' + head + ' ' + body + '\n', () => {
// nothing
});
};
let enable = true;
bot.on('message', (msg) => {
if (enable && config.block[msg.from.id]) {
log(
msg.chat.id + ':' + msg.from.id,
msg.text
);
bot.deleteMessage(msg.chat.id, msg.message_id);
}
});
bot.onText(/^\/ban(@\w+)?$/, (msg, match) => {
if (config.admin[msg.from.id]) {
log(
msg.chat.id + ':' + msg.from.id,
'ban'
);
enable = true;
}
});
bot.onText(/^\/unban(@\w+)?$/, (msg, match) => {
if (config.admin[msg.from.id]) {
log(
msg.chat.id + ':' + msg.from.id,
'unban'
);
enable = false;
}
});