-
Notifications
You must be signed in to change notification settings - Fork 2
/
wat.js
148 lines (131 loc) · 4.34 KB
/
wat.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var irc = require('irc');
var config = require('./config');
function ignore(from) {
return from.indexOf('dwong') !== -1 || from.indexOf('firebot') !== -1;
}
// Replaces "should have" by "shuhao" in sentences people say
function reactToShouldHave(client)
{
var rgx = ['should have', "should've", 'should of'];
client.addListener('message', function (from, chan, message) {
if (ignore(from))
return;
for (var i = 0; i < rgx.length; ++i) {
var diff = message.replace(rgx[i], '*shuhao');
if (diff !== message) {
client.say(chan, from + ': ' + diff);
break;
}
}
});
}
// Reacts to messages containing only a smiley
function smiley(client)
{
var base = {
'o.o': 'O.O',
'o.O': 'O.o',
'-_-': 'T_T',
':)': ':D',
'>_>': '<_<',
'o.0': '0.o',
'0.0': '\\o/'
};
var smileys = {}, rgx = {}
function sanitizeRgx (t) {
return t.replace('.', '\\.').replace(')', '\\)');
}
for (var s in base) {
smileys[s] = base[s];
smileys[base[s]] = s;
rgx[s] = new RegExp(sanitizeRgx('^' + s + '$'));
rgx[base[s]] = new RegExp(sanitizeRgx('^' + base[s] + '$'));
}
client.addListener('message', function(from, chan, message) {
if (ignore(from))
return;
for (var s in rgx) {
if (rgx[s].test(message)) {
client.say(chan, smileys[s]);
break;
}
}
});
}
// Invite people to go to crepevine together
function crepevine(client)
{
var lastCrepevineInvite = Date.now();
var firstTime = true;
client.addListener('message', function(from, chan, message) {
if (ignore(from))
return;
// Avoid inviting people to crepevine more than once every 5 minutes
var diffCrepevine = (Date.now() - lastCrepevineInvite) / 1000;
const CREPEVINE_THRESHOLD = 5 * 60; // 5 minutes
var canSend = firstTime || diffCrepevine > CREPEVINE_THRESHOLD;
if (message.toLowerCase().indexOf("crepevine") !== -1 && canSend) {
client.say(chan, from + ': let\'s go. pool 5 min?');
lastCrepevineInvite = Date.now();
firstTime = false;
}
});
}
function whatever(client)
{
var quote = ['whatever', "it's fine", "rockband?", "pool?", "crepevine?", "club house?", 'big jumbo platter?', 'DUDE', 'wat', 'WAT'];
var hater = ['webdev', 'firefox OS', 'indexeddb', 'PaaS', 'guitar', 'javascript'];
client.addListener('message', function(from, chan, message) {
if (from == 'Pwnna' || from == 'Punna' || from == 'Ponna') {
if (Math.random() > 0.85) {
client.say(chan, from + ': ' + quote[Math.floor(Math.random() * quote.length)]);
} else if (Math.random() > 0.98) {
var which = hater[Math.floor(Math.random() * hater.length)];
client.say(chan, from + ': I hate ' + which + '. ' + which + " is too hard. I should just coach " + which + 'instead.');
}
}
});
}
function godmode(client)
{
client.addListener('pm', function(from, message) {
if (from == 'bbrittain' || from == 'bbouvier'){
client.say('#interns', message);
} else {
// Repeat direct messages to owners
var message = from + ': ' + message;
client.say('bbrittain', message);
client.say('bbouvier', message);
}
});
}
var extensions = [reactToShouldHave, smiley, whatever, crepevine, godmode];
function run(names)
{
var client = new irc.Client(config.server, names.nick, {
debug: true,
channels: config.channels,
userName: names.userName,
realName: names.realName,
retryDelay: 120000
});
for (var i = 0, e = extensions.length; i < e; ++i) {
extensions[i](client);
}
}
function changeName()
{
var names = ['john', 'mark', 'robert', 'rubber', 'patrick', 'wu', 'lulz', 'troll', 'wat'];
var number = Math.floor(Math.random() * 255);
var usedName = names[Math.floor(Math.random() * names.length)] + number;
return {
nick: usedName,
userName: usedName,
realName: usedName
}
}
run(config);
process.on('uncaughtException', function(err) {
var names = changeName();
run(names);
});