Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.49 KB | None | 0 0
  1. <?php
  2. /*
  3. demonbot - a demonstation for codedemons.net
  4. */
  5.  
  6. // Include files
  7. include "mysql.php";
  8. include "functions.php";
  9. /* Variables that determine server, channel, etc */
  10. $CONFIG = array();
  11. $CONFIG['server'] = 'chat.freenode.net'; // server (i.e. irc.gamesnet.net)
  12. $CONFIG['nick'] = 'CyndreBot_'; // nick (i.e. demonbot
  13. $CONFIG['port'] = 6667; // port (standard: 6667)
  14. $CONFIG['channel'] = '#cyndrebot'; // channel  (i.e. #php) //mortomes for bot channel
  15. //$CONFIG['channel'] = '##philosophy'; // channel  (i.e. #php) //mortomes for bot channel
  16. $CONFIG['name'] = 'CyndreBot_'; // bot name (i.e. demonbot)
  17. $CONFIG['admin_pass'] = '****'; // admin pass (to change settings remotely)
  18.  
  19. /* Let it run forever (no timeouts) */
  20. set_time_limit(0);
  21.  
  22. /* The connection */
  23. $ignore = array("Transient");
  24. $con = array();
  25. $buffer = array();
  26. $wordarray = array();
  27. $userTrack = array("Usernamedfhfdhsdfhfdh" => array("score" => 0, "seen" => 0, "index" => 0)); //$userTrack("Username" => array("score" => 0, "seen" => 0, "index" => 0))
  28. $wordTrack = array("worddfhgdhfdfhd" => array("seen" => 0, "index" => 0)); //$wordTrack("word" => array("seen" => 0, "index" => 0))
  29. print_r($wordTrack);
  30. $update = array("parse_buffer", "watch");
  31. /* start the bot... */
  32. init();
  33.  
  34. function init()
  35. {
  36.     global $con, $buffer, $CONFIG, $update, $wordarray, $test, $ignore, $userTrack, $wordTrack;
  37.     /* We need this to see if we need to JOIN (the channel) during
  38.     the first iteration of the main loop */
  39.     $firstTime = true;
  40.    
  41.     /* Connect to the irc server */
  42.     $con['socket'] = fsockopen($CONFIG['server'], $CONFIG['port']);
  43.    
  44.     /* Check that we have connected */
  45.     if (!$con['socket']) {
  46.         print ("Could not connect to: ". $CONFIG['server'] ." on port ". $CONFIG['port']);
  47.     } else {
  48.         /* Send the username and nick */
  49.         cmd_send("NS GHOST " .$CONFIG['nick'] . " " . $CONFIG['admin_pass']);
  50.         cmd_send("USER ". $CONFIG['nick'] ." codedemons.net codedemons.net :". $CONFIG['name']);
  51.         cmd_send("NICK ". $CONFIG['nick'] ." codedemons.net");
  52.         cmd_send("NS IDENTIFY " .$CONFIG['admin_pass']);
  53.         /* Here is the loop. Read the incoming data (from the socket connection) */
  54.         while (!feof($con['socket']))
  55.         {
  56.             /* Think of $con['buffer']['all'] as a line of chat messages.
  57.             We are getting a 'line' and getting rid of whitespace around it. */
  58.             $con['buffer']['all'] = trim(fgets($con['socket'], 4096));
  59.             if ($firstTime == true){
  60.                     cmd_send("NS IDENTIFY " .$CONFIG['admin_pass']);
  61.                     cmd_send("JOIN ". $CONFIG['channel']);
  62.                     /* The next time we get here, it will NOT be the firstTime */
  63.                     $firstTime = false;
  64.                 }
  65.             /* Pring the line/buffer to the console
  66.             I used <- to identify incoming data, -> for outgoing. This is so that
  67.             you can identify messages that appear in the console. */
  68.             print date("[d/m @ H:i]")."<- ".$con['buffer']['all'] ."\n";
  69.            
  70.             /* If the server is PINGing, then PONG. This is to tell the server that
  71.             we are still here, and have not lost the connection */
  72.             if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
  73.                 /* PONG : is followed by the line that the server
  74.                 sent us when PINGing */
  75.                 cmd_send('PONG :'.substr($con['buffer']['all'], 6));
  76.                 /* If this is the first time we have reached this point,
  77.                 then JOIN the channel */
  78.                 /* Make sure that we have a NEW line of chats to analyse. If we don't,
  79.                 there is no need to parse the data again */
  80.             } elseif ($old_buffer != $con['buffer']['all']) {
  81.  
  82.                 /* Determine the patterns to be passed
  83.                 to parse_buffer(). buffer is in the form:
  84.                 :username!~identd@hostname JOIN :#php
  85.                 :username!~identd@hostname PRIVMSG #PHP :action text
  86.                 :username!~identd@hostname command channel :text */
  87.                 foreach ($update as $run)
  88. {
  89. $run();
  90. }
  91.                 /*
  92.                 Right now this bot does nothing. But this is where you would
  93.                 add some conditions, or see what is being said in the chat, and then
  94.                 respond. Before you try doing that you should become familiar with
  95.                 how commands are send over IRC. Just read the console when you run this
  96.                 script, and then you will see the patterns in chats, i.e. where the username
  97.                 occurs, where the hostmask is, etc. All you need is functions such as
  98.                 preg_replace_callback(), or perhaps your own function that checks for patterns
  99.                 in the text.
  100.                
  101.                 Good Luck.
  102.                 */
  103.                
  104.             }
  105.             $old_buffer = $con['buffer']['all'];
  106.         }
  107.     }
  108. }
  109.  
  110. /* Accepts the command as an argument, sends the command
  111. to the server, and then displays the command in the console
  112. for debugging */
  113.  
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement