author | Dan |
Fri, 09 May 2008 22:19:32 -0400 | |
changeset 6 | a802bb5b3e08 |
parent 4 | 8f62a406d9d9 |
child 7 | 1d6e762433fe |
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 |
||
8 |
// define('LIBIRC_DEBUG', ''); |
|
9 |
||
0 | 10 |
require('libirc.php'); |
11 |
require('config.php'); |
|
12 |
||
13 |
@ini_set('display_errors', 'on'); |
|
14 |
||
15 |
$mysql_conn = false; |
|
16 |
||
17 |
function mysql_reconnect() |
|
18 |
{ |
|
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
|
19 |
global $mysql_conn, $mysql_host, $mysql_user, $mysql_pass, $mysql_dbname; |
0 | 20 |
if ( $mysql_conn ) |
4
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
21 |
{ |
0 | 22 |
@mysql_close($mysql_conn); |
4
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
23 |
if ( defined('LIBIRC_DEBUG') ) |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
24 |
{ |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
25 |
echo "< > Reconnecting to MySQL\n"; |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
26 |
} |
8f62a406d9d9
Added debug message for MySQL reconnection; it's tested and confirmed working now
Dan
parents:
3
diff
changeset
|
27 |
} |
0 | 28 |
// connect to MySQL |
29 |
$mysql_conn = @mysql_connect($mysql_host, $mysql_user, $mysql_pass); |
|
30 |
if ( !$mysql_conn ) |
|
31 |
{ |
|
32 |
$m_e = mysql_error(); |
|
33 |
echo "Error connecting to MySQL: $m_e\n"; |
|
34 |
exit(1); |
|
35 |
} |
|
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
|
36 |
$q = @mysql_query("USE `$mysql_dbname`;", $mysql_conn); |
0 | 37 |
if ( !$q ) |
38 |
{ |
|
39 |
$m_e = mysql_error(); |
|
40 |
echo "Error selecting database: $m_e\n"; |
|
41 |
exit(1); |
|
42 |
} |
|
43 |
} |
|
44 |
||
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
|
45 |
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
|
46 |
{ |
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
|
47 |
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
|
48 |
$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
|
49 |
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
|
50 |
{ |
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
|
51 |
$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
|
52 |
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
|
53 |
{ |
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
|
54 |
$m_e = mysql_error(); |
3 | 55 |
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
|
56 |
{ |
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
|
57 |
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
|
58 |
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
|
59 |
} |
3 | 60 |
$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
|
61 |
$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
|
62 |
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
|
63 |
} |
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
|
64 |
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
|
65 |
} |
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
|
66 |
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
|
67 |
} |
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
|
68 |
|
0 | 69 |
mysql_reconnect(); |
70 |
||
6 | 71 |
$libirc_channels = array(); |
72 |
||
0 | 73 |
$irc = new Request_IRC('irc.freenode.net'); |
74 |
$irc->connect($nick, $user, $name, $pass); |
|
75 |
$irc->set_privmsg_handler('enanobot_privmsg_event'); |
|
6 | 76 |
|
77 |
foreach ( $channels as $channel ) |
|
78 |
{ |
|
79 |
$libirc_channels[$channel] = $irc->join($channel, 'enanobot_channel_event'); |
|
80 |
$channel_clean = preg_replace('/^[#&]/', '', $channel); |
|
81 |
$libirc_channels[$channel_clean] =& $libirc_channels[$channel]; |
|
82 |
$irc->privmsg('ChanServ', "OP $channel $nick"); |
|
83 |
} |
|
0 | 84 |
|
85 |
$irc->event_loop(); |
|
86 |
$irc->close(); |
|
87 |
mysql_close($mysql_conn); |
|
88 |
||
6 | 89 |
function enanobot_channel_event($sockdata, $chan) |
0 | 90 |
{ |
91 |
global $irc, $nick, $mysql_conn, $privileged_list; |
|
92 |
$sockdata = trim($sockdata); |
|
93 |
$message = Request_IRC::parse_message($sockdata); |
|
6 | 94 |
$channelname = $chan->get_channel_name(); |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
95 |
enanobot_log_message($chan, $message); |
0 | 96 |
switch ( $message['action'] ) |
97 |
{ |
|
98 |
case 'JOIN': |
|
99 |
// if a known op joins the channel, send mode +o |
|
100 |
if ( in_array($message['nick'], $privileged_list) ) |
|
101 |
{ |
|
6 | 102 |
$chan->parent->put("MODE $channelname +o {$message['nick']}\r\n"); |
0 | 103 |
} |
104 |
break; |
|
105 |
case 'PRIVMSG': |
|
106 |
enanobot_process_channel_message($sockdata, $chan, $message); |
|
107 |
break; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
function enanobot_process_channel_message($sockdata, $chan, $message) |
|
112 |
{ |
|
113 |
global $irc, $nick, $mysql_conn, $privileged_list; |
|
114 |
||
115 |
if ( preg_match('/^\!echo /', $message['message']) && in_array($message['nick'], $privileged_list) ) |
|
116 |
{ |
|
117 |
$chan->msg(preg_replace('/^\!echo /', '', $message['message']), true); |
|
118 |
} |
|
119 |
else if ( preg_match('/^\![\s]*([a-z0-9_-]+)([\s]*\|[\s]*([^ ]+))?$/', $message['message'], $match) ) |
|
120 |
{ |
|
121 |
$snippet =& $match[1]; |
|
122 |
if ( @$match[3] === 'me' ) |
|
123 |
$match[3] = $message['nick']; |
|
124 |
$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
|
125 |
if ( $snippet == 'snippets' ) |
0 | 126 |
{ |
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
|
127 |
// 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
|
128 |
$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
|
129 |
$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
|
130 |
if ( mysql_num_rows($q) < 1 ) |
0 | 131 |
{ |
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
|
132 |
$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
|
133 |
} |
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
|
134 |
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
|
135 |
{ |
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
|
136 |
$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
|
137 |
while ( $row = mysql_fetch_assoc($q) ) |
0 | 138 |
{ |
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
|
139 |
$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
|
140 |
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
|
141 |
{ |
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
|
142 |
$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
|
143 |
} |
0 | 144 |
} |
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
|
145 |
$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
|
146 |
$chan->msg("{$message['nick']}, the following snippets are available: $snippets", true); |
0 | 147 |
} |
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
|
148 |
@mysql_free_result($q); |
0 | 149 |
} |
150 |
else |
|
151 |
{ |
|
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
|
152 |
// 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
|
153 |
$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
|
154 |
if ( mysql_num_rows($q) < 1 ) |
0 | 155 |
{ |
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
|
156 |
$chan->msg("{$message['nick']}, I couldn't find that snippet (\"$snippet\") in the database.", true); |
0 | 157 |
} |
158 |
else |
|
159 |
{ |
|
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
|
160 |
$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
|
161 |
$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
|
162 |
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
|
163 |
{ |
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
|
164 |
$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
|
165 |
} |
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
|
166 |
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
|
167 |
{ |
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
|
168 |
$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
|
169 |
} |
0 | 170 |
} |
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 |
@mysql_free_result($q); |
0 | 172 |
} |
173 |
} |
|
174 |
else if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick ) |
|
175 |
{ |
|
176 |
$target_nick =& $message['nick']; |
|
177 |
$chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); |
|
178 |
} |
|
179 |
} |
|
180 |
||
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
181 |
function enanobot_log_message($chan, $message) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
182 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
183 |
global $nick; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
184 |
|
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
185 |
// Log the message |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
186 |
$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
|
187 |
$nick_db = mysql_real_escape_string($message['nick']); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
188 |
$line_db = mysql_real_escape_string($message['message']); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
189 |
$day = date('Y-m-d'); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
190 |
$time = time(); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
191 |
$m_et = false; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
192 |
$sql = false; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
193 |
switch($message['action']) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
194 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
195 |
case 'PRIVMSG': |
3 | 196 |
if ( substr($line_db, 0, 5) != '[off]' ) |
197 |
{ |
|
198 |
$sql = "INSERT INTO irclog(channel, day, nick, timestamp, line) VALUES |
|
199 |
( '$chan_db', '$day', '$nick_db', '$time', '$line_db' );"; |
|
200 |
} |
|
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
201 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
202 |
case 'JOIN': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
203 |
$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
|
204 |
( '$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
|
205 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
206 |
case 'PART': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
207 |
$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
|
208 |
( '$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
|
209 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
210 |
case 'MODE': |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
211 |
list($mode, $target_nick) = explode(' ', $line_db); |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
212 |
if ( $message['nick'] != 'ChanServ' && $target_nick != $nick ) |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
213 |
{ |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
214 |
$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
|
215 |
( '$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
|
216 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
217 |
break; |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
218 |
} |
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
|
219 |
if ( $sql ) |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
220 |
{ |
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
|
221 |
eb_mysql_query($sql); |
1
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
222 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
223 |
} |
739423b66116
Added support for logging mode messages and join/part messages
Dan
parents:
0
diff
changeset
|
224 |
|
0 | 225 |
function enanobot_privmsg_event($message) |
226 |
{ |
|
6 | 227 |
global $privileged_list, $irc, $nick; |
0 | 228 |
static $part_cache = array(); |
229 |
if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' ) |
|
230 |
{ |
|
231 |
foreach ( $irc->channels as $channel ) |
|
232 |
{ |
|
233 |
$part_cache[] = array($channel->get_channel_name(), $channel->get_handler()); |
|
6 | 234 |
$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 | 235 |
$channel->part("Logging and presence suspended by {$message['nick']}", true); |
236 |
} |
|
237 |
} |
|
238 |
else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' ) |
|
239 |
{ |
|
240 |
global $nick; |
|
241 |
foreach ( $part_cache as $chan_data ) |
|
242 |
{ |
|
243 |
$chan_name = substr($chan_data[0], 1); |
|
244 |
$GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]); |
|
245 |
$GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true); |
|
246 |
$irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick"); |
|
247 |
} |
|
248 |
$part_cache = array(); |
|
249 |
} |
|
250 |
else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Shutdown' && $message['action'] == 'PRIVMSG' ) |
|
251 |
{ |
|
252 |
$irc->close("Remote bot shutdown ordered by {$message['nick']}", true); |
|
253 |
return 'BREAK'; |
|
254 |
} |
|
6 | 255 |
else if ( in_array($message['nick'], $privileged_list) && preg_match("/^\!echo-([^\007, \r\n\a\t]+) /", $message['message'], $match) ) |
0 | 256 |
{ |
6 | 257 |
global $libirc_channels; |
258 |
$channel_name =& $match[1]; |
|
259 |
if ( isset($libirc_channels[$channel_name]) && is_object($libirc_channels[$channel_name]) ) |
|
260 |
{ |
|
261 |
$libirc_channels[$channel_name]->msg(preg_replace("/^\!echo-([^\007, \r\n\a\t]+) /", '', $message['message']), true); |
|
262 |
} |
|
0 | 263 |
} |
264 |
} |
|
265 |