Advertisement
Shuudoushi

Untitled

May 6th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var irc = require('irc');
  2.  
  3. var os = require('os');
  4.  
  5.  
  6.  
  7. var commandChar = '+';
  8.  
  9. var password = '<pw>';
  10.  
  11.  
  12.  
  13. var ops = ['Shuudoushi', 'Shuudoushi-MC'];
  14.  
  15.  
  16.  
  17. var bot = new irc.Client('irc.pc-logix.com', 'ShuuBot', {
  18.  
  19.     userName: 'Shuu',
  20.  
  21.     channels: ['#Shuu'],
  22.  
  23.     port: 6667,
  24.  
  25.     realName: 'ShuuBot',
  26.  
  27.     debug: true,
  28.  
  29.     showErrors: true,
  30.  
  31.     autoRejoin: true,
  32.  
  33. });
  34.  
  35.  
  36.  
  37. var cmds = {
  38.  
  39.     ram: function(args, message, from, to)
  40.  
  41.     {
  42.  
  43.         if (args[0].toLowerCase() == commandChar+'ram')
  44.  
  45.         {
  46.  
  47.             bot.say(to, 'Free RAM: '+Math.round(os.freemem()/1048576)+'/'+Math.round(os.totalmem()/1048576)+'MB');
  48.  
  49.         }
  50.  
  51.     },
  52.  
  53.     cycle: function(args, message, from, to)
  54.  
  55.     {
  56.  
  57.         if (args[0].toLowerCase() == commandChar+'cycle')
  58.  
  59.         {
  60.  
  61.             if (args.length == 2)
  62.  
  63.             {
  64.  
  65.                 if (args[1].startsWith('#'))
  66.  
  67.                 {
  68.  
  69.                     bot.send('cycle', args[1]);
  70.  
  71.                 }
  72.  
  73.                 else
  74.  
  75.                 {
  76.  
  77.                     bot.notice(from, 'Second argument must be a channel.');
  78.  
  79.                 }
  80.  
  81.             }
  82.  
  83.             else
  84.  
  85.             {
  86.  
  87.                 bot.notice(from, 'Usage: '+commandChar+'cycle #channel');
  88.  
  89.             }
  90.  
  91.         }
  92.  
  93.     },
  94.  
  95.     join: function(args, message, from, to)
  96.  
  97.     {
  98.  
  99.         if (args[0].toLowerCase() == commandChar+'join')
  100.  
  101.         {
  102.  
  103.             if (args.length == 2)
  104.  
  105.             {
  106.  
  107.                 if (args[1].startsWith('#'))
  108.  
  109.                 {
  110.  
  111.                     bot.join(args[1]);
  112.  
  113.                     bot.notice(from, 'Joined: '+args[1]);
  114.  
  115.                 }
  116.  
  117.                 else
  118.  
  119.                 {
  120.  
  121.                     bot.notice(from, 'Second argument must be a channel.');
  122.  
  123.                 }
  124.  
  125.             }
  126.  
  127.             else
  128.  
  129.             {
  130.  
  131.                 bot.notice(from, 'Usage: '+commandChar+'join #channel');
  132.  
  133.             }
  134.  
  135.         }
  136.  
  137.     },
  138.  
  139.     part: function(args, message, from, to)
  140.  
  141.     {
  142.  
  143.         if (args[0].toLowerCase() == commandChar+'part')
  144.  
  145.         {
  146.  
  147.             if (args.length == 2)
  148.  
  149.             {
  150.  
  151.                 if (args[1].startsWith('#'))
  152.  
  153.                 {
  154.  
  155.                     bot.part(args[1]);
  156.  
  157.                     bot.notice(from, 'Parted: '+args[1]);
  158.  
  159.                 }
  160.  
  161.                 else
  162.  
  163.                 {
  164.  
  165.                     bot.notice(from, 'Second argument must be a channel.');
  166.  
  167.                 }
  168.  
  169.             }
  170.  
  171.             else
  172.  
  173.             {
  174.  
  175.                 bot.notice(from, 'Usage: '+commandChar+'part #channel');
  176.  
  177.             }
  178.  
  179.         }
  180.  
  181.     },
  182.  
  183.     cmdChar: function(args, message, from, to)
  184.  
  185.     {
  186.  
  187.         if (args[0].toLowerCase() == commandChar+'cmdChar')
  188.  
  189.         {
  190.  
  191.             if (args.length == 2)
  192.  
  193.             {
  194.  
  195.                 commandChar = args[1];
  196.  
  197.             }
  198.  
  199.             else
  200.  
  201.             {
  202.  
  203.                 bot.notice(from, 'Usage: '+commandChar+'cmdChar newCmdChar');
  204.  
  205.             }
  206.  
  207.         }  
  208.  
  209.     },
  210.  
  211.     reboot: function(args, message, from, to)
  212.  
  213.     {
  214.  
  215.         if (args[0].toLowerCase() == commandChar+'reboot')
  216.  
  217.         {
  218.  
  219.             process.exit(1);
  220.  
  221.         }
  222.  
  223.     },
  224.  
  225.     kill: function(args, message, from, to)
  226.  
  227.     {
  228.  
  229.         if (args[0].toLowerCase() == commandChar+'reboot')
  230.  
  231.         {
  232.  
  233.             process.exit(0);
  234.  
  235.         }
  236.  
  237.     },
  238.  
  239.     op: function(args, message, from, to)
  240.  
  241.     {
  242.  
  243.         if (args[0].toLowerCase() == commandChar+'op')
  244.  
  245.         {
  246.  
  247.             if (args.length == 2)
  248.  
  249.             {
  250.  
  251.                 if (ops.indexOf(args[1] != -1))
  252.  
  253.                 {
  254.  
  255.                     ops.push(args[1]);
  256.  
  257.                     bot.notice(from, 'Added '+args[1]+' to the ops list.')
  258.  
  259.                 }
  260.  
  261.                 else
  262.  
  263.                 {
  264.  
  265.                     bot.notice(from, 'Cannot op '+args[1]+'. '+args[1]+' is already a op.');
  266.  
  267.                 }
  268.  
  269.             }
  270.  
  271.             else
  272.  
  273.             {
  274.  
  275.                 bot.notice(from, 'Usage: '+commandChar+'op nickname');
  276.  
  277.             }
  278.  
  279.         }
  280.  
  281.     },
  282.  
  283.     deop: function(args, message, from, to)
  284.  
  285.     {
  286.  
  287.         if (args[0].toLowerCase() == commandChar+'deop')
  288.  
  289.         {
  290.  
  291.             if (args.length == 2)
  292.  
  293.             {
  294.  
  295.                 if (ops.indexOf(args[1]) != -1)
  296.  
  297.                 {
  298.  
  299.                     ops.splice(ops.indexOf(args[1]), 1);
  300.  
  301.                     bot.notice(from, 'Removed '+args[1]+' from the ops list.');
  302.  
  303.                 }
  304.  
  305.                 else
  306.  
  307.                 {
  308.  
  309.                     bot.notice(from, 'Cannot remove '+args[1]+' from ops list. '+args[1]+' is not a op.');
  310.  
  311.                 }
  312.  
  313.             }
  314.  
  315.             else
  316.  
  317.             {
  318.  
  319.                 bot.notice(from, 'Usage: '+commandChar+'deop nickname');
  320.  
  321.             }
  322.  
  323.         }
  324.  
  325.     },
  326.  
  327.     ops: function(args, message, from, to)
  328.  
  329.     {
  330.  
  331.         if (args[0].toLowerCase() == commandChar+'ops')
  332.  
  333.         {
  334.  
  335.             bot.notice(from, 'Ops: '+ops.join(', '));
  336.  
  337.         }
  338.  
  339.     },
  340.  
  341.     id: function(args, message, from, to)
  342.  
  343.     {
  344.  
  345.         bot.say('NickServ', 'IDENTIFY '+password);
  346.  
  347.     }
  348.  
  349. };
  350.  
  351.  
  352.  
  353. if (typeof String.prototype.startsWith != 'function') {
  354.  
  355.     String.prototype.startsWith = function (str){
  356.  
  357.         return this.slice(0, str.length) == str;
  358.  
  359.     };
  360.  
  361. }
  362.  
  363.  
  364.  
  365. if (typeof String.prototype.contains != 'function') {
  366.  
  367.     String.prototype.contains = function(it)
  368.  
  369.     {
  370.  
  371.         return this.indexOf(it) != -1;
  372.  
  373.     };
  374.  
  375. }
  376.  
  377.  
  378.  
  379. bot.addListener('error', function(message) {
  380.  
  381.     console.log('ERROR: %s: %s', message.command, message.args.join(' '));
  382.  
  383. });
  384.  
  385.  
  386.  
  387. bot.addListener('message#', function (from, to, message) {
  388.  
  389.     console.log('%s => %s: %s', to, from, message);
  390.  
  391.    
  392.  
  393.     var args = message.split(' ');
  394.  
  395.  
  396.  
  397.     for (var name in ops)
  398.  
  399.     {
  400.  
  401.         if (from == ops[name])
  402.  
  403.         {
  404.  
  405.             if (message.startsWith(commandChar))
  406.  
  407.             {
  408.  
  409.                 for (var cmd in cmds)
  410.  
  411.                 {
  412.  
  413.                     cmds[cmd](args, message, from, to);
  414.  
  415.                 }
  416.  
  417.             }
  418.  
  419.         }
  420.  
  421.     }
  422.  
  423. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement