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