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 = '<password>';
- var bot = new irc.Client('irc.pc-logix.com', 'ShuuBot', {
- userName: 'ShuuBot',
- channels: ['#Shuu'],
- port: 6667,
- realName: 'ShuuBot ',
- debug: false,
- showErrors: true,
- autoRejoin: true,
- });
- bot.say('NickServ', 'IDENTIFY '+password);
- var cmds = {
- ram: function(args, message, from, to)
- {
- if (message.toLowerCase(args[0]) == 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 (message.toLowerCase(args[0]) == 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');
- }
- }
- },
- cmds: function(args, message, from, to)
- {
- if (message.toLowerCase(args[0]) == commandChar+'cmds')
- {
- bot.notice(from, cmds.join(''));
- }
- },
- join: function(args, message, from, to)
- {
- if (message.toLowerCase(args[0]) == 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 (message.toLowerCase(args[0]) == commandChar+'part')
- {
- if (args.length == 2)
- {
- if (args[1].startsWith('#'))
- {
- bot.part(args[1]);
- bot.notice(from, 'Joined: '+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 (message.toLowerCase(args[0]) == commandChar+'cmdChar')
- {
- if (args.length == 2)
- {
- commandChar = args[1];
- }
- else
- {
- bot.notice(from, 'Usage: '+commandChar+'cmdChar newCmdChar');
- }
- }
- },
- reboot: function(args, message, from, to)
- {
- if (message.toLowerCase(args[0]) == commandChar+'reboot')
- {
- process.exit(1);
- }
- },
- kill: function(args, message, from, to)
- {
- if (message.toLowerCase(args[0]) == commandChar+'reboot')
- {
- process.exit(0);
- }
- }
- };
- 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(' ');
- if (message.startsWith(commandChar))
- {
- for (cmd in cmds)
- {
- cmds[cmd](args, message, from, to);
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement