Guest User

Untitled

a guest
Mar 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.63 KB | None | 0 0
  1. <?php
  2.  
  3. ##############################
  4. ## BotNick IRC Bot PHP-Beta ##
  5. ##### Created by Dead-i ######
  6. ##############################
  7.  
  8. // Set no time limit; run forever
  9. set_time_limit(0);
  10.  
  11. // Get the start date incase of status
  12.  
  13. command
  14. $startseconds = time();
  15.  
  16. // Opening the socket to the freenode network
  17. $socket = fsockopen("irc.x10hosting.com", 6667);
  18.  
  19. // Send auth info
  20. fputs($socket,"USER BotNick tomtiger11 CM :BotNick\n");
  21. fputs($socket,"NICK
  22.  
  23. BotNick\n");
  24. fputs($socket,"NS IDENTIFY forkingninja2011\n");
  25.  
  26. // Join channel
  27. fputs($socket,"JOIN #tomtiger11\n");
  28.  
  29. // Get the admin files
  30. $adminfile = file_get_contents('./admins.txt');
  31. $hostmasks = file_get_contents('./hostmasks.txt');
  32.  
  33. $staffpass = 'botnickpass';
  34.  
  35. // Force an endless while
  36. while(1) {
  37.  
  38.     // Continue the rest of the script here
  39.     while($data = fgets($socket, 522)) {
  40.        
  41.         if ($argv[1] == 'debug') {
  42.             echo
  43.  
  44. nl2br($data);
  45.         }
  46.         flush();
  47.  
  48.         // Separate all data
  49.         $ex = explode(' ', $data);
  50.  
  51.         // Send PONG back to the server
  52.         if($ex[0] == "PING"){
  53.            
  54.  
  55. fputs($socket, "PONG ".$ex[1]."\n");
  56.         }
  57.        
  58.         // Say something in the channel
  59.         $command = str_replace(array(chr(10), chr(13)), '', $ex[4]);
  60.        
  61.        
  62.  
  63. // Get the value if any
  64.         $value = str_replace(array(chr(10), chr(13)), '', $ex[5]);
  65.         if ($value == '@') $value = '';
  66.        
  67.         // Get the second value if any
  68.         $value2 =
  69.  
  70. str_replace(array(chr(10), chr(13)), '', $ex[6]);
  71.         $value2exploderand = explode($value2[0], '1234567890');
  72.         if (!isset($value2exploderand[1])) $value2 = '';
  73.        
  74.         // Explode the command;
  75.  
  76. useful in many purposes
  77.         $explode = explode(' ', $command);
  78.        
  79.         // Get the user's name; useful in many purposes
  80.         $userinfo = explode("!", $ex[0]);
  81.        
  82.        
  83.  
  84. // Detect if the message was directed toward someone
  85.         $directionexplode = explode(' @ ', $data);
  86.         if (!isset($directionexplode[1])) {
  87.             $recipient = $userinfo[0];
  88.         }else{
  89.    
  90.  
  91.         $recipient = ":".substr($directionexplode[1], 0, -2);
  92.         }
  93.        
  94.         // Detect if message is private
  95.         if ($ex[2] == 'botnick') {
  96.             $ex[2] =
  97.  
  98. substr(strtolower($recipient), 1);
  99.         }
  100.        
  101.         // Hostmask detection
  102.         $hostmask = explode('!', $data);
  103.         $hostmask = explode('@', $hostmask[1]);
  104.        
  105.  
  106. $hostmask = explode(' ', $hostmask[1]);
  107.         $hostmask = $hostmask[0];
  108.        
  109.         // Admin detection
  110.         $adminarray = explode(substr($userinfo[0], 1), $adminfile);
  111.        
  112.  
  113. $hostsarray = explode($hostmask, $hostmasks);
  114.         if (isset($adminarray[1]) && isset($hostsarray[1])) {
  115.             $admin = 1;
  116.         }else{
  117.             $admin = 0;
  118.        
  119.  
  120. }
  121.        
  122.         /*if (isset($this->$user) && $userinfo[0] == ':NickServ') {
  123.             $adminstatus = explode('STATUS '.$this->$user.' ', $data);
  124.             $adminstatus = $adminstatus[1];
  125.    
  126.  
  127.         $adminstatus = $adminstatus[0];
  128.             if ($adminstatus == '3') {
  129.                 $admin = 1;
  130.                 $this->$user = NULL;
  131.            
  132.  
  133. }else{
  134.                 $admin = 0;
  135.             }
  136.         }*/
  137.        
  138.         // Get the entire command
  139.         $entirecommandraw = explode(' :', $data);
  140.        
  141.  
  142. $entirecommandraw = $entirecommandraw[1];
  143.         $entirecommandraw = substr($entirecommandraw, 0, -2);
  144.        
  145.         // Get the start message for each command
  146.         $startmsg = "PRIVMSG ".
  147.  
  148. $ex[2]." ".$recipient.":";
  149.  
  150.         // If the bot was directed at
  151.         $direct = str_replace(array(chr(10), chr(13)), '', $ex[3]);
  152.         $direct = strtolower($direct);
  153.         if ($direct == ':botnick') {
  154.            
  155.             // Attempt to detect excess flooding
  156.             $current = date('ymdHis');
  157.             if (!(($current - $lastmsg) < 1 && $abuser == $userinfo[0])) {
  158.                
  159.                 // Get the commands
  160.                 include 'cmd.php';
  161.                
  162.             // End of flooding detection
  163.             }
  164.    
  165.  
  166.         $lastmsg = date('ymdHis');
  167.             $abuser = $userinfo[0];
  168.            
  169.         }
  170.  
  171.  
  172. // If DeadBot gets a permission denied error
  173. if ($ex[2] == 'botnick' ($ex[3] == ':Permission' || $ex[3] == ':Access')) {
  174. fputs($socket,"PRIVMSG ".$channel." :I was instructed to run a command that I could not perform; I had insufficient priviledges on the specific channel.\n");
  175.     }      
  176.         // Get the sayings
  177.         include 'sayings.php';
  178.        
  179.         // Admin echo command
  180.         if ($admin == 1) {
  181.             $content = explode('echo ',
  182.  
  183. $data);
  184.             $content = $content[1];
  185.             if ($ex[3] == ':echo') {
  186.                 if ($ex[2] != '#tomtiger11') {
  187.                     fputs($socket, "PRIVMSG
  188.  
  189. #tomtiger11 :".$content."\n");
  190.                 }
  191.             }
  192.         }
  193.        
  194.         // Admin raw command
  195.         if ($admin == 1) {
  196.            
  197.  
  198. $content = explode('raw ', $data);
  199.             $content = $content[1];
  200.             if ($ex[3] == ':raw') {
  201.                 if ($ex[2] != '#tomtiger11') {
  202.                    
  203.  
  204. fputs($socket, $content."\n");
  205.                 }
  206.             }
  207.         }
  208.        
  209.         // If BotNick is kicked
  210.         $kick = explode('KICK', $data);
  211.    
  212.  
  213.     if (isset($kick[1])) {
  214.             $kickedby = explode('!', $data);
  215.             fputs($socket,"JOIN #tomtiger11\n");
  216.         }
  217.        
  218.     }
  219.  
  220. }
  221. ?>
Add Comment
Please, Sign In to add comment