73 |
73 |
74 require('libirc.php'); |
74 require('libirc.php'); |
75 require('hooks.php'); |
75 require('hooks.php'); |
76 require('config.php'); |
76 require('config.php'); |
77 require('database.php'); |
77 require('database.php'); |
|
78 require('permissions.php'); |
|
79 |
|
80 if ( !isset($permissions) ) |
|
81 { |
|
82 foreach ( $privileged_list as $user ) |
|
83 { |
|
84 $permissions[$user] = array('admin'); |
|
85 } |
|
86 if ( isset($alert_list) ) |
|
87 { |
|
88 foreach ( $alert_list as $user ) |
|
89 { |
|
90 $permissions[$user] = array('admin', 'alert'); |
|
91 } |
|
92 } |
|
93 } |
78 |
94 |
79 $enanobot_version = '0.5-unstable'; |
95 $enanobot_version = '0.5-unstable'; |
80 |
96 |
81 @ini_set('display_errors', 'on'); |
97 @ini_set('display_errors', 'on'); |
82 error_reporting(E_ALL); |
98 error_reporting(E_ALL); |
139 |
155 |
140 function enanobot_process_channel_message($sockdata, $chan, $message) |
156 function enanobot_process_channel_message($sockdata, $chan, $message) |
141 { |
157 { |
142 global $irc, $nick, $mysql_conn, $privileged_list; |
158 global $irc, $nick, $mysql_conn, $privileged_list; |
143 |
159 |
144 if ( strpos($message['message'], $nick) && !in_array($message['nick'], $privileged_list) && $message['nick'] != $nick ) |
160 if ( strpos($message['message'], $nick) && !check_permissions($message['nick'], array('context' => 'channel', 'channel' => $chan->get_channel_name())) && $message['nick'] != $nick ) |
145 { |
161 { |
146 $target_nick =& $message['nick']; |
162 $target_nick =& $message['nick']; |
147 // $chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); |
163 // $chan->msg("{$target_nick}, I'm only a bot. :-) You should probably rely on the advice of humans if you need further assistance.", true); |
148 } |
164 } |
149 else |
165 else |
154 |
170 |
155 function enanobot_privmsg_event($message) |
171 function enanobot_privmsg_event($message) |
156 { |
172 { |
157 global $privileged_list, $irc, $nick; |
173 global $privileged_list, $irc, $nick; |
158 static $part_cache = array(); |
174 static $part_cache = array(); |
159 if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' ) |
175 if ( $message['message'] == 'Suspend' && $message['action'] == 'PRIVMSG' && check_permissions($message['nick'], array('context' => 'suspend'), false) ) |
160 { |
176 { |
161 foreach ( $irc->channels as $channel ) |
177 foreach ( $irc->channels as $channel ) |
162 { |
178 { |
163 $part_cache[] = array($channel->get_channel_name(), $channel->get_handler()); |
179 $part_cache[] = array($channel->get_channel_name(), $channel->get_handler()); |
164 $channel->msg("I've received a request from {$message['nick']} to stop responding to requests, messages, and activities. Don't forget to unsuspend me with /msg $nick Resume when finished.", true); |
180 $channel->part("suspended by {$message['nick']}", true); |
165 $channel->part("Logging and presence suspended by {$message['nick']}", true); |
181 } |
166 } |
182 } |
167 } |
183 else if ( $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' && check_permissions($message['nick'], array('context' => 'suspend'), false) ) |
168 else if ( in_array($message['nick'], $privileged_list) && $message['message'] == 'Resume' && $message['action'] == 'PRIVMSG' ) |
|
169 { |
184 { |
170 global $nick; |
185 global $nick; |
171 foreach ( $part_cache as $chan_data ) |
186 foreach ( $part_cache as $chan_data ) |
172 { |
187 { |
173 $chan_name = substr($chan_data[0], 1); |
188 $chan_name = substr($chan_data[0], 1); |
174 $GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]); |
189 $GLOBALS[$chan_name] = $irc->join($chan_data[0], $chan_data[1]); |
175 $GLOBALS[$chan_name]->msg("Bot resumed by {$message['nick']}.", true); |
190 $GLOBALS[$chan_name]->msg("(resumed by {$message['nick']})", true); |
176 $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick"); |
191 $irc->privmsg('ChanServ', "OP {$chan_data[0]} $nick"); |
177 } |
192 } |
178 $part_cache = array(); |
193 $part_cache = array(); |
179 } |
194 } |
180 else if ( in_array($message['nick'], $privileged_list) && preg_match('/^Shutdown(?: (.+))?$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' ) |
195 else if ( preg_match('/^Shutdown(?: (.+))?$/i', $message['message'], $match) && $message['action'] == 'PRIVMSG' && check_permissions($message['nick'], array('context' => 'shutdown'), false) ) |
181 { |
196 { |
182 $GLOBALS['_shutdown'] = true; |
197 $GLOBALS['_shutdown'] = true; |
183 $quitmessage = empty($match[1]) ? "Remote bot shutdown requested by {$message['nick']}" : $match[1]; |
198 $quitmessage = empty($match[1]) ? "Remote bot shutdown requested by {$message['nick']}" : $match[1]; |
184 $irc->close($quitmessage, true); |
199 $irc->close($quitmessage, true); |
185 return 'BREAK'; |
200 return 'BREAK'; |
186 } |
201 } |
187 else if ( in_array($message['nick'], $privileged_list) && preg_match('/^re(?:hash|load)?(?:config)?(?: |$)/', $message['message']) ) |
202 else if ( preg_match('/^re(?:hash|load)?(?:config)?(?: |$)/', $message['message']) && check_permissions($message['nick'], array('context' => 'rehash'), false) ) |
188 { |
203 { |
|
204 $oldnick = $GLOBALS['nick']; |
189 require('config.php'); |
205 require('config.php'); |
190 $GLOBALS['privileged_list'] = $privileged_list; |
206 $GLOBALS['privileged_list'] = $privileged_list; |
191 $GLOBALS['alert_list'] = $alert_list; |
207 $GLOBALS['alert_list'] = $alert_list; |
192 $GLOBALS['channels'] = $channels; |
208 $GLOBALS['channels'] = $channels; |
|
209 $GLOBALS['permissions'] = $permissions; |
|
210 if ( $nick != $oldnick ) |
|
211 { |
|
212 $irc->change_nick($nick, $pass); |
|
213 $GLOBALS['nick'] = $nick; |
|
214 $GLOBALS['pass'] = $pass; |
|
215 } |
193 $in = array(); |
216 $in = array(); |
194 foreach ( $irc->channels as $channel ) |
217 foreach ( $irc->channels as $channel ) |
195 { |
218 { |
196 $channame = $channel->get_channel_name(); |
219 $channame = $channel->get_channel_name(); |
197 if ( !in_array($channame, $channels) ) |
220 if ( !in_array($channame, $channels) ) |