Changeset 94


Ignore:
Timestamp:
Jul 26, 2008, 10:16:52 PM (16 years ago)
Author:
george
Message:

Upraveno: Přepsány ostatní příkazy a celý bot jako třída.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/www/chat/irc_bot.php

    r92 r94  
    1616  function __construct()
    1717  {
    18     $Jokes = file($this->JokeFileName);
     18    $this->Jokes = file($this->JokeFileName);
    1919    $this->File = fsockopen($this->Server, $this->Port, $ErrNumber, $ErrString, 5);
    2020    $this->Connect($this->File, $this->Nick, $this->Channel, 0);
     
    2929  }
    3030
    31   function SayPrivate($Message, $Recepient)
     31  function Say($Message, $Recipient = '')
    3232  {
    33     $this->Command(': PRIVMSG '.$Recepient.' :'.$Message);
    34   }
    35 
    36   function Say($Message)
    37   {
    38     $this->Command(':'.$Message);
     33    if($Recipient == '') $Recipient = $this->Channel;
     34    $this->Command(': PRIVMSG '.$Recipient.' :'.$Message);
    3935  }
    4036
     
    9288        if($Command == 'hhelp')
    9389        {
    94           $this->SayPrivate('Ja jsem Harvester.', $this->Channel);
     90          $this->Say('Ja jsem Harvester.');
    9591          /*
    9692          irc_say( $sfp, "Harvester - Posle vizitku", $nick, $channel );
     
    107103        }
    108104
    109        // hsay:Message - Posle zpravu
    110        if($Command == 'hsay')
    111        {
    112          $this->SayPrivate($Commands[3], $this->Channel);
    113          echo("-SAID: ".$Commands[3]."\n");
    114        }
     105        // hsay:Message - Posle zpravu
     106        if($Command == 'hsay')
     107        {
     108          $this->Say($Commands[3]);
     109          echo("-SAID: ".$Commands[3]."\n");
     110        }
    115111
    116        // hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe
    117        if($Command == 'hpsay')
    118        {
    119          $this->SayPrivate($Commands[4], $Commands[3]);
    120          echo("-SAID: ".$Commands[4]." -- To: ".$Commands[3]."\n");
    121        }
     112        // hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe
     113        if($Command == 'hpsay')
     114        {
     115          $this->Say($Commands[4], $Commands[3]);
     116          echo("-SAID: ".$Commands[4]." -- To: ".$Commands[3]."\n");
     117        }
    122118
    123 /*
    124     // hcol:to:Message - Posle kolizni zpravu kanalu nebo osobe
    125     if($Command == 'hcol')
    126     {
    127       irc_say( $sfp, trim($commands[4]), trim($commands[3]), $channel );
    128       echo("-COLIDED: ".trim($commands[4])." To: ".trim($commands[3])."\n");
    129     }
     119        // hcol:to:Message - Posle kolizni zpravu kanalu nebo osobe
     120        if($Command == 'hcol')
     121        {
     122          $this->Say($Commands[4], $Commands[3]);
     123          echo("-COLIDED: ".$Commands[4]." To: ".$Commands[3]."\n");
     124        }
    130125
    131     // hdo:Command - Posle serveru prikaz
    132     if(trim($commands[2]) == "hdo")
    133     {
    134       $hdo = explode("hdo:", $line);
    135       fwrite( $sfp, trim($hdo[1])."\n" );
    136       echo("-DONE: ".trim($hdo[1])."\n");
    137     }
     126        // hdo:Command - Posle serveru prikaz
     127        if($Command == 'hdo')
     128        {
     129          $hdo = explode('hdo:', $Line);
     130          $this->Command(trim($hdo[1]));
     131          echo("-DONE: ".trim($hdo[1])."\n");
     132        }
    138133
    139     // hpart:Channel - Odpoji se z kanalu
    140     if(trim($commands[2]) == "hpart")
    141     {
    142       $hdo = explode("hpart:", $line);
    143       if(trim($hdo[1]) != trim($home_channel))
    144       {
    145         fwrite( $sfp, "PART :".trim($hdo[1])."\n" );
    146         echo("-PARTED: ".trim($hdo[1])."\n");
     134        // hpart:Channel - Odpoji se z kanalu
     135        if($Command == 'hpart')
     136        {
     137          $hdo = explode('hpart:', $Line);
     138          if(trim($hdo[1]) != trim($this->Channel))
     139          {
     140            $this->Command('PART :'.trim($hdo[1])."\n");
     141            echo("-PARTED: ".trim($hdo[1])."\n");
     142          }
     143        }
     144
     145        // hmove:Channel - Zmeni aktivni kanal
     146        if($Command == 'hmove')
     147        {
     148          $hdo = explode("hmove:", $Line);
     149          if(trim($hdo[1]) != trim($$this->Cannel))
     150          {
     151            $this->Channel = trim($hdo[1]);
     152            $this->Command('JOIN '.$this->Channel."\n");
     153            $this->Say('Hi, im here...');
     154            echo("-ACTIVATED: ".trim($hdo[1])."\n");
     155          }
     156        }
     157
     158        // htime - udaje o casu
     159        if($Command == 'htime')
     160        {
     161          $Date = implode("-", getdate(time()));
     162          $this->Say(trim($Date));
     163          echo("-TIMED"."\n");
     164        }
     165
     166        // hjoke - Posle nahodny vtip
     167        if($Command == 'hjoke')
     168        {
     169          $Joke = ($this->Jokes[rand(0, (sizeof($this->Jokes) - 1))]);
     170          $this->Say(trim($Joke));
     171          echo("-JOKED"."\n");
     172        }
    147173      }
    148     }
    149 
    150     // hmove:Channel - Zmeni aktivni kanal
    151     if(trim($commands[2]) == "hmove")
    152     {
    153       $hdo = explode("hmove:", $line);
    154       if(trim($hdo[1]) != trim($home_channel))
    155       {
    156         $home_channel = trim($hdo[1]);
    157         fwrite($sfp, "JOIN $home_channel\n");
    158         irc_say( $sfp, "Hi, im here...", $nick, $home_channel );
    159         echo("-ACTIVATED: ".trim($hdo[1])."\n");
    160       }
    161     }
    162 
    163     // htime - udaje o casu
    164     if(trim($commands[2]) == "htime")
    165     {
    166       $msg = implode("-", getdate(time()));
    167       irc_say( $sfp, trim($msg), $nick, $channel );
    168       echo("-TIMED"."\n");
    169     }
    170 
    171     // hjoke - Posle nahodny vtip
    172     if(trim($commands[2]) == "hjoke")
    173     {
    174       $joke = ($jokes[ rand(0, (sizeof($jokes)-1) ) ]);
    175       //$ftip = "Potkaji se dve blondyny a jedna rika te druhe: \"How do you do?\" a ta ji odpovi co? kde ses to naucila? To vis vzdycky pretocim radio doprava a tam mluvi jen anglicky tak se to tak ucim. Potkaji se za 2 tydny a jedna rika druhe How do you do a druha ji odpovi chsrchsrsrshchsrshchs";
    176       irc_say( $sfp, trim($joke), $nick, $channel );
    177       echo("-JOKED"."\n");
    178     }
    179 */    }
    180174    }
    181175    echo("-Connection lost.\n");
Note: See TracChangeset for help on using the changeset viewer.