Advertisement
Shuudoushi

broken

May 3rd, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var irc = require('irc');
  2. var os = require('os');
  3.  
  4. var commandChar = '~';
  5. var password = '<password>';
  6.  
  7. var bot = new irc.Client('irc.pc-logix.com', 'ShuuBot', {
  8.     userName: 'ShuuBot',
  9.     channels: ['#Shuu'],
  10.     port: 6667,
  11.     realName: 'ShuuBot ',
  12.     debug: false,
  13.     showErrors: true,
  14.     autoRejoin: true,
  15. });
  16.  
  17. bot.say('NickServ', 'IDENTIFY '+password);
  18.  
  19. var cmds = {
  20.     ram: function(args, message, from, to)
  21.     {
  22.         if (message.toLowerCase(args[0]) == commandChar+'ram')
  23.         {
  24.             bot.say(to, 'Free RAM: '+Math.round(os.freemem()/1048576)+'/'+Math.round(os.totalmem()/1048576)+'MB');
  25.         }
  26.     },
  27.     cycle: function(args, message, from, to)
  28.     {
  29.         if (message.toLowerCase(args[0]) == commandChar+'cycle')
  30.         {
  31.             if (args.length == 2)
  32.             {
  33.                 if (args[1].startsWith('#'))
  34.                 {
  35.                     bot.send('cycle', args[1]);
  36.                 }
  37.                 else
  38.                 {
  39.                     bot.notice(from, 'Second argument must be a channel.');
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 bot.notice(from, 'Usage: '+commandChar+'cycle #channel');
  45.             }
  46.         }
  47.     },
  48.     cmds: function(args, message, from, to)
  49.     {
  50.         if (message.toLowerCase(args[0]) == commandChar+'cmds')
  51.         {
  52.             bot.notice(from, cmds.join(''));    
  53.         }
  54.     },
  55.     join: function(args, message, from, to)
  56.     {
  57.         if (message.toLowerCase(args[0]) == commandChar+'join')
  58.         {
  59.             if (args.length == 2)
  60.             {
  61.                 if (args[1].startsWith('#'))
  62.                 {
  63.                     bot.join(args[1]);
  64.                     bot.notice(from, 'Joined: '+args[1]);
  65.                 }
  66.                 else
  67.                 {
  68.                     bot.notice(from, 'Second argument must be a channel.');
  69.                 }
  70.             }
  71.             else
  72.             {
  73.                 bot.notice(from, 'Usage: '+commandChar+'join #channel');
  74.             }
  75.         }
  76.     },
  77.     part: function(args, message, from, to)
  78.     {
  79.         if (message.toLowerCase(args[0]) == commandChar+'part')
  80.         {
  81.             if (args.length == 2)
  82.             {
  83.                 if (args[1].startsWith('#'))
  84.                 {
  85.                     bot.part(args[1]);
  86.                     bot.notice(from, 'Joined: '+args[1]);
  87.                 }
  88.                 else
  89.                 {
  90.                     bot.notice(from, 'Second argument must be a channel.');
  91.                 }
  92.             }
  93.             else
  94.             {
  95.                 bot.notice(from, 'Usage: '+commandChar+'part #channel');
  96.             }
  97.         }
  98.     },
  99.     cmdChar: function(args, message, from, to)
  100.     {
  101.         if (message.toLowerCase(args[0]) == commandChar+'cmdChar')
  102.         {
  103.             if (args.length == 2)
  104.             {
  105.                 commandChar = args[1];
  106.             }
  107.             else
  108.             {
  109.                 bot.notice(from, 'Usage: '+commandChar+'cmdChar newCmdChar');
  110.             }
  111.         }  
  112.     },
  113.     reboot: function(args, message, from, to)
  114.     {
  115.         if (message.toLowerCase(args[0]) == commandChar+'reboot')
  116.         {
  117.             process.exit(1);
  118.         }
  119.     },
  120.     kill: function(args, message, from, to)
  121.     {
  122.         if (message.toLowerCase(args[0]) == commandChar+'reboot')
  123.         {
  124.             process.exit(0);
  125.         }
  126.     }
  127. };
  128.  
  129. if (typeof String.prototype.startsWith != 'function') {
  130.     String.prototype.startsWith = function (str){
  131.         return this.slice(0, str.length) == str;
  132.     };
  133. }
  134.  
  135. if (typeof String.prototype.contains != 'function') {
  136.     String.prototype.contains = function(it)
  137.     {
  138.         return this.indexOf(it) != -1;
  139.     };
  140. }
  141.  
  142. //
  143.  
  144. bot.addListener('error', function(message) {
  145.     console.log('ERROR: %s: %s', message.command, message.args.join(' '));
  146. });
  147.  
  148. bot.addListener('message#', function (from, to, message) {
  149.     console.log('%s => %s: %s', to, from, message);
  150.    
  151.     var args = message.split(' ');
  152.    
  153.     if (message.startsWith(commandChar))
  154.     {
  155.         for (cmd in cmds)
  156.         {
  157.             cmds[cmd](args, message, from, to);
  158.         }
  159.     }
  160. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement