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