Skip to content

Instantly share code, notes, and snippets.

@kaw2k
Last active December 21, 2015 07:28
Show Gist options
  • Save kaw2k/6271221 to your computer and use it in GitHub Desktop.
Save kaw2k/6271221 to your computer and use it in GitHub Desktop.
Simple all caps javascript bot
// Import settings
var settings = require('./settings');
// Setup IRC
var irc = require('irc');
var bot = new irc.Client(settings.server, settings.botName, settings);
console.log(
settings.botName + ' connecting to ' + settings.server + settings.channels
);
//+ directlyAddressed :: {} -> boolean
function directlyAddressed (message) {
return (new RegExp(settings.botName, 'i')).test(message.text);
};
//+ isAllCaps :: {} -> boolean
function isAllCaps (message) {
return message.text.toUpperCase() === message.text;
}
// Do something for every raw message
bot.addListener('raw', function (msg) {
// Break out early if we get a garbage message
if(msg.command !== 'PRIVMSG' || !msg.args || msg.args.length < 2)
return;
var message = {
username: msg.nick,
channel: msg.args[0],
text: msg.args[1]
}
if (directlyAddressed(message))
console.log(message.username + ' :: ' + message.text);
if (!isAllCaps(message)) {
console.log('Booting: ' + message.username);
bot.send('KICK', message.channel, message.username, 'USE ALLCAPS BRO.');
bot.say(message.channel, 'BOOM, ' + message.username + ' GOT B00TED');
}
});
var settings = {
server: '',
port: 6667,
channels: ['#channel'],
botName: '',
userName: '',
realName: '',
// Omit this if you don't need SSL
secure: {
passphrase: 'We_built_that_app.',
rejectUnauthorized: false
},
password: 'We_built_that_app.',
certExpired: true,
selfSigned: true
// Debugging things
//debug: true,
//showErrors: true,
}
if (module && module.exports)
module.exports = settings;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment