Changeset 24
- Timestamp:
- 02/09/08 13:53:00 (5 years ago)
- Location:
- trunk/Phergie/Event
- Files:
-
- 1 added
- 9 modified
-
Handler.php (modified) (2 diffs)
-
Handler/AdminCommand.php (modified) (2 diffs)
-
Handler/Autojoin.php (modified) (1 diff)
-
Handler/Command.php (added)
-
Handler/Cron.php (modified) (1 diff)
-
Handler/JoinPart.php (modified) (1 diff)
-
Handler/Nickserv.php (modified) (1 diff)
-
Handler/Quit.php (modified) (1 diff)
-
Handler/RSSParser.php (modified) (1 diff)
-
Handler/Users.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Phergie/Event/Handler.php
r21 r24 30 30 31 31 /** 32 * Sets a reference to the client used to initiate commands 32 * Sets a reference to the client used to initiate commands. 33 33 * 34 34 * @param Phergie_Client $client … … 40 40 41 41 /** 42 * Initializes the plugin 43 * 44 * Should it require initialization, just extend this method 45 */ 42 * Returns the short name of the current plugin. 43 * 44 * @return string 45 */ 46 public function getName() 47 { 48 return substr(get_class($this), 22); 49 } 50 51 /** 52 * Returns the value of a configuration setting for a plugin. 53 * 54 * @param string $setting Name of the setting 55 * @param string $plugin Name of the plugin, defaults to the current 56 * plugin (optional) 57 * @return string Value of the setting 58 */ 59 public function getIni($setting, $plugin = null) 60 { 61 if ($plugin === null) { 62 $plugin = $this->getName(); 63 } 64 return $this->_client->getIni($plugin . '.' . $setting); 65 } 66 67 /** 68 * Sets the value of a configuration setting for a plugin. 69 * 70 * @param string $setting Name of the setting 71 * @param string $value New value for the setting 72 * @param string $plugin Name of the plugin, defaults to the current 73 * plugin (optional) 74 */ 75 public function setIni($setting, $value, $plugin = null) 76 { 77 if ($plugin === null) { 78 $plugin = $this->getName(); 79 } 80 $this->_client->setIni($plugin . '.' . $setting, $value); 81 } 82 83 /** 84 * Initializes the plugin. Should it require initialization, just 85 * override this method. 86 */ 46 87 public function init() { } 47 88 -
trunk/Phergie/Event/Handler/AdminCommand.php
r21 r24 2 2 3 3 /** 4 * @see Phergie_Event_Handler 4 * @see Phergie_Event_Handler_Command 5 5 */ 6 require_once 'Phergie/Event/Handler .php';6 require_once 'Phergie/Event/Handler/Command.php'; 7 7 8 8 /** … … 31 31 * </code> 32 32 */ 33 abstract class Phergie_Event_Handler_AdminCommand extends Phergie_Event_Handler 33 abstract class Phergie_Event_Handler_AdminCommand extends Phergie_Event_Handler_Command 34 34 { 35 35 protected $_admins = array(); 36 protected $_ adminOps = array();36 protected $_ops = array(); 37 37 38 public function isAdmin(Phergie_Event_Request $event)38 public function fromAdmin(Phergie_Event_Request $event) 39 39 { 40 $class = substr(get_class($this), 22); 41 if (!isset($this->_admins[$class])) { 42 $this->initialize($class); 43 } 40 $class = $this->getName(); 44 41 $mask = $event->getNick() .'!'. $event->getUsername() .'@'. $event->getHost(); 45 42 // Check if is op and ops are admins 46 if($this->_adminOps[$class] === true && Phergie_Event_Handler_Users::isOp($event->getNick(), $event->getArgument(0)) === true) { 43 if($this->_ops[$class] === true 44 && Phergie_Event_Handler_Users::isOp($event->getNick(), $event->getArgument(0)) === true) { 47 45 return true; 48 46 } 49 47 // Try to match mask against admin masks 50 foreach ($this->_admins[$class] as $admin) { 51 if (preg_match('{^'.$admin.'$}', $mask)) { 52 return true; 53 } 54 } 48 if (isset($this->_admins[$class])) { 49 foreach ($this->_admins[$class] as $admin) { 50 if (preg_match('{^'.$admin.'$}', $mask)) { 51 return true; 52 } 53 } 54 } 55 55 return false; 56 56 } 57 57 58 p rotected function initialize($class)58 public function onPrivmsg(Phergie_Event_Request $event) 59 59 { 60 // Set adminOps values 61 $ini = $this->getIni($class.'.admin_ops'); 60 if ($this->fromAdmin($event) 61 && preg_match('/^' . $this->getConnection()->getNick() . ':?\s+(.*)$/', $event->getArgument(1), $m)) { 62 $this->processCommand($m[1], $event); 63 } 64 } 65 66 public function init() 67 { 68 $class = $this->getName(); 69 70 // Set ops values 71 $ini = $this->getIni('ops'); 62 72 if ($ini===null) { 63 $ini = $this->getIni(' admincommand.admin_ops');73 $ini = $this->getIni('ops', 'admincommand'); 64 74 } 65 75 if ($ini==='true' || $ini==='1') { 66 $this->_ adminOps[$class] = true;76 $this->_ops[$class] = true; 67 77 } else { 68 $this->_ adminOps[$class] = false;78 $this->_ops[$class] = false; 69 79 } 70 80 71 81 // Set admins values 72 $ini = $this->getIni( $class.'.admins');82 $ini = $this->getIni('admins'); 73 83 if ($ini===null) { 74 $ini = $this->getIni('admin command.admins');84 $ini = $this->getIni('admins', 'admincommand'); 75 85 } 76 86 $admins = preg_split('#[\s\r\n,]+#', $ini); -
trunk/Phergie/Event/Handler/Autojoin.php
r20 r24 7 7 public function onResponse(Phergie_Event_Response $response) 8 8 { 9 $channels = $this->getIni(' autojoin.channels');9 $channels = $this->getIni('channels'); 10 10 if (!empty($channels) 11 11 && $response->getCode() == Phergie_Event_Response::RPL_ENDOFMOTD) { -
trunk/Phergie/Event/Handler/Cron.php
r20 r24 36 36 { 37 37 if($this->ttl === null) { 38 $class = substr(get_class($this), 22); 39 if ((($time = $this->getIni($class.'.time_to_live')) !== null) || $time = $this->defaultTTL) { 38 if ((($time = $this->getIni('time_to_live')) !== null) || $time = $this->defaultTTL) { 40 39 $this->ttl = $time; 41 40 } -
trunk/Phergie/Event/Handler/JoinPart.php
r20 r24 8 8 class Phergie_Event_Handler_JoinPart extends Phergie_Event_Handler_AdminCommand 9 9 { 10 public function onPrivmsg(Phergie_Event_Request $event) 10 /** 11 * Joins the specified channel. 12 * 13 * @param string $channel Name of the channel to join 14 */ 15 public function onDoJoin($channel) 11 16 { 12 // Tries to match join #chan or part [#chan] (parts the chan where the command is called if no chan provided) 13 if (preg_match('{^(join|part)\s*(#.*)?$}i', $event->getArgument(1), $m)) { 14 // Checks admin 15 if ($this->isAdmin($event, __CLASS__)) { 16 if ($m[1] === 'join' && $m[2] != null) { 17 $this->doJoin($m[2]); 18 } elseif ($m[1] === 'part' && ($m[2] != null || substr($event->getArgument(0), 0, 1) === '#')) { 19 $this->doPart($m[2] == null ? $event->getArgument(0) : $m[2]); 20 } 21 } 22 } 17 $this->doJoin($channel); 18 } 19 20 /** 21 * Parts either the specified channel or the current channel if none is 22 * specified. 23 * 24 * @param mixed $spec A string containing the name of the channel to part 25 * or an instance of Phergie_Event_Request for the 26 * original event that occurred 27 */ 28 public function onDoPart($spec) 29 { 30 if ($spec instanceof Phergie_Event_Request) { 31 $this->doPart($spec->getArgument(0)); 32 } else { 33 $this->doPart($spec); 34 } 23 35 } 24 36 } -
trunk/Phergie/Event/Handler/Nickserv.php
r1 r24 9 9 if ($event->getNick() == 'NickServ' 10 10 && $event->getArgument(1) == 'This nickname is owned by someone else') { 11 $password = $this->getIni(' nickserv.password');11 $password = $this->getIni('password'); 12 12 if (!empty($password)) { 13 13 $this->doPrivmsg('NickServ', 'IDENTIFY ' . $password); -
trunk/Phergie/Event/Handler/Quit.php
r20 r24 8 8 class Phergie_Event_Handler_Quit extends Phergie_Event_Handler_AdminCommand 9 9 { 10 public function on Privmsg(Phergie_Event_Request $event)10 public function onDoQuit(Phergie_Event_Request $event) 11 11 { 12 if($event->getArgument(1)=='quit' && $this->isAdmin($event)) { 13 $this->doQuit('by request of ' . $event->getNick()); 14 } 12 $this->doQuit('by request of ' . $event->getNick()); 15 13 } 16 14 } -
trunk/Phergie/Event/Handler/RSSParser.php
r23 r24 19 19 $i = 0; 20 20 $this->feeds = array(); 21 while ($i < 10 || ($this->getIni(' rssparser.feed'.$i) !== null && $this->getIni('rssparser.chans'.$i) !== null)) {22 $this->feeds[] = array($this->getIni(' rssparser.feed'.$i), preg_split('#[\s\r\n,]+#', $this->getIni('rssparser.chans'.$i)));21 while ($i < 10 || ($this->getIni('feed'.$i) !== null && $this->getIni('chans'.$i) !== null)) { 22 $this->feeds[] = array($this->getIni('feed'.$i), preg_split('#[\s\r\n,]+#', $this->getIni('chans'.$i))); 23 23 $i++; 24 24 } -
trunk/Phergie/Event/Handler/Users.php
r17 r24 66 66 { 67 67 if ($event->getCode() == Phergie_Event_Response::RPL_NAMREPLY) { 68 echo $event->getDescription()."\n";69 68 $desc = $event->getDescription(); 70 69 $desc = substr($desc, strpos($desc, '=')+2);