forked from ceejbot/LOUDBOT-SLACK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SLACKBOT.js
74 lines (59 loc) · 1.39 KB
/
SLACKBOT.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
var FS = require('fs');
function ISLOUD(MSG)
{
return MSG !== MSG.toLowerCase() && MSG === MSG.toUpperCase();
}
var STARTERFILE = __dirname + '/STARTERS';
var STARTERS = FS.readFileSync(STARTERFILE, 'UTF8');
STARTERS = STARTERS.trim().split(/\n/);
var SAVEFILE = __dirname + '/LOUDS';
var SAVING = false;
var WAITING = [];
var LOUDBOT = module.exports = function LOUDBOT()
{
if (!(this instanceof LOUDBOT))
return new LOUDBOT();
var THIS = this;
try
{
THIS.LOUDS = FS.readFileSync(SAVEFILE, 'UTF8').trim().split('\n');
}
catch (ERRRRROR)
{
THIS.LOUDS = [];
}
THIS.LOUDS = THIS.LOUDS.concat(STARTERS);
};
LOUDBOT.prototype.LISTENUP = function LISTENUP(MSG)
{
var THIS = this;
if (ISLOUD(MSG))
{
THIS.REMEMBER(MSG);
return THIS.YELL();
}
};
LOUDBOT.prototype.REMEMBER = function REMEMBER(LOUD)
{
this.LOUDS.push(LOUD);
WAITING.push(LOUD);
if (SAVING) return;
SAVING = true;
FS.appendFile(SAVEFILE, WAITING.join('\n') + '\n', 'UTF8', function()
{
SAVING = false;
});
WAITING.length = 0;
};
LOUDBOT.prototype.YELL = function YELL()
{
var THIS = this;
var LEN = THIS.LOUDS.length;
var L = Math.floor(Math.random() * LEN)
var LOUD = THIS.LASTLOUD = THIS.LOUDS[L];
return LOUD;
};
LOUDBOT.prototype.THELOUDS = function THELOUDS()
{
return this.LOUDS;
};