author | Dan |
Fri, 09 May 2008 22:37:57 -0400 | |
changeset 7 | 1d6e762433fe |
parent 6 | a802bb5b3e08 |
child 8 | 0acb8d9a3194 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
6 | 2 |
|
3 |
/** |
|
4 |
* EnanoBot - the Enano CMS IRC logging and help automation bot |
|
5 |
* GPL and no warranty, see the LICENSE file for more info |
|
6 |
*/ |
|
7 |
||
7 | 8 |
// parse command line |
9 |
if ( isset($argv[1]) ) |
|
10 |
{ |
|
11 |
$arg =& $argv[1]; |
|
12 |
if ( $arg == '--daemon' || $arg == '-d' ) |
|
13 |
{ |
|
14 |
// attempt to fork... |
|
15 |
if ( function_exists('pcntl_fork') ) |
|
16 |
{ |
|
17 |
$pid = pcntl_fork(); |
|
18 |
if ( $pid == -1 ) |
|
19 |
{ |
|
20 |
echo "Forking process failed.\n"; |
|
21 |
exit(1); |
|
22 |
} |
|
23 |
else if ( $pid ) |
|
24 |
{ |
|
25 |
echo "EnanoBot daemon started, pid $pid\n"; |
|
26 |
exit(0); |
|
27 |
} |
|
28 |
else |
|
29 |
{ |
|
30 |
// do nothing, just continue. |
|
31 |
} |
|
32 |
} |
|
33 |
else |
|
34 |
{ |
|
35 |
echo "No pcntl support in PHP, continuing in foreground\n"; |
|
36 |
} |
|
37 |
} |
|
38 |
else if ( $arg == '-v' || $arg == '--verbose' ) |
|
39 |
{ |
|
40 |
define('LIBIRC_DEBUG', ''); |
|
41 |
} |
|
42 |
else |
|
43 |
{ |
|
44 |
echo <<<EOF |
|
45 |
Usage: {$argv[0]} |
|
46 |
Options: |
|
47 |
-d, --daemon Run in background (requires pcntl support) |
|
48 |
-v, --verbose Log communication to stdout (ignored if -d specified) |
|
49 |
-h, --help This help message |
|
50 |
||
51 |
EOF; |
|
52 |
exit(1); |
|
53 |
} |
|
54 |
} |
|
6 | 55 |
|
0 | 56 |
require('libirc.php'); |
57 |
require('config.php'); |
|
58 |
||
59 |
@ini_set('display_errors', 'on'); |
|
60 |
||
61 |
$mysql_conn = false; |
|
62 |
||
63 |
function mysql_reconnect() |
|
64 |
{ |
|
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
65 |
global $mysql_conn, $mysql_host, $mysql_user, $mysql_pass, $mysql_dbname; |
0 | 66 |
if ( $mysql_conn ) |
4
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
67 |
{ |
0 | 68 |
@mysql_close($mysql_conn); |
4
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
69 |
if ( defined('LIBIRC_DEBUG') ) |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
70 |
{ |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
71 |
echo "< > Reconnecting to MySQL\n"; |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
72 |
} |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
73 |
} |
0 | 74 |
// connect to MySQL |
75 |
$mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass); |
|
76 |
if ( !$mysql_conn ) |
|
77 |
{ |
|
78 |
$m_e = mysql_error(); |
|
79 |
echo "Error connecting to MySQL: $m_e\n"; |
|
80 |
exit(1); |
|
81 |
} |
|
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
82 |
$q = @mysql_query("USE `$mysql_dbname`;", $mysql_conn); |
0 | 83 |
if ( !$q ) |
84 |
{ |
|
85 |
$m_e = mysql_error(); |
|
86 |
echo "Error selecting database: $m_e\n"; |
|
87 |
exit(1); |
|
88 |
} |
|
89 |
} |
|
90 |
||
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
91 |
function eb_mysql_query($sql, $conn = false) |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
92 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
93 |
global $mysql_conn, $irc; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
94 |
$m_et = false; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
95 |
while ( true ) |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
96 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
97 |
$q = mysql_query($sql, $mysql_conn); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
98 |
if ( !$q ) |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
99 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
100 |
$m_e = mysql_error(); |
3 | 101 |
if ( strpos($m_e, 'gone away') && !$m_et ) |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
102 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
103 |
mysql_reconnect(); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
104 |
continue; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
105 |
} |
3 | 106 |
$m_et = true; |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
107 |
$irc->close("MySQL query error: $m_e"); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
108 |
exit(1); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
109 |
} |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
110 |
break; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
111 |
} |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
112 |
return $q; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
113 |
} |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
114 |
|
0 | 115 |
mysql_reconnect(); |
116 |
||
6 | 117 |
$libirc_channels = array(); |
118 |
||
0 | 119 |
$irc = new Request_IRC('irc.freenode.net'); |
120 |
$irc->connect($nick, $user, $name, $pass); |
|
121 |
$irc->set_privmsg_handler('enanobot_privmsg_event'); |
|
6 | 122 |
|
123 |
foreach ( $channels as $channel ) |
|
124 |
{ |
|
125 |
$libirc_channels[$channel] = $irc->join($channel, 'enanobot_channel_event'); |
|
126 |
$channel_clean = preg_replace('/^[#&]/', '', $channel); |
|
127 |
$libirc_channels[$channel_clean] =& $libirc_channels[$channel]; |
|
128 |
$irc->privmsg('ChanServ', "OP $channel $nick"); |
|
129 |
} |
|
0 | 130 |
|
131 |
$irc->event_loop(); |
|
132 |
$irc->close(); |
|
133 |
mysql_close($mysql_conn); |
|
134 |
||
6 | 135 |
function enanobot_channel_event($sockdata, $chan) |
0 | 136 |
{ |
137 |
global $irc, $nick, $mysql_conn, $privileged_list; |
|
138 |
$sockdata = trim($sockdata); |
|
139 |
$message = Request_IRC::parse_message($sockdata); |
|
6 | 140 |
$channelname = $chan->get_channel_name(); |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
141 |
enanobot_log_message($chan, $message); |
0 | 142 |
switch ( $message['action'] ) |
143 |
{ |
|
144 |
case 'JOIN': |
|
145 |
// if a known op joins the channel, send mode +o |
|
146 |
if ( in_array($message['nick'], $privileged_list) ) |
|
147 |
{ |
|
6 | 148 |
$chan->parent->put("MODE $channelname +o {$message['nick']}\r\n"); |
0 | 149 |
} |
150 |
break; |
|
151 |
case 'PRIVMSG': |
|
152 |
enanobot_process_channel_message($sockdata, $chan, $message); |
|
153 |
break; |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
function enanobot_process_channel_message($sockdata, $chan, $message) |
|
158 |
{ |
|
159 |
global $irc, $nick, $mysql_conn, $privileged_list; |
|
160 |
||
161 |
if ( preg_match('/^\!echo /', $message['message']) && in_array($message['nick'], $privileged_list) ) |
|
162 |
{ |
|
163 |
$chan->msg(preg_replace('/^\!echo /', '', $message['message']), true); |
|
164 |
} |
|
165 |
else if ( preg_match('/^\![\s]*([a-z0-9_-]+)([\s]*\|[\s]*([^ ]+))?$/', $message['message'], $match) ) |
|
166 |
{ |
|
167 |
$snippet =& $match[1]; |
|
168 |
if ( @$match[3] === 'me' ) |
|
169 |
$match[3] = $message['nick']; |
|
170 |
$target_nick = ( !empty($match[3]) ) ? "{$match[3]}, " : "{$message['nick']}, "; |
|
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
171 |
if ( $snippet == 'snippets' ) |
0 | 172 |
{ |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
173 |
// list available snippets |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
174 |
$m_et = false; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
175 |
$q = eb_mysql_query('SELECT snippet_code, snippet_channels FROM snippets;'); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
176 |
if ( mysql_num_rows($q) < 1 ) |
0 | 177 |
{ |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
178 |
$chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
179 |
} |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
180 |
else |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
181 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
182 |
$snippets = array(); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
183 |
while ( $row = mysql_fetch_assoc($q) ) |
0 | 184 |
{ |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
185 |
$channels = explode('|', $row['snippet_channels']); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
186 |
if ( in_array($chan->get_channel_name(), $channels) ) |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
187 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
188 |
$snippets[] = $row['snippet_code']; |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
189 |
} |
0 | 190 |
} |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
191 |
$snippets = implode(', ', $snippets); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
192 |
$chan->msg("{$message['nick']}, the following snippets are available: $snippets", true); |
0 | 193 |
} |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
194 |
@mysql_free_result($q); |
0 | 195 |
} |
196 |
else |
|
197 |
{ |
|
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
198 |
// Look for the snippet... |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
199 |
$q = eb_mysql_query('SELECT snippet_text, snippet_channels FROM snippets WHERE snippet_code = \'' . mysql_real_escape_string($snippet) . '\';'); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
200 |
if ( mysql_num_rows($q) < 1 ) |
0 | 201 |
{ |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
202 |
$chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); |
0 | 203 |
} |
204 |
else |
|
205 |
{ |
|
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
206 |
$row = mysql_fetch_assoc($q); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
207 |
$channels = explode('|', $row['snippet_channels']); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
208 |
if ( in_array($chan->get_channel_name(), $channels) ) |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
209 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
210 |
$chan->msg("{$target_nick}{$row['snippet_text']}", true); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
211 |
} |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
212 |
else |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
213 |
{ |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
214 |
$chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); |
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
215 |
} |
0 | 216 |
} |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
217 |
@mysql_free_result($q); |
0 | 218 |
} |
219 |
} |
|
220 |
else if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick ) |
|
221 |
{ |
|
222 |
$target_nick =& $message['nick']; |
|
223 |
$chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); |
|
224 |
} |
|
225 |
} |
|
226 |
||
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
227 |
function enanobot_log_message($chan, $message) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
228 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
229 |
global $nick; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
230 |
|
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
231 |
// Log the message |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
232 |
$chan_db = mysql_real_escape_string($chan->get_channel_name()); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
233 |
$nick_db = mysql_real_escape_string($message['nick']); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
234 |
$line_db = mysql_real_escape_string($message['message']); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
235 |
$day = date('Y-m-d'); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
236 |
$time = time(); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
237 |
$m_et = false; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
238 |
$sql = false; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
239 |
switch($message['action']) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
240 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
241 |
case 'PRIVMSG': |
3 | 242 |
if ( substr($line_db, 0, 5) != '[off]' ) |
243 |
{ |
|
244 |
$sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES |
|
245 |
( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );"; |
|
246 |
} |
|
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
247 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
248 |
case 'JOIN': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
249 |
$sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
250 |
( '$chan_db', '$day', '', '$time', '$nick_db has joined $chan_db' );"; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
251 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
252 |
case 'PART': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
253 |
$sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
254 |
( '$chan_db', '$day', '', '$time', '$nick_db has left $chan_db' );"; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
255 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
256 |
case 'MODE': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
257 |
list($mode, $target_nick) = explode(' ', $line_db); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
258 |
if ( $message['nick'] != 'ChanServ' && $target_nick != $nick ) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
259 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
260 |
$sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
261 |
( '$chan_db', '$day', '', '$time', '$nick_db set mode $mode on $target_nick' );"; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
262 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
263 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
264 |
} |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
265 |
if ( $sql ) |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
266 |
{ |
2
c474904ed707
Moved db_name to config.php; added !snippets virtual snippet that lists all snippet codes in database; abstracted database query and error checking code
Dan
parents:
1
diff
changeset
|
267 |
eb_mysql_query($sql); |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
268 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
269 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
270 |
|
0 | 271 |
function enanobot_privmsg_event($message) |
272 |
{ |
|
6 | 273 |
global $privileged_list, $irc, $nick; |
0 | 274 |
static $part_cache = array(); |
275 |
if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' ) |
|
276 |
{ |
|
277 |
foreach ( $irc->channels as $channel ) |
|
278 |
{ |
|
279 |
$part_cache[] = array($channel->get_channel_name(), $channel->get_handler()); |
|
6 | 280 |
$channel->msg("I've received a request to stop logging messages and responding to requests from {$message['nick']}. Don't forget to unsuspend me with /msg $nick Resume when finished.", true); |
0 | 281 |
$channel->part("Logging and presence suspended by {$message['nick']}", true); |
282 |
} |
|
283 |
} |
|
284 |
else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' ) |
|
285 |
{ |
|
286 |
global $nick; |
|
287 |
foreach ( $part_cache as $chan_data ) |
|
288 |
{ |
|
289 |
$chan_name = substr($chan_data[0], 1); |
|
290 |
$GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]); |
|
291 |
$GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true); |
|
292 |
$irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick"); |
|
293 |
} |
|
294 |
$part_cache = array(); |
|
295 |
} |
|
296 |
else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Shutdown' && $message['action'] == 'PRIVMSG' ) |
|
297 |
{ |
|
298 |
$irc->close("Remote bot shutdown ordered by {$message['nick']}", true); |
|
299 |
return 'BREAK'; |
|
300 |
} |
|
6 | 301 |
else if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!echo-([^\007, \r\n\a\t]+) /", $message['message'], $match) ) |
0 | 302 |
{ |
6 | 303 |
global $libirc_channels; |
304 |
$channel_name =& $match[1]; |
|
305 |
if ( isset($libirc_channels[$channel_name]) && is_object($libirc_channels[$channel_name]) ) |
|
306 |
{ |
|
307 |
$libirc_channels[$channel_name]->msg(preg_replace("/^\!echo-([^\007, \r\n\a\t]+) /", '', $message['message']), true); |
|
308 |
} |
|
0 | 309 |
} |
310 |
} |
|
311 |