-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
52 lines (46 loc) · 1.35 KB
/
index.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
const routes = require('./routes');
const bot = require('./bot');
const misuhLimit = {};
bot.hears(/(jancuk|kontol|memek|goblok|tolol)/i, context => {
const username = context.update.message.from.username;
const limit = misuhLimit[username];
if (!limit || limit < 2) {
misuhLimit[username] = limit ? limit + 1 : 1;
context.reply(`@${username} gak boleh ngomong kasar! ${3 - misuhLimit[username]} kali lagi ngomong jorok aku kick ya!`);
} else {
try {
const user_id = context.update.message.from.id;
context.kickChatMember(user_id);
} catch(err) {
context.reply(`error ngekick @${username} nih :(`);
}
}
});
routes.forEach(item => {
if (item.event) {
bot.on(item.event, async ctx => {
item.action(ctx);
});
}
if (item.command) {
bot.command(item.command, async (ctx) => {
const message = ctx.update.message.text;
const params = message
.replace(`/${item.command} `, '')
.split(/\s(?=(?:[^'"`“]*(['"`”]).*?\1)*[^'"`”]*$)/g)
.filter(item => !!item);
item.action(ctx, params);
});
}
if (item.prefix) {
bot.hears(item.prefix, ctx => {
const message = ctx.match.input;
if (item.suffix) {
if (message.match(item.suffix) !== null) item.action(ctx);
} else {
item.action(ctx);
}
});
}
});
bot.startPolling();