-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
152 lines (127 loc) · 3.87 KB
/
bot.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
149
150
151
152
require('dotenv').config();
const fs = require('fs');
const moment = require('moment');
// Get the lib
const irc = require("irc");
// Create the bot name
let bot = new irc.Client(process.env.IRC_NETWORK, process.env.BOT_NAME, {
channels: [process.env.IRC_CHANNEL]
});
// Global Variables
let logging_on = false,
file = null;
function notEmpty(value) {
return value !== null && value !== undefined && value !== '';
}
let kickUser = function(message, from) {
let pattern = commands.kick.pattern,
matches = pattern.exec(message),
name;
if(notEmpty(matches)) {
name = matches[1];
}
else {
return;
}
bot.say(from, 'Attempting to kick ' + name + ' ' + process.env.IRC_CHANNEL);
bot.send('KICK', process.env.IRC_CHANNEL, name);
}
const commands = {
kick: {
pattern: /kick ([\w\-\d]+) */,
command: kickUser,
},
};
const responses = {
name: {
pattern: new RegExp(process.env.BOT_NAME, 'i'),
command: respondToBotsName
}
}
// Listen for joins
bot.addListener("join", function(channel, who) {
// Welcome them in!
bot.say(channel, randomWelcome(who));
let admins = [
/^_?asc/i,
/^_?ck/i,
/^_?ian/i,
];
for (let i in admins) {
if(admins[i].test(who)) {
bot.send('MODE',process.env.IRC_CHANNEL,'+o', who);
}
}
});
// Listen for any commands sent via pm
bot.addListener("pm", function(from, to, message) {
let command = message.args[1];
for(type in commands) {
if(commands[type].pattern.test(command)) {
commands[type].command(command, from);
}
}
});
// Listen to messages in channel
bot.addListener('message' + process.env.IRC_CHANNEL, function (from, message) {
console.log(from + ' on '+ process.env.IRC_CHANNEL + ': ' + message);
if(logging_on) {
logChatToFile(from, message);
}
for(type in responses) {
if(responses[type].pattern.test(message)) {
responses[type].command(from, message);
}
}
});
/* Functions */
function randomWelcome(who) {
let messages = [
who + ', welcome back!',
who + ', what\'s new?',
'Howdy, ' + who + '!',
'Oh, no! Not ' + who + ' again.',
'Hey there, ' + who + "!",
'What\'s happenin\', ' + who + "?",
'Hi, '+ who +'!',
'Here\'s ' + who + "!",
'Greetings and salutations, '+ who + '!',
'Oh, no! Not ' + who + ' again.',
'Oh, yoohoo, '+ who + '!',
'Aloha, ' + who + "!",
'Hola, ' + who + '!',
'Que Pasa, ' + who + "?",
'Konnichiwa, ' + who + '!',
'Namaste, ' + who + '!',
'Oh, no! Not ' + who + ' again.',
];
return messages[Math.floor(Math.random() * messages.length)];
}
function respondToBotsName(from, message) {
if(/hi/i.test(message) ||
/hey/i.test(message) ||
/hello/i.test(message)) {
bot.say(process.env.IRC_CHANNEL, 'How are you, ' + from + '?');
}
else {
bot.say(process.env.IRC_CHANNEL, getRandomSaying());
}
}
function getRandomSaying() {
let sayings = [
'Huzzah!',
'Wha\'choo talin\' \'bout, Willis!',
'Discretion is the greater part of valor.',
'Everything you can imagine is real.',
'I could agree with you but then we’d both be wrong.',
"Fish and visitors stink after three days.",
"Black Holes are where God divided by zero.",
"I'd like to help you out. Which way did you come in?",
"On the other hand, you have different fingers.",
"Always remember to pillage BEFORE you burn.",
"Procrastination is the greatest labor saving invention of all time.",
'I don\'t suffer from insanity. I enjoy every minute of it.',
],
random = Math.floor(Math.random() * sayings.length);
return sayings[random];
}