1+ <?php 
2+ 
3+ 
4+ // Set the timeout limit so the page wont timeout 
5+ set_time_limit (0 );
6+ 
7+ $ channel  = "" ;
8+ 
9+ // IRC Class 
10+ include ("irc_class.php " );
11+ // Config 
12+ include ("config.php " );
13+ 
14+ 	// Create an instance of the IRC class 
15+ 	$ irc  = new  ConnectIrc (IRC_HOST , IRC_PORT );
16+ 
17+ 	// Echo out the server and port 
18+ 	echo  "IRC Server:  {$ irc ->server }<br />Port:  {$ irc ->port }<br /> " ;
19+ 	echo  "<pre> " ;
20+ 
21+ 	// Open socket 
22+ 	if  ( $ irc ->openSocket () ) {
23+ 	
24+ 		// Set password (leaving it blank defines no password) 
25+ 		$ irc ->setPassword ();
26+ 		// Set nick/user 
27+ 		//$username = $_GET['nick']; 
28+ 		if  (isset ($ _GET  ['nick ' ]))
29+ 			$ username  = $ _GET  ['nick ' ];
30+ 		else 
31+ 			$ username  = "LeonBot " ;
32+ 			
33+ 		$ irc ->setNick ($ username );
34+ 		$ irc ->setUser ($ username );
35+ 	
36+ 		// While you are connected to the server 
37+ 		while  ( $ irc ->connected () ) {
38+ 			
39+ 			// Print out the read buffer 
40+ 			$ buffer  = $ irc ->showReadBuffer ();
41+ 			//echo $buffer."\n\r"; 
42+ 			
43+ 			// Here is where you test for certain conditions 
44+ 			$ irc ->returnLastSaid ($ message );
45+ 			$ params  = trim ($ message [PARAMS ]);
46+ 			switch  ($ message [COMMAND ])
47+ 			{
48+ 				// Shutting down 
49+ 				case  "!gtfo " :
50+ 					echo  "Shutting down \n\r" ;
51+ 					$ irc ->closeConnection (); exit ;
52+ 					break ;
53+ 					
54+ 				// Saying hello 
55+ 				case  "!hello " :		
56+ 					echo  "Saying hello to  {$ message [WHERE ]}\n\r" ;
57+  					$ irc ->say ("Hey,  {$ message [SENDER ]}! " , $ message [WHERE ]);
58+ 					break ;
59+ 					
60+ 				// Handles joining rooms 
61+ 				case  "!join " :
62+ 					echo  "Joining  {$ params }\n\r" ;
63+ 					$ channel  = $ params ;
64+ 					$ irc ->joinChannel ($ channel );
65+ 					break ;
66+ 					
67+ 				// handles parting rooms 
68+ 				case  "!part " :
69+ 					echo  "Leaving  {$ params }\n\r" ;
70+ 					$ channel  = $ params ;
71+ 					$ irc ->partChannel ($ channel );
72+ 					break ;
73+ 					
74+ 				// changing nickname 
75+ 				case  "!nick " :
76+ 					echo  "Changing nick to  {$ params }\n\r" ;
77+ 					$ irc ->setNick ($ params );
78+ 					break ;
79+ 					
80+ 				// grabbing someone's twitter status 
81+ 				case  "!twitter " :
82+ 					echo  "Grabbing status for  {$ params }\n\r" ;
83+ 					$ ch  = curl_init ();
84+ 					curl_setopt ($ ch , CURLOPT_URL , "http://api.twitter.com/1/statuses/user_timeline/ {$ params }.json " );
85+ 					curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
86+ 					$ json  = curl_exec ($ ch );
87+ 					curl_close ($ ch );
88+ 					$ jsonObject  = json_decode ($ json );
89+ 					$ status  = $ jsonObject [0 ]->text ;
90+ 					echo  "Got latest Tweet from  {$ params }\n\t->  {$ status }" ;
91+ 					$ irc ->say ("{$ status }" , $ message [WHERE ]);
92+ 					break ;
93+ 				// for anything else ... 
94+ 				default :
95+ 					if  (strtolower ($ message [COMMAND ]) == strtolower ($ irc ->nick ) || 
96+ 						strstr (strtolower ($ params ), strtolower ($ irc ->nick )))
97+ 						$ irc ->say ("What the fuck do you want,  {$ message [SENDER ]}? " , $ message [WHERE ]);
98+ 					break ;
99+ 			}
100+ 								
101+ 			// Handle the ping pong 
102+ 			$ irc ->handlePingPong ();			
103+ 		
104+ 			// Flush the buffer 
105+ 			$ irc ->flushIrc ();
106+ 		}
107+ 	
108+ 		// Close the connection 
109+ 		if  ( $ irc ->closeConnection () ) {
110+ 			echo  "<br />Connection closed...  " ;
111+ 		} else  {
112+ 			echo  "<br />Connection had a problem closing... wait wtf? " ;
113+ 		}
114+ 	}
115+ 
116+ ?> 
0 commit comments