git://git.camperquake.de
/
quotesite.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change quotesite to use BettIrssi, clean up module hierarchy for the plugins
[quotesite.git]
/
quotesite.pl
diff --git
a/quotesite.pl
b/quotesite.pl
index
a6414a9
..
94859d7
100644
(file)
--- a/
quotesite.pl
+++ b/
quotesite.pl
@@
-3,17
+3,28
@@
# (c) 2007-2008 by Ralf Ertzinger <ralf@camperquake.de>
# licensed under GNU GPL v2
# (c) 2007-2008 by Ralf Ertzinger <ralf@camperquake.de>
# licensed under GNU GPL v2
+
+BEGIN {
+ # Get rid of a (possibly old) version of BettIrssi
+ # This is a hack to prevent having to reload irssi just
+ # because BettIrssi.pm changed
+
+ delete($INC{'BettIrssi.pm'});
+}
+
use strict;
use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last window_find_refnum);
use vars qw($VERSION %IRSSI);
use XML::Simple;
use Data::Dumper;
use File::Spec;
use strict;
use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_last window_find_refnum);
use vars qw($VERSION %IRSSI);
use XML::Simple;
use Data::Dumper;
use File::Spec;
+use BettIrssi 101 qw(_bcb _bcs);
my @grabbers;
my $conf;
my $conffile = File::Spec->catfile(Irssi::get_irssi_dir(), 'quotesite.xml');
my $plugindir = File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts', 'quotesite');
my @grabbers;
my $conf;
my $conffile = File::Spec->catfile(Irssi::get_irssi_dir(), 'quotesite.xml');
my $plugindir = File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts', 'quotesite');
+my @outputstack = (undef);
my $PARAMS = {
};
my $PARAMS = {
};
@@
-23,74
+34,79
@@
my $PARAMS = {
my $debug = 0;
# "message public", SERVER_REC, char *msg, char *nick, char *address, char *target
my $debug = 0;
# "message public", SERVER_REC, char *msg, char *nick, char *address, char *target
-signal_add_last(
"message public" => sub {check_for_link(\@_,1,4,2,0);}
);
+signal_add_last(
_bcs("message public" => sub {check_for_link(@_)})
);
# "message own_public", SERVER_REC, char *msg, char *target
# "message own_public", SERVER_REC, char *msg, char *target
-signal_add_last(
"message own_public" => sub {check_for_link(\@_,1,2,-1,0);}
);
+signal_add_last(
_bcs("message own_public" => sub {check_for_link(@_)})
);
# "message private", SERVER_REC, char *msg, char *nick, char *address
# "message private", SERVER_REC, char *msg, char *nick, char *address
-signal_add_last(
"message private" => sub {check_for_link(\@_,1,-1,2,0);}
);
+signal_add_last(
_bcs("message private" => sub {check_for_link(@_)})
);
# "message own_private", SERVER_REC, char *msg, char *target, char *orig_target
# "message own_private", SERVER_REC, char *msg, char *target, char *orig_target
-signal_add_last(
"message own_private" => sub {check_for_link(\@_,1,2,-1,0);}
);
+signal_add_last(
_bcs("message own_private" => sub {check_for_link(@_)})
);
# "message irc action", SERVER_REC, char *msg, char *nick, char *address, char *target
# "message irc action", SERVER_REC, char *msg, char *nick, char *address, char *target
-signal_add_last(
"message irc action" => sub {check_for_link(\@_,1,4,2,0);}
);
+signal_add_last(
_bcs("message irc action" => sub {check_for_link(@_)})
);
# "message irc own_action", SERVER_REC, char *msg, char *target
# "message irc own_action", SERVER_REC, char *msg, char *target
-signal_add_last("message irc own_action" => sub {check_for_link(\@_,1,2,-1,0);});
+signal_add_last(_bcs("message irc own_action" => sub {check_for_link(@_)}));
+
+sub push_output {
+ unshift(@outputstack, shift);
+}
+
+sub pop_output {
+ shift(@outputstack);
+
+ @outputstack = (undef) unless (@outputstack);
+}
sub write_irssi {
sub write_irssi {
- my $witem = shift;
my @text = @_;
my @text = @_;
+ my $output = $outputstack[0];
-
$text[0] = 'quotesite: ' . $text[0]
;
+
my $format = "%%mquotesite: %%n" . shift(@text)
;
- if (defined($witem) && ref($witem)) {
- $witem->print(sprintf(shift(@text), @text), MSGLEVEL_CLIENTCRAP);
+ # escape % in parameters for irssi
+ s/%/%%/g foreach @text;
+
+ if (defined($output)) {
+ $output->(sprintf($format, @text), MSGLEVEL_CLIENTCRAP);
} else {
} else {
- Irssi::print(sprintf(
shift(@text)
, @text));
+ Irssi::print(sprintf(
$format
, @text));
}
}
sub write_debug {
if ($debug) {
}
}
sub write_debug {
if ($debug) {
- write_irssi(
shift,
@_);
+ write_irssi(@_);
}
}
sub check_for_link {
}
}
sub check_for_link {
- my ($signal,$parammessage,$paramchannel,$paramnick,$paramserver) = @_;
- my $server = $signal->[$paramserver];
- my $target = $signal->[$paramchannel];
- my $message = ($parammessage == -1) ? '' : $signal->[$parammessage];
+ my $event = shift;
+ my $message = $event->message();
+ my $channel = $event->channel();
my $g;
my $m;
my $p;
my $g;
my $m;
my $p;
- my $witem;
- if (defined $server) {
- $witem = $server->window_item_find($target);
- } else {
- $witem = Irssi::window_item_find($target);
- }
-
# Look if we should ignore this line
if ($message =~ m,(?:\s|^)/nosave(?:\s|$),) {
return;
}
# Look if we should ignore this line
if ($message =~ m,(?:\s|^)/nosave(?:\s|$),) {
return;
}
+ push_output($event->ewpf);
+
study($message);
# Offer the message to all Grabbers in turn
foreach $g (@grabbers) {
study($message);
# Offer the message to all Grabbers in turn
foreach $g (@grabbers) {
- # $g->pushio(sub{ write_irssi($witem, @_); });
($m, $p) = $g->get($message);
($m, $p) = $g->get($message);
- # $g->popio();
while (defined($m)) {
while (defined($m)) {
- write_irssi(
$witem,
'%%R>>> %%Y%s%%N %%G%s', $m->{'SOURCE'}, $m->{'ID'});
+ write_irssi('%%R>>> %%Y%s%%N %%G%s', $m->{'SOURCE'}, $m->{'ID'});
foreach (split(/[\n\r]+/, $m->{'CONTENT'})) {
foreach (split(/[\n\r]+/, $m->{'CONTENT'})) {
- write_irssi(
$witem,
' %%g%s', $_);
+ write_irssi(' %%g%s', $_);
}
# Remove the matched part from the message and try again (there may be
}
# Remove the matched part from the message and try again (there may be
@@
-101,6
+117,8
@@
sub check_for_link {
($m, $p) = $g->get($message);
}
}
($m, $p) = $g->get($message);
}
}
+
+ pop_output();
}
sub cmd_save {
}
sub cmd_save {
@@
-111,9
+129,9
@@
sub cmd_save {
close(CONF);
};
if ($@) {
close(CONF);
};
if ($@) {
- write_irssi(
undef,
'Could not save config to %s: %s', ($conffile, $@));
+ write_irssi('Could not save config to %s: %s', ($conffile, $@));
} else {
} else {
- write_irssi(
undef,
'configuration saved to %s', $conffile);
+ write_irssi('configuration saved to %s', $conffile);
}
}
}
}
@@
-129,7
+147,7
@@
sub cmd_set {
return;
}
}
return;
}
}
- write_irssi(
undef,
'No such module');
+ write_irssi('No such module');
}
}
@@
-143,7
+161,7
@@
sub cmd_enable {
return;
}
}
return;
}
}
- write_irssi(
undef,
'No such module');
+ write_irssi('No such module');
}
}
@@
-157,7
+175,7
@@
sub cmd_disable {
return;
}
}
return;
}
}
- write_irssi(
undef,
'No such module');
+ write_irssi('No such module');
}
}
@@
-169,16
+187,16
@@
sub cmd_show {
if (defined($target)) {
foreach $p (@grabbers) {
if ($p->{'NAME'} eq $target) {
if (defined($target)) {
foreach $p (@grabbers) {
if ($p->{'NAME'} eq $target) {
- write_irssi(
undef,
$p->getconfstr());
+ write_irssi($p->getconfstr());
return;
}
}
return;
}
}
- write_irssi(
undef,
'No such module');
+ write_irssi('No such module');
} else {
} else {
- write_irssi(
undef,
'Loaded grabbers (* denotes enabled modules):');
+ write_irssi('Loaded grabbers (* denotes enabled modules):');
foreach $p (@grabbers) {
$e = $p->_getval('enabled');
foreach $p (@grabbers) {
$e = $p->_getval('enabled');
- write_irssi(
undef,
' %s%s', $p->{'NAME'}, $e?'*':'');
+ write_irssi(' %s%s', $p->{'NAME'}, $e?'*':'');
};
}
}
};
}
}
@@
-190,13
+208,13
@@
sub cmd_help {
if (defined($target)) {
foreach $p (@grabbers) {
if ($p->{'NAME'} eq $target) {
if (defined($target)) {
foreach $p (@grabbers) {
if ($p->{'NAME'} eq $target) {
- write_irssi(
undef,
$p->gethelpstr());
+ write_irssi($p->gethelpstr());
return;
}
}
return;
}
}
- write_irssi(
undef,
'No such module');
+ write_irssi('No such module');
} else {
} else {
- write_irssi(
undef,
<<'EOT');
+ write_irssi(<<'EOT');
Supported commands:
save: Save the current configuration
help [modulename]: Display this help, or module specific help
Supported commands:
save: Save the current configuration
help [modulename]: Display this help, or module specific help
@@
-234,32
+252,32
@@
sub ploader {
closedir(D);
foreach $p (@list) {
closedir(D);
foreach $p (@list) {
- write_debug(
undef,
"Trying to load $p:");
+ write_debug("Trying to load $p:");
$p =~ s/\.pm$//;
$p =~ s/\.pm$//;
- eval qq{ require $p; };
+ eval qq{ require
quotesite::
$p; };
if ($@) {
if ($@) {
- write_debug(
undef,
"Failed to load plugin: $@");
+ write_debug("Failed to load plugin: $@");
next;
}
next;
}
- $g = eval
$p.q{->new();
};
+ $g = eval
qq{ quotesite::$p->new();
};
if ($@) {
if ($@) {
- write_debug(
undef,
"Failed to instanciate: $@");
+ write_debug("Failed to instanciate: $@");
delete($INC{$p});
next;
}
delete($INC{$p});
next;
}
- write_debug(
undef,
"found $g->{'TYPE'} $g->{'NAME'}");
+ write_debug("found $g->{'TYPE'} $g->{'NAME'}");
if ($type eq $g->{'TYPE'}) {
push(@g, $g);
if ($type eq $g->{'TYPE'}) {
push(@g, $g);
- $g->setio(
sub {Irssi::print(shift)}
);
+ $g->setio(
\&write_irssi
);
} else {
} else {
- write_irssi(
undef,
'%s has wrong type (got %s, expected %s)', $p, $g->{'TYPE'}, $type);
+ write_irssi('%s has wrong type (got %s, expected %s)', $p, $g->{'TYPE'}, $type);
delete($INC{$p});
}
}
delete($INC{$p});
}
}
- write_debug(
undef,
"Loaded %d plugins", $#g+1);
+ write_debug("Loaded %d plugins", $#g+1);
return @g;
}
return @g;
}
@@
-270,7
+288,7
@@
sub _load_modules($) {
foreach (keys(%INC)) {
if ($INC{$_} =~ m|^$path|) {
foreach (keys(%INC)) {
if ($INC{$_} =~ m|^$path|) {
- write_debug(
undef,
"Removing %s from \$INC", $_);
+ write_debug("Removing %s from \$INC", $_);
delete($INC{$_});
}
}
delete($INC{$_});
}
}
@@
-285,7
+303,7
@@
sub init_quotesite {
unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}))) {
# No config, start with an empty one
unless(-r $conffile && defined($conf = XML::Simple::XMLin($conffile, ForceArray => ['config', 'option'], KeepRoot => 1, KeyAttr => {'config' => 'module', 'option' => 'key'}))) {
# No config, start with an empty one
- write_debug(
undef,
'No config found, using defaults');
+ write_debug('No config found, using defaults');
$conf = { 'quotesite' => { }};
}
foreach (keys(%{$PARAMS})) {
$conf = { 'quotesite' => { }};
}
foreach (keys(%{$PARAMS})) {
@@
-297,7
+315,7
@@
sub init_quotesite {
_load_modules($plugindir);
unless (defined(@grabbers)) {
_load_modules($plugindir);
unless (defined(@grabbers)) {
- write_irssi(
undef,
'No grabbers found, can not proceed.');
+ write_irssi('No grabbers found, can not proceed.');
return;
}
return;
}
@@
-314,15
+332,17
@@
sub init_quotesite {
Irssi::signal_add('setup saved', 'cmd_save');
Irssi::signal_add('setup saved', 'cmd_save');
- Irssi::command_bind(
'quotesite' => \&cmdhandler
);
+ Irssi::command_bind(
_bcb('quotesite' => \&cmdhandler)
);
}
}
- write_irssi(
undef,
'quotesite initialized');
+ write_irssi('quotesite initialized');
}
sub cmdhandler {
}
sub cmdhandler {
- my ($data, $server, $item) = @_;
- my @params = split(/\s+/, $data);
+ my $event = shift;
+ my @params = split(/\s+/, $event->message());
+
+ push_output($event->ewpf);
if ($params[0] eq 'save') {
cmd_save();
if ($params[0] eq 'save') {
cmd_save();
@@
-348,14
+368,16
@@
sub cmdhandler {
foreach (@grabbers) {
$_->setdebug(1);
}
foreach (@grabbers) {
$_->setdebug(1);
}
- write_irssi(
$item,
'Enabled debugging');
+ write_irssi('Enabled debugging');
} elsif ($params[0] eq 'nodebug') {
$debug = 0;
foreach (@grabbers) {
$_->setdebug(0);
}
} elsif ($params[0] eq 'nodebug') {
$debug = 0;
foreach (@grabbers) {
$_->setdebug(0);
}
- write_irssi(
$item,
'Disabled debugging');
+ write_irssi('Disabled debugging');
}
}
+
+ pop_output();
}
unshift(@INC, $plugindir);
}
unshift(@INC, $plugindir);