Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var irc = require('irc');
- var os = require('os');
- var commandChar = '+';
- var password = '<pw>';
- var ops = ['Shuudoushi', 'Shuudoushi-MC'];
- var bot = new irc.Client('irc.pc-logix.com', 'ShuuBot', {
- userName: 'Shuu',
- channels: ['#Shuu'],
- port: 6667,
- realName: 'ShuuBot',
- debug: true,
- showErrors: true,
- autoRejoin: true,
- });
- var cmds = {
- ram: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'ram')
- {
- bot.say(to, 'Free RAM: '+Math.round(os.freemem()/1048576)+'/'+Math.round(os.totalmem()/1048576)+'MB');
- }
- },
- cycle: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'cycle')
- {
- if (args.length == 2)
- {
- if (args[1].startsWith('#'))
- {
- bot.send('cycle', args[1]);
- }
- else
- {
- bot.notice(from, 'Second argument must be a channel.');
- }
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'cycle #channel');
- }
- }
- },
- join: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'join')
- {
- if (args.length == 2)
- {
- if (args[1].startsWith('#'))
- {
- bot.join(args[1]);
- bot.notice(from, 'Joined: '+args[1]);
- }
- else
- {
- bot.notice(from, 'Second argument must be a channel.');
- }
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'join #channel');
- }
- }
- },
- part: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'part')
- {
- if (args.length == 2)
- {
- if (args[1].startsWith('#'))
- {
- bot.part(args[1]);
- bot.notice(from, 'Parted: '+args[1]);
- }
- else
- {
- bot.notice(from, 'Second argument must be a channel.');
- }
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'part #channel');
- }
- }
- },
- cmdChar: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'cmdChar')
- {
- if (args.length == 2)
- {
- commandChar = args[1];
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'cmdChar newCmdChar');
- }
- }
- },
- reboot: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'reboot')
- {
- process.exit(1);
- }
- },
- kill: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'reboot')
- {
- process.exit(0);
- }
- },
- op: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'op')
- {
- if (args.length == 2)
- {
- if (ops.indexOf(args[1] != -1))
- {
- ops.push(args[1]);
- bot.notice(from, 'Added '+args[1]+' to the ops list.')
- }
- else
- {
- bot.notice(from, 'Cannot op '+args[1]+'. '+args[1]+' is already a op.');
- }
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'op nickname');
- }
- }
- },
- deop: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'deop')
- {
- if (args.length == 2)
- {
- if (ops.indexOf(args[1]) != -1)
- {
- ops.splice(ops.indexOf(args[1]), 1);
- bot.notice(from, 'Removed '+args[1]+' from the ops list.');
- }
- else
- {
- bot.notice(from, 'Cannot remove '+args[1]+' from ops list. '+args[1]+' is not a op.');
- }
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'deop nickname');
- }
- }
- },
- ops: function(args, message, from, to)
- {
- if (args[0].toLowerCase() == commandChar+'ops')
- {
- bot.notice(from, 'Ops: '+ops.join(', '));
- }
- },
- id: function(args, message, from, to)
- {
- bot.say('NickServ', 'IDENTIFY '+password);
- }
- };
- if (typeof String.prototype.startsWith != 'function') {
- String.prototype.startsWith = function (str){
- return this.slice(0, str.length) == str;
- };
- }
- if (typeof String.prototype.contains != 'function') {
- String.prototype.contains = function(it)
- {
- return this.indexOf(it) != -1;
- };
- }
- bot.addListener('error', function(message) {
- console.log('ERROR: %s: %s', message.command, message.args.join(' '));
- });
- bot.addListener('message#', function (from, to, message) {
- console.log('%s => %s: %s', to, from, message);
- var args = message.split(' ');
- for (var name in ops)
- {
- if (from == ops[name])
- {
- if (message.startsWith(commandChar))
- {
- for (var cmd in cmds)
- {
- cmds[cmd](args, message, from, to);
- }
- }
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement