This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
79 lines (70 loc) · 2.03 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
var flip = require('flip-text');
class ShrugBot9000 extends global.AKP48.pluginTypes.MessageHandler {
constructor(AKP48) {
super(AKP48, 'ShrugBot9000');
if(!global.shrugTimes) {
global.shrugTimes = {};
}
this.data = require('./shrug.json');
}
}
ShrugBot9000.prototype.handleCommand = function(context) {
context.setCustomData('noPrefix', true);
if(this.data.commands[context.command()]) {
return this.reply(context.command(), this.data.commands[context.command()].replace('{text}', context.argText()).replace('{flip}', flip(context.argText()) || '🙃'), context);
}
switch(context.command().toLowerCase()) {
case 'rl':
case 'reload':
return global.AKP48.reload();
default:
return;
}
};
ShrugBot9000.prototype.handleMessage = function (context) {
context.setCustomData('noPrefix', true);
var text = context.text().toLowerCase().split(' ');
var sendCount = 0;
for (var i = 0; i < text.length && sendCount < 2; i++) {
var w = this.getWord(text[i], this.data.words);
if(w) {
this.reply(w.name, w.output, context);
sendCount++;
}
}
};
ShrugBot9000.prototype.getWord = function (word, list) {
for (var i = 0; i < list.length; i++) {
if(word.toLowerCase().includes(list[i].name.toLowerCase())) {
if(list[i].nomatch && word.toLowerCase().includes(list[i].nomatch.toLowerCase())) {
return false;
}
return list[i];
}
}
return false;
};
ShrugBot9000.prototype.canSend = function (cmd, to) {
var times = global.shrugTimes[cmd];
if(!times) {
global.shrugTimes[cmd] = {};
global.shrugTimes[cmd][to] = Date.now();
return true;
}
if(!times[to]) {
global.shrugTimes[cmd][to] = Date.now();
return true;
}
if(Date.now() - times[to] > 15000) {
global.shrugTimes[cmd][to] = Date.now();
return true;
}
return false;
};
ShrugBot9000.prototype.reply = function (cmd, msg, context) {
if(this.canSend(cmd, context.to())) {
return context.reply(msg);
}
};
module.exports = ShrugBot9000;