| 1 | <?php\r |
| 2 | //HARVESTER IRC BOT\r |
| 3 | //by: Harvie 2oo7\r |
| 4 | \r |
| 5 | //Settings:\r |
| 6 | $server = "irc.2600.net";\r |
| 7 | $port = "6667";\r |
| 8 | $channel = "#soom";\r |
| 9 | $nick = "Harvester";\r |
| 10 | $jokefile = "jokes.txt";\r |
| 11 | error_reporting(0);\r |
| 12 | error_reporting(E_ERROR);\r |
| 13 | \r |
| 14 | //Functions:\r |
| 15 | function irc_connect( $fp, $nick, $channel, $joinwait ) {\r |
| 16 | fwrite($fp, "USER USER $nick # # :$nick\n");\r |
| 17 | fwrite($fp, "NICK $nick\n");\r |
| 18 | //sleep($joinwait);\r |
| 19 | fwrite($fp, "JOIN $channel\n");\r |
| 20 | }\r |
| 21 | \r |
| 22 | function irc_say( $fp, $msg, $nick, $rcpto ) {\r |
| 23 | //fwrite($fp, ":$nick!~Harvie@r3ax157.net.upc.cz PRIVMSG $rcpto :$msg\n");\r |
| 24 | fwrite($fp, ": PRIVMSG $rcpto :$msg\n");\r |
| 25 | }\r |
| 26 | \r |
| 27 | //Code:\r |
| 28 | //Init:\r |
| 29 | $jokes = file($jokefile);\r |
| 30 | $spam = "";\r |
| 31 | $rfile = "";\r |
| 32 | $sfp = fsockopen ($server, $port, &$errno, &$errstr, 5);\r |
| 33 | irc_connect( $sfp, $nick, $channel, 0 );\r |
| 34 | \r |
| 35 | $home_channel = $channel;\r |
| 36 | \r |
| 37 | while(!fwrite($sfp, "")) {\r |
| 38 | \r |
| 39 | fwrite($sfp, "JOIN $channel\n");\r |
| 40 | \r |
| 41 | //ReadLine from IRC Server\r |
| 42 | $line = (fgets($sfp));\r |
| 43 | echo($line);\r |
| 44 | \r |
| 45 | //IRC Sever PING/PONG Response\r |
| 46 | $words = (explode(" ", $line));\r |
| 47 | if ($words[0] == "PING") {\r |
| 48 | fwrite($sfp, "PONG ".trim($words[1])."\n");\r |
| 49 | echo("-PONG ".trim($words[1])."\n");\r |
| 50 | }\r |
| 51 | \r |
| 52 | //Prijem pozvanky\r |
| 53 | if ( ( trim($words[1]) == "INVITE" ) && ( substr(trim($words[3]), 0, 2) == ":#" ) ) {\r |
| 54 | $channel = substr(trim($words[3]), 1);\r |
| 55 | fwrite($sfp, "JOIN $channel\n");\r |
| 56 | irc_say( $sfp, "Hello", $nick, $channel );\r |
| 57 | echo("-JOINED $channel\n");\r |
| 58 | }\r |
| 59 | \r |
| 60 | $commands = (explode(":", $line));\r |
| 61 | \r |
| 62 | //Harvester - Posle vizitku\r |
| 63 | if ( trim($commands[2]) == "Harvester") {\r |
| 64 | irc_say( $sfp, ("Ahoj lidi, ja jsem Harvieho bot. Random#: ".rand(0,10)), $nick, $channel );\r |
| 65 | echo("-VISITCARD"."\n");\r |
| 66 | }\r |
| 67 | \r |
| 68 | //hspam:Message - Posle zpravu pri kazde prijate\r |
| 69 | if ( trim($commands[2]) == "hspam") {\r |
| 70 | $spam = trim($commands[3]);\r |
| 71 | echo("-SPAM: ".trim($commands[3])."\n");\r |
| 72 | }\r |
| 73 | \r |
| 74 | if ( $spam != "" ) {\r |
| 75 | irc_say( $sfp, $spam, $nick, $channel );\r |
| 76 | //echo("-SAID: ".trim($commands[3])."\n");\r |
| 77 | }\r |
| 78 | \r |
| 79 | //hplay:file - Prehraje soubor\r |
| 80 | if ( trim($commands[2]) == "hplay") {\r |
| 81 | if ( is_file( trim($commands[3]) ) ) {\r |
| 82 | $rfile = fopen( trim($commands[3]), "r");\r |
| 83 | }\r |
| 84 | else\r |
| 85 | {\r |
| 86 | fclose($rfile);\r |
| 87 | $rfile = "";\r |
| 88 | }\r |
| 89 | echo("-FILE: ".trim($commands[3])."\n");\r |
| 90 | }\r |
| 91 | \r |
| 92 | if ( $rfile != "" ) {\r |
| 93 | irc_say( $sfp, fgetss($rfile), $nick, $channel );\r |
| 94 | }\r |
| 95 | \r |
| 96 | //hhelp - vypise tuto napovedu\r |
| 97 | if ( trim($commands[2]) == "hhelp") {\r |
| 98 | irc_say( $sfp, "Ja jsem Harvester - vice info na: http://ircbot.wz.cz/", $nick, $channel );\r |
| 99 | /*\r |
| 100 | irc_say( $sfp, "Harvester - Posle vizitku", $nick, $channel );\r |
| 101 | irc_say( $sfp, "hhelp - vypise tuto napovedu", $nick, $channel );\r |
| 102 | irc_say( $sfp, "hsay:Message - Posle zpravu", $nick, $channel );\r |
| 103 | irc_say( $sfp, "hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe", $nick, $channel );\r |
| 104 | irc_say( $sfp, "hdo:Command - Posle serveru prikaz", $nick, $channel );\r |
| 105 | irc_say( $sfp, "hmove:Channel - Pripoji do kanalu / Zmeni aktivni kanal", $nick, $channel );\r |
| 106 | irc_say( $sfp, "/invite Harvester #channel - Pozve a pripoji bota do kanalu", $nick, $channel );\r |
| 107 | irc_say( $sfp, "hpart:Channel - Odpoji se z kanalu", $nick, $channel );\r |
| 108 | irc_say( $sfp, "hjoke - Posle \"nahodny\" vtip", $nick, $channel );\r |
| 109 | */\r |
| 110 | echo("-HELPED"."\n");\r |
| 111 | }\r |
| 112 | \r |
| 113 | //hsay:Message - Posle zpravu\r |
| 114 | if ( trim($commands[2]) == "hsay") {\r |
| 115 | irc_say( $sfp, trim($commands[3]), $nick, $channel );\r |
| 116 | echo("-SAID: ".trim($commands[3])."\n");\r |
| 117 | }\r |
| 118 | \r |
| 119 | //hpsay:to:Message - Posle soukromou zpravu kanalu nebo osobe\r |
| 120 | if ( trim($commands[2]) == "hpsay") {\r |
| 121 | irc_say( $sfp, trim($commands[4]), $nick, trim($commands[3]) );\r |
| 122 | echo("-SAID: ".trim($commands[4])." -- To: ".trim($commands[3])."\n");\r |
| 123 | }\r |
| 124 | \r |
| 125 | //hcol:to:Message - Posle kolizni zpravu kanalu nebo osobe\r |
| 126 | if ( trim($commands[2]) == "hcol") {\r |
| 127 | irc_say( $sfp, trim($commands[4]), trim($commands[3]), $channel );\r |
| 128 | echo("-COLIDED: ".trim($commands[4])." To: ".trim($commands[3])."\n");\r |
| 129 | }\r |
| 130 | \r |
| 131 | //hdo:Command - Posle serveru prikaz\r |
| 132 | if ( trim($commands[2]) == "hdo") {\r |
| 133 | $hdo = explode("hdo:", $line);\r |
| 134 | fwrite( $sfp, trim($hdo[1])."\n" );\r |
| 135 | echo("-DONE: ".trim($hdo[1])."\n");\r |
| 136 | }\r |
| 137 | \r |
| 138 | //hpart:Channel - Odpoji se z kanalu\r |
| 139 | if ( trim($commands[2]) == "hpart") {\r |
| 140 | $hdo = explode("hpart:", $line);\r |
| 141 | if ( trim($hdo[1]) != trim($home_channel) ) {\r |
| 142 | fwrite( $sfp, "PART :".trim($hdo[1])."\n" );\r |
| 143 | echo("-PARTED: ".trim($hdo[1])."\n");\r |
| 144 | }\r |
| 145 | }\r |
| 146 | \r |
| 147 | //hmove:Channel - Zmeni aktivni kanal\r |
| 148 | if ( trim($commands[2]) == "hmove") {\r |
| 149 | $hdo = explode("hmove:", $line);\r |
| 150 | if ( trim($hdo[1]) != trim($home_channel) ) {\r |
| 151 | $home_channel = trim($hdo[1]);\r |
| 152 | fwrite($sfp, "JOIN $home_channel\n");\r |
| 153 | irc_say( $sfp, "Hi, im here...", $nick, $home_channel );\r |
| 154 | echo("-ACTIVATED: ".trim($hdo[1])."\n");\r |
| 155 | }\r |
| 156 | }\r |
| 157 | \r |
| 158 | //htime - udaje o casu\r |
| 159 | if ( trim($commands[2]) == "htime") {\r |
| 160 | $msg = implode("-", getdate(time()));\r |
| 161 | irc_say( $sfp, trim($msg), $nick, $channel );\r |
| 162 | echo("-TIMED"."\n");\r |
| 163 | }\r |
| 164 | \r |
| 165 | //hjoke - Posle nahodny vtip\r |
| 166 | if ( trim($commands[2]) == "hjoke") {\r |
| 167 | $joke = ($jokes[ rand(0, (sizeof($jokes)-1) ) ]);\r |
| 168 | //$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";\r |
| 169 | irc_say( $sfp, trim($joke), $nick, $channel );\r |
| 170 | echo("-JOKED"."\n");\r |
| 171 | }\r |
| 172 | \r |
| 173 | //Navrat do domaciho kanalu\r |
| 174 | $channel = $home_channel;\r |
| 175 | \r |
| 176 | }\r |
| 177 | \r |
| 178 | echo("-Connection lost.")\r |
| 179 | \r |
| 180 | ?>\r |