cvs: embed /php-irssi theme.c /php-irssi/examples autoop.php
[email protected] ("Wez Furlong") Tue, 01 Apr 2003 20:39:31 -0000
| Newsgroups | php.embed.cvs |
|---|---|
| Message-ID | <cvswez1049229571@cvsserver> |
--wez1049229571
Content-Type: text/plain
wez Tue Apr 1 15:39:31 2003 EDT
Modified files:
/embed/php-irssi theme.c
/embed/php-irssi/examples autoop.php
Log:
Fix theme/format printing.
Make autoop script use themes/formats for its output.
--wez1049229571
Content-Type: text/plain
Content-Disposition: attachment; filename="wez-20030401153931.txt"
Index: embed/php-irssi/theme.c
diff -u embed/php-irssi/theme.c:1.2 embed/php-irssi/theme.c:1.3
--- embed/php-irssi/theme.c:1.2 Tue Apr 1 14:36:20 2003
+++ embed/php-irssi/theme.c Tue Apr 1 15:39:31 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
| Author: Wez Furlong <[email protected]> |
+----------------------------------------------------------------------+
- $Id: theme.c,v 1.2 2003/04/01 19:36:20 wez Exp $
+ $Id: theme.c,v 1.3 2003/04/01 20:39:31 wez Exp $
*/
#include "php-irssi.h"
@@ -144,7 +144,7 @@
}
for (n = 2; n < ZEND_NUM_ARGS(); n++) {
- convert_to_array_ex(args[n]);
+ convert_to_string_ex(args[n]);
arglist[n-2] = Z_STRVAL_PP(args[n]);
}
}
Index: embed/php-irssi/examples/autoop.php
diff -u embed/php-irssi/examples/autoop.php:1.4 embed/php-irssi/examples/autoop.php:1.5
--- embed/php-irssi/examples/autoop.php:1.4 Tue Apr 1 11:19:18 2003
+++ embed/php-irssi/examples/autoop.php Tue Apr 1 15:39:31 2003
@@ -1,5 +1,5 @@
<?php
-/* $Id: autoop.php,v 1.4 2003/04/01 16:19:18 wez Exp $
+/* $Id: autoop.php,v 1.5 2003/04/01 20:39:31 wez Exp $
*
* Autoop.
*
@@ -10,135 +10,155 @@
* Inspired by the perl version in the irssi distro.
*/
-class AutoOp {
+namespace SampleAutoOp {
- var $oplist = array();
+ class AutoOp {
- /* The autoop command allows you to define who gets ops and where.
- * Remember to /save after making changes to the oplist.
- * /autoop add nick|mask [[nick|mask] ...]
- */
- function cmd_autoop(/* string */ $params, /* SERVER */ $server, /* CHANNEL */ $channel)
- {
- $args = explode(' ', $params);
-
- if ($args[0] == '*') {
- $channame = '*';
- array_shift($args);
- } else {
- $channame = $channel->name;
- }
+ var $oplist = array();
- switch(array_shift($args)) {
- case "add":
- while (($mask = array_shift($args))) {
- if (strpos($mask, '*') === false) {
- $nick = $channel->nick_find($mask);
- $mask = irssi_irc_get_mask($nick->nick, $nick->host);
+ /* The autoop command allows you to define who gets ops and where.
+ * Remember to /save after making changes to the oplist.
+ * /autoop add nick|mask [[nick|mask] ...]
+ */
+ function cmd_autoop(/* string */ $params, /* SERVER */ $server, /* CHANNEL */ $channel)
+ {
+ $args = explode(' ', $params);
+
+ if ($args[0] == '*') {
+ $channame = '*';
+ array_shift($args);
+ } else {
+ $channame = $channel->name;
+ }
+
+ switch(array_shift($args)) {
+ case "add":
+ while (($mask = array_shift($args))) {
+ if (strpos($mask, '*') === false) {
+ $nick = $channel->nick_find($mask);
+ $mask = irssi_irc_get_mask($nick->nick, $nick->host);
+ }
+ irssi_printformat(IRSSI_MSGLEVEL_CRAP, 'oplist_adding', $mask);
+ $this->oplist[$channame][] = $mask;
}
- printf("Adding %s\n", $mask);
- $this->oplist[$channame][] = $mask;
- }
break;
- case "list":
- echo "OpList is currently:\n";
- print_r($this->oplist);
+ case "list":
+ if (count($this->oplist) == 0) {
+ irssi_printformat(IRSSI_MSGLEVEL_CRAP, 'oplist_empty');
+ } else {
+ irssi_printformat(IRSSI_MSGLEVEL_CRAP, 'oplist_contains');
+ foreach ($this->oplist as $channel => $nicks) {
+ foreach ($nicks as $nick) {
+ irssi_printformat(IRSSI_MSGLEVEL_CRAP, 'oplist_line', $channel, $nick);
+ }
+ }
+ }
break;
+ }
+
+ /* store */
+ irssi_settings_set_str('autoop_oplist', base64_encode(serialize($this->oplist)));
}
- /* store */
- irssi_settings_set_str('autoop_oplist', base64_encode(serialize($this->oplist)));
- }
+ function get_autoop_masks($channame)
+ {
+ $masks = array();
+ if (isset($this->oplist[$channame])) {
+ $masks[] = implode(' ', $this->oplist[$channame]);
+ }
+ if (isset($this->oplist['*'])) {
+ $masks[] = implode(' ', $this->oplist['*']);
+ }
- function get_autoop_masks($channame)
- {
- $masks = array();
- if (isset($this->oplist[$channame])) {
- $masks[] = implode(' ', $this->oplist[$channame]);
- }
- if (isset($this->oplist['*'])) {
- $masks[] = implode(' ', $this->oplist['*']);
+ $masks = implode(' ', $masks);
+
+ return $masks;
}
- $masks = implode(' ', $masks);
+ function handle_massjoin(/* CHANNEL */ $channel, /* array of NICK */ $nicks)
+ {
- return $masks;
- }
+ if (!$channel->chanop) {
+ /* can't give ops if we don't have it :) */
+ return;
+ }
- function handle_massjoin(/* CHANNEL */ $channel, /* array of NICK */ $nicks)
- {
+ $server = $channel->server;
+ $to_op = array();
+ $masks = AutoOp::get_autoop_masks($channel->name);
+
+ foreach ($nicks as $nick) {
+ if ($server->masks_match($masks, $nick->nick, $nick->host)) {
+ $to_op[] = $nick->nick;
+ }
+ }
- if (!$channel->chanop) {
- /* can't give ops if we don't have it :) */
- return;
+ if (count($to_op)) {
+ $channel->command('op ' . implode(' ', $to_op));
+ }
}
- $server = $channel->server;
- $to_op = array();
- $masks = AutoOp::get_autoop_masks($channel->name);
-
- foreach ($nicks as $nick) {
- if ($server->masks_match($masks, $nick->nick, $nick->host)) {
- $to_op[] = $nick->nick;
+ function handle_mode(/* SERVER */ $server, $commandstr, $sourcenick, $sourceaddr)
+ {
+ list($channame, $modestr, $nicks) = explode(' ', $commandstr, 3);
+
+ /* get the correct channel object */
+ $channel = $server->channel_find($channame);
+ if (!$channel->chanop) {
+ /* can't give ops if we don't have it */
+ return;
}
- }
-
- if (count($to_op)) {
- $channel->command('op ' . implode(' ', $to_op));
- }
- }
- function handle_mode(/* SERVER */ $server, $commandstr, $sourcenick, $sourceaddr)
- {
- list($channame, $modestr, $nicks) = explode(' ', $commandstr, 3);
-
- /* get the correct channel object */
- $channels = $server->channels;
- foreach ($channels as $channel) {
- if ($channels->name == $channame) {
- break;
+ $masks = AutoOp::get_autoop_masks($channame);
+ $to_op = array();
+
+ /* op everyone that is not an op and who is on the op-list */
+ $nicks = $channel->nicks;
+ foreach ($nicks as $nick) {
+ if (!$nick->op && $server->masks_match($masks, $nick->nick, $nick->host)) {
+ $to_op[] = $nick->nick;
+ }
+ }
+
+ if (count($to_op)) {
+ $channel->command('op ' . implode(' ', $to_op));
}
- }
- if (!$channel->chanop) {
- /* can't give ops if we don't have it */
- return;
}
- $masks = AutoOp::get_autoop_masks($channame);
- $to_op = array();
-
- /* op everyone that is not an op and who is on the op-list */
- $nicks = $channel->nicks;
- foreach ($nicks as $nick) {
- if (!$nick->op && $server->masks_match($masks, $nick->nick, $nick->host)) {
- $to_op[] = $nick->nick;
+ function __construct()
+ {
+ 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));
}
- }
- if (count($to_op)) {
- $channel->command('op ' . implode(' ', $to_op));
}
-
+
}
- function __construct()
+
+ function init()
{
+ // Only do this once
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_theme_register(array(
+ 'oplist_empty' => 'Your oplist is empty',
+ 'oplist_contains' => 'Your oplist contains:',
+ 'oplist_adding' => 'Adding $0 to oplist',
+ 'oplist_line' => 'Channel $0: $1',
+ ));
+ new AutoOp();
}
-
}
-new AutoOp();
+SampleAutoOp::init();
?>
--wez1049229571--