Skip to content

Commit

Permalink
lint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mmb committed May 5, 2011
1 parent 7f39a39 commit 1f39887
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 33 deletions.
21 changes: 21 additions & 0 deletions COPYING
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2011 Matthew M. Boedicker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion README
@@ -1,3 +1,3 @@
IRC bot written in node.js.

In part an exercise to learn node.js so it might suck for a while.
First node.js project use at own risk.
63 changes: 31 additions & 32 deletions lousybot.js
@@ -1,12 +1,12 @@
var serverHost = '127.0.0.1',
serverPort = 6668,
serverPass = 'snails68Ibo',
botNick = 'lousybot',
joinChannels = [ '#test' ],
pluginDir = './plugins';
serverPort = 6668,
serverPass = '*',
botNick = 'lousybot',
joinChannels = [ '#test' ],
pluginDir = './plugins',

fs = require('fs');
net = require('net');
fs = require('fs'),
net = require('net');

function formatIrcMessage(command, text) {
return command + ' ' + text + '\r\n';
Expand All @@ -15,13 +15,12 @@ function formatIrcMessage(command, text) {
function parseIrcMessage(s) {
console.log('parse ' + s);

var match = s.match(/(?::(.+?) )?(.+?) (.*)\r\n/);

parsed = {
prefix : match[1],
command : match[2],
params : match[3].split(' ')
};
var match = s.match(/(?::(.+?) )?(.+?) (.*)\r\n/),
parsed = {
prefix : match[1],
command : match[2],
params : match[3].split(' ')
};

console.log(parsed);

Expand All @@ -30,19 +29,19 @@ function parseIrcMessage(s) {

function loadPlugins(path) {
var exp,
plugin,
pluginPath;
plugin,
pluginPath;

fs.readdirSync(path).forEach(function(file) {
if (file.match(/\.js$/)) {
pluginPath = path + '/' + file;
console.log('require ' + pluginPath);
plugin = require(pluginPath);

for (exp in plugin) {
conn.addListener(exp, plugin[exp]);
}
}
pluginPath = path + '/' + file;
console.log('require ' + pluginPath);
plugin = require(pluginPath);

for (exp in plugin) {
conn.addListener(exp, plugin[exp]);
}
}
});
}

Expand Down Expand Up @@ -73,7 +72,7 @@ conn.addListener('data', function(buffer) {
this.messageSoFar += buffer.toString();

if (this.messageSoFar.match(/\r\n$/)) {
message = parseIrcMessage(this.messageSoFar.slice(0));
message = parseIrcMessage(this.messageSoFar.slice(0));
this.emit(message.command, message);
this.messageSoFar = '';
}
Expand All @@ -86,7 +85,7 @@ conn.addListener('001', function() {
var connection = this;

joinChannels.forEach(function(channel) {
connection.sendMessage('JOIN', channel);
connection.sendMessage('JOIN', channel);
});
});

Expand All @@ -101,15 +100,15 @@ conn.addListener('PRIVMSG', function(m) {
var hostmaskMatch = m.prefix.match(/(.+)!(.+)@(.+)/);

if (hostmaskMatch) {
m.from = {
nick : hostmaskMatch[1],
user : hostmaskMatch[2],
host : hostmaskMatch[3]
};
m.from = {
nick : hostmaskMatch[1],
user : hostmaskMatch[2],
host : hostmaskMatch[3]
};
}

if (m.to.match(/^#/)) {
m.channel = m.to;
m.channel = m.to;
this.emit('channelMessage', m);
} else {
this.emit('privateMessage', m);
Expand Down
15 changes: 15 additions & 0 deletions plugins/greeter.js
@@ -0,0 +1,15 @@
function isGreeting(s) {
return s.match(/^(hi|hello)$/i);
}

exports.channelMessage = function (m) {
if (isGreeting(m.text)) {
this.privmsg(m.to, 'hi ' + m.from.nick);
}
};

exports.privateMessage = function (m) {
if (isGreeting(m.text)) {
this.privmsg(m.from.nick, 'hi ' + m.from.nick);
}
};

0 comments on commit 1f39887

Please sign in to comment.