robotirc

Multifonction IRC bot written in Node.js
Log | Files | Refs | README | LICENSE

commit 65dfba0b01b7ae885937254d82be33d00dd07de6
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date:   Thu,  2 Jan 2014 23:08:54 +0100

Initial commit

Diffstat:
ALICENSE | 24++++++++++++++++++++++++
AREADME.md | 16++++++++++++++++
Aconfig.json | 14++++++++++++++
Aindex.js | 1+
Alib/robotirc.js | 153+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackage.json | 33+++++++++++++++++++++++++++++++++
6 files changed, 241 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2013-2014, Frederic Cambus +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md @@ -0,0 +1,16 @@ +# RobotIRC + +## Description + +Multifonction IRC bot written in Node. + +## License + +RobotIRC is released under the BSD 2-Clause license. See `LICENSE` file for details. + +## Author + +RobotIRC is developed by Frederic Cambus + +- Site : http://www.cambus.net +- Twitter: http://twitter.com/fcambus diff --git a/config.json b/config.json @@ -0,0 +1,14 @@ +{ + "server": "irc.freenode.net", + "nickname": "robotirc", + "options": { + "userName": "robotirc", + "realName": "RobotIRC 0.1.0", + "port": 6667, + "autoRejoin": true, + "autoConnect": true, + "channels": [ + "#robotirc" + ] + } +} diff --git a/index.js b/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/robotirc'); diff --git a/lib/robotirc.js b/lib/robotirc.js @@ -0,0 +1,153 @@ +/*****************************************************************************/ +/* */ +/* RobotIRC 0.1.0 (c) by Frederic Cambus 2013-2014 */ +/* https://github.com/fcambus/robotirc */ +/* */ +/* Created: 2013/12/17 */ +/* Last Updated: 2014/01/02 */ +/* */ +/* RobotIRC is released under the BSD 2-Clause license. */ +/* See LICENSE file for details. */ +/* */ +/*****************************************************************************/ + +var dns = require('dns'); +var net = require('net'); +var crypto = require('crypto'); + + + +/**[ NPM Modules ]************************************************************/ + +var irc = require('irc'); +var request = require('request'); + + + +/**[ Configuration ]**********************************************************/ + +var config = require("../config.json") + +var client = new irc.Client(config.server, config.nickname, config.options); + + + +/**[ Error handler ]**********************************************************/ + +client.addListener('error', function(message) { + console.log('ERROR : ', message); +}); + + + +/**[ Message handler ]********************************************************/ + +client.addListener('message', function(from, to, message) { + var params = message.split(' ').slice(1).join(' '); + + /**************************************************************[ !help ]**/ + + if (message.match(/^!help/)) { + var help = "RobotIRC 0.1.0 supports the following commands :\n" + + "!date => Display server local time\n" + + "!expand => Expand a shortened URL\n" + + "!geoip => IP address Geolocation\n" + + "!headers => Display HTTP headers for queried URL\n" + + "!resolve => Get A records (IPv4) and AAAA records (IPv6) for queried domain\n" + + "!reverse => Get reverse (PTR) records from IPv4 or IPv6 addresses\n" + + "!wikipedia => Query Wikipedia for an article summary\n"; + + client.say(to, help); + } + + /**************************************************************[ !date ]**/ + + if (message.match(/^!date/)) { + client.say(to, Date()); + } + + /************************************************************[ !expand ]**/ + + if (message.match(/^!expand/)) { + request({ + method: "HEAD", + url: params, + followAllRedirects: true + }, + function(error, response) { + if (!error && response.statusCode == 200) { + client.say(to, response.request.href); + console.log(response.request.href); + } + }); + } + + /*************************************************************[ !geoip ]**/ + + if (message.match(/^!geoip/)) { + request('http://www.telize.com/geoip/' + params, function(error, response, body) { + if (!error && response.statusCode == 200) { + var geoip = JSON.parse(response.body); + + for (item in data) { + client.say(to, item + ": " + geoip[item] + "\n"); + } + } + }) + } + + /***********************************************************[ !headers ]**/ + + if (message.match(/^!headers/)) { + request(params, function(error, response, body) { + if (!error && response.statusCode == 200) { + for (item in response.headers) { + client.say(to, item + ": " + response.headers[item] + "\n"); + } + } + }) + } + + /***********************************************************[ !resolve ]**/ + + if (message.match(/^!resolve/)) { + dns.resolve4(params, function(error, addresses) { + if (!error) { + for (item in addresses) { + client.say(to, addresses[item] + "\n"); + } + } + dns.resolve6(params, function(error, addresses) { + if (!error) { + for (item in addresses) { + client.say(to, addresses[item] + "\n"); + } + } + }); + }); + } + + /***********************************************************[ !reverse ]**/ + + if (message.match(/^!reverse/)) { + if (net.isIP(params)) { + dns.reverse(params, function(error, domains) { + if (!error) { + client.say(to, domains[0]); + } + }); + } + } + + /*********************************************************[ !wikipedia ]**/ + + if (message.match(/^!wikipedia/)) { + params.split(' ').join('_'); + + dns.resolveTxt(params + ".wp.dg.cx", function(error, txt) { + if (!error) { + client.say(to, txt[0]); + } + }); + } +}); diff --git a/package.json b/package.json @@ -0,0 +1,33 @@ +{ + "name": "robotirc", + "version": "0.1.0", + "description": "Multifonction IRC bot written in Node", + "main": "index.js", + "repository": { + "type": "git", + "url": "https://github.com/fcambus/robotirc" + }, + "keywords": [ + "irc", + "bot", + "dns", + "geoip", + "headers", + "wikipedia" + ], + "author": { + "name": "Frederic Cambus", + "url": "http://www.cambus.net" + }, + "licenses": [{ + "type": "BSD", + "url": "https://github.com/fcambus/robotirc/blob/master/LICENSE" + }], + "bugs": { + "url": "https://github.com/fcambus/robotirc/issues" + }, + "dependencies": { + "irc": "~0.3.6", + "request": "~2.30.0" + } +}