Skip to content

Instantly share code, notes, and snippets.

@makenowjust
Last active August 29, 2015 14:02
Show Gist options
  • Save makenowjust/712a8d7ddd907c8d2a60 to your computer and use it in GitHub Desktop.
Save makenowjust/712a8d7ddd907c8d2a60 to your computer and use it in GitHub Desktop.
No29-botのソースコードです
var
vm = require('vm'),
irc = require('irc'),
cfg = require('./config');
var
bot = new irc.Client(cfg.server, cfg.nickName, {
channels: cfg.channels,
});
var
regex = new RegExp('^\\s*@' + cfg.nickName + '\\s+([^]+)$');
bot.addListener('join', function (chan, nickName) {
console.log('join ' + nickName + ' => ' + chan);
if (nickName === cfg.nickName) {
bot.say(chan, cfg.nickName + 'が起動しましたし');
} else {
bot.say(chan, '@' + nickName + ' さんこんにちはです〜');
}
});
bot.addListener('message', function (from, to, msg) {
var
m, res;
console.log(to + ' => ' + from + ' : ' + msg);
if (m = msg.match(regex)) {
try {
res = vm.runInNewContext('with(Math){' + m[1] + '}', null, '<sandbox>');
} catch (e) {
res = e;
}
bot.say(to, '@' + from + ' ' + res);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment