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