Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- demonbot - a demonstation for codedemons.net
- */
- // Include files
- include "mysql.php";
- include "functions.php";
- /* Variables that determine server, channel, etc */
- $CONFIG = array();
- $CONFIG['server'] = 'chat.freenode.net'; // server (i.e. irc.gamesnet.net)
- $CONFIG['nick'] = 'CyndreBot_'; // nick (i.e. demonbot
- $CONFIG['port'] = 6667; // port (standard: 6667)
- $CONFIG['channel'] = '#cyndrebot'; // channel (i.e. #php) //mortomes for bot channel
- //$CONFIG['channel'] = '##philosophy'; // channel (i.e. #php) //mortomes for bot channel
- $CONFIG['name'] = 'CyndreBot_'; // bot name (i.e. demonbot)
- $CONFIG['admin_pass'] = '****'; // admin pass (to change settings remotely)
- /* Let it run forever (no timeouts) */
- set_time_limit(0);
- /* The connection */
- $ignore = array("Transient");
- $con = array();
- $buffer = array();
- $wordarray = array();
- $userTrack = array("Usernamedfhfdhsdfhfdh" => array("score" => 0, "seen" => 0, "index" => 0)); //$userTrack("Username" => array("score" => 0, "seen" => 0, "index" => 0))
- $wordTrack = array("worddfhgdhfdfhd" => array("seen" => 0, "index" => 0)); //$wordTrack("word" => array("seen" => 0, "index" => 0))
- print_r($wordTrack);
- $update = array("parse_buffer", "watch");
- /* start the bot... */
- init();
- function init()
- {
- global $con, $buffer, $CONFIG, $update, $wordarray, $test, $ignore, $userTrack, $wordTrack;
- /* We need this to see if we need to JOIN (the channel) during
- the first iteration of the main loop */
- $firstTime = true;
- /* Connect to the irc server */
- $con['socket'] = fsockopen($CONFIG['server'], $CONFIG['port']);
- /* Check that we have connected */
- if (!$con['socket']) {
- print ("Could not connect to: ". $CONFIG['server'] ." on port ". $CONFIG['port']);
- } else {
- /* Send the username and nick */
- cmd_send("NS GHOST " .$CONFIG['nick'] . " " . $CONFIG['admin_pass']);
- cmd_send("USER ". $CONFIG['nick'] ." codedemons.net codedemons.net :". $CONFIG['name']);
- cmd_send("NICK ". $CONFIG['nick'] ." codedemons.net");
- cmd_send("NS IDENTIFY " .$CONFIG['admin_pass']);
- /* Here is the loop. Read the incoming data (from the socket connection) */
- while (!feof($con['socket']))
- {
- /* Think of $con['buffer']['all'] as a line of chat messages.
- We are getting a 'line' and getting rid of whitespace around it. */
- $con['buffer']['all'] = trim(fgets($con['socket'], 4096));
- if ($firstTime == true){
- cmd_send("NS IDENTIFY " .$CONFIG['admin_pass']);
- cmd_send("JOIN ". $CONFIG['channel']);
- /* The next time we get here, it will NOT be the firstTime */
- $firstTime = false;
- }
- /* Pring the line/buffer to the console
- I used <- to identify incoming data, -> for outgoing. This is so that
- you can identify messages that appear in the console. */
- print date("[d/m @ H:i]")."<- ".$con['buffer']['all'] ."\n";
- /* If the server is PINGing, then PONG. This is to tell the server that
- we are still here, and have not lost the connection */
- if(substr($con['buffer']['all'], 0, 6) == 'PING :') {
- /* PONG : is followed by the line that the server
- sent us when PINGing */
- cmd_send('PONG :'.substr($con['buffer']['all'], 6));
- /* If this is the first time we have reached this point,
- then JOIN the channel */
- /* Make sure that we have a NEW line of chats to analyse. If we don't,
- there is no need to parse the data again */
- } elseif ($old_buffer != $con['buffer']['all']) {
- /* Determine the patterns to be passed
- to parse_buffer(). buffer is in the form:
- :username!~identd@hostname JOIN :#php
- :username!~identd@hostname PRIVMSG #PHP :action text
- :username!~identd@hostname command channel :text */
- foreach ($update as $run)
- {
- $run();
- }
- /*
- Right now this bot does nothing. But this is where you would
- add some conditions, or see what is being said in the chat, and then
- respond. Before you try doing that you should become familiar with
- how commands are send over IRC. Just read the console when you run this
- script, and then you will see the patterns in chats, i.e. where the username
- occurs, where the hostmask is, etc. All you need is functions such as
- preg_replace_callback(), or perhaps your own function that checks for patterns
- in the text.
- Good Luck.
- */
- }
- $old_buffer = $con['buffer']['all'];
- }
- }
- }
- /* Accepts the command as an argument, sends the command
- to the server, and then displays the command in the console
- for debugging */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement