cvs: embed /php-irssi/examples autoop.php
[email protected] ("Wez Furlong") Tue, 01 Apr 2003 16:17:19 -0000
| Newsgroups | php.embed.cvs |
|---|---|
| Message-ID | <cvswez1049213839@cvsserver> |
wez Tue Apr 1 11:17:19 2003 EDT
Modified files:
/embed/php-irssi/examples autoop.php
Log:
Make auto-op more OO.
Also, allow adding multiple items in /autoop add, as well as adding a mask
directly (rather than have irssi generate it for you).
Index: embed/php-irssi/examples/autoop.php
diff -u embed/php-irssi/examples/autoop.php:1.2 embed/php-irssi/examples/autoop.php:1.3
--- embed/php-irssi/examples/autoop.php:1.2 Tue Apr 1 10:00:47 2003
+++ embed/php-irssi/examples/autoop.php Tue Apr 1 11:17:17 2003
@@ -1,5 +1,5 @@
<?php
-/* $Id: autoop.php,v 1.2 2003/04/01 15:00:47 wez Exp $
+/* $Id: autoop.php,v 1.3 2003/04/01 16:17:17 wez Exp $
*
* Autoop.
*
@@ -12,44 +12,51 @@
class AutoOp {
+ var $oplist = array();
+
/* The autoop command allows you to define who gets ops and where.
* Remember to /save after making changes to the oplist.
- * /autoop add nick
+ * /autoop add nick|mask [[nick|mask] ...]
*/
function cmd_autoop(/* string */ $params, /* SERVER */ $server, /* CHANNEL */ $channel)
{
- global $AutoOpList;
-
$args = explode(' ', $params);
-
- $channame = $channel->name;
+
+ if ($args[0] == '*') {
+ $channame = '*';
+ } else {
+ $channame = $channel->name;
+ }
switch(array_shift($args)) {
case "add":
- $nick = $channel->nick_find(array_shift($args));
- printf("Adding %s (%s)\n", $nick->nick, $nick->host);
- $AutoOpList[$channame][] = irssi_irc_get_mask($nick->nick, $nick->host);
+ while (($mask = array_shift($args))) {
+ if (strpos($mask, '*') === false) {
+ $nick = $channel->nick_find($mask);
+ $mask = irssi_irc_get_mask($nick->nick, $nick->host);
+ }
+ printf("Adding %s\n", $mask);
+ $this->oplist[$channame][] = $mask;
+ }
break;
case "list":
echo "OpList is currently:\n";
- print_r($AutoOpList);
+ print_r($this->oplist);
break;
}
/* store */
- irssi_settings_set_str('autoop_oplist', base64_encode(serialize($AutoOpList)));
+ irssi_settings_set_str('autoop_oplist', base64_encode(serialize($this->oplist)));
}
function get_autoop_masks($channame)
{
- global $AutoOpList;
-
$masks = array();
- if (isset($AutoOpList[$channame])) {
- $masks[] = implode(' ', $AutoOpList[$channame]);
+ if (isset($this->oplist[$channame])) {
+ $masks[] = implode(' ', $this->oplist[$channame]);
}
- if (isset($AutoOpList['*'])) {
- $masks[] = implode(' ', $AutoOpList['*']);
+ if (isset($this->oplist['*'])) {
+ $masks[] = implode(' ', $this->oplist['*']);
}
$masks = implode(' ', $masks);
@@ -114,19 +121,23 @@
}
-}
+ function __construct()
+ {
+ irssi_settings_add_str('autoop', 'autoop_oplist', '');
+ irssi_command_bind('autoop', array($this, 'cmd_autoop'));
+ irssi_signal_add('massjoin', array($this, 'handle_massjoin'), IRSSI_SIGNAL_PRIORITY_LOW);
+ irssi_signal_add('event mode', array($this, 'handle_mode'), IRSSI_SIGNAL_PRIORITY_LOW);
+
+ $oplist = irssi_settings_get_str('autoop_oplist');
+
+ if (strlen($oplist)) {
+ $this->oplist = unserialize(base64_decode($oplist));
+ }
+
+ }
-irssi_settings_add_str('autoop', 'autoop_oplist', '');
-irssi_command_bind('autoop', array('AutoOp', 'cmd_autoop'));
-irssi_signal_add('massjoin', array('AutoOp', 'handle_massjoin'), IRSSI_SIGNAL_PRIORITY_LOW);
-irssi_signal_add('event mode', array('AutoOp', 'handle_mode'), IRSSI_SIGNAL_PRIORITY_LOW);
-
-/* keyed by channel */
-$GLOBALS['AutoOpList'] = irssi_settings_get_str('autoop_oplist');
-
-if (strlen($GLOBALS['AutoOpList'])) {
- $GLOBALS['AutoOpList'] = unserialize(base64_decode($GLOBALS['AutoOpList']));
-} else {
- $GLOBALS['AutoOpList'] = array();
}
+
+new AutoOp();
+
?>