X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite.pl;h=bf14b9560f54a7db27a141d67cad07b29d0afa42;hb=80b87674e8efaeeb259a4f84167b6ed4209b0989;hp=3ae1e83fdfe0fd03a82e0475f37226af3a10a5ce;hpb=1d562536b9c6135697a468ae572cb4afce36db34;p=videosite.git diff --git a/videosite.pl b/videosite.pl index 3ae1e83..bf14b95 100644 --- a/videosite.pl +++ b/videosite.pl @@ -45,6 +45,63 @@ signal_add_last("message irc action" => sub {check_for_link(\@_,1,4,2,0);}); # "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);}); +# For tab completion +signal_add_first('complete word', \&sig_complete); + +my $videosite_commands = { + 'save' => sub { + cmd_save(); + }, + + 'set' => sub { + cmd_set(@_); + }, + + 'show' => sub { + cmd_show(@_); + }, + + 'help' => sub { + cmd_help(@_); + }, + + 'getter' => sub { + cmd_getter(@_); + }, + + 'enable' => sub { + cmd_enable(@_); + }, + + 'disable' => sub { + cmd_disable(@_); + }, + + 'reload' => sub { + init_videosite(0); + }, + + 'mode' => sub { + cmd_mode(@_); + }, + + 'debug' => sub { + $debug = 1; + foreach (@grabbers, @getters) { + $_->setdebug(1); + } + write_irssi(undef, 'Enabled debugging'); + }, + + 'nodebug' => sub { + $debug = 0; + foreach (@grabbers, @getters) { + $_->setdebug(0); + } + write_irssi(undef, 'Disabled debugging'); + }, +}; + sub write_irssi { my $witem = shift; my @text = @_; @@ -87,6 +144,8 @@ sub check_for_link { return; } + study($message); + # Offer the message to all Grabbers in turn foreach $g (@grabbers) { ($m, $p) = $g->get($message); @@ -106,6 +165,7 @@ sub check_for_link { # Remove the matched part from the message and try again (there may be # more!) $message =~ s/$p//; + study($message); ($m, $p) = $g->get($message); } @@ -288,13 +348,13 @@ sub ploader { $p =~ s/\.pm$//; eval qq{ require $p; }; if ($@) { - write_debug(undef, "Failed to load plugin: $@"); + write_irssi(undef, "Failed to load plugin: $@"); next; } $g = eval $p.q{->new();}; if ($@) { - write_debug(undef, "Failed to instanciate: $@"); + write_irssi(undef, "Failed to instanciate: $@"); delete($INC{$p}); next; } @@ -379,47 +439,56 @@ sub init_videosite { write_irssi(undef, 'videosite initialized'); } -sub cmdhandler { - my ($data, $server, $item) = @_; - my @params = split(/\s+/, $data); +sub sig_complete { + my ($complist, $window, $word, $linestart, $want_space) = @_; + my @matches; - if ($params[0] eq 'save') { - cmd_save(); - } elsif ($params[0] eq 'set') { - shift(@params); - cmd_set(@params); - } elsif ($params[0] eq 'show') { - shift(@params); - cmd_show(@params); - } elsif ($params[0] eq 'help') { - shift(@params); - cmd_help(@params); - } elsif ($params[0] eq 'getter') { - shift(@params); - cmd_getter(@params); - } elsif ($params[0] eq 'enable') { - shift(@params); - cmd_enable(@params); - } elsif ($params[0] eq 'disable') { - shift(@params); - cmd_disable(@params); - } elsif ($params[0] eq 'reload') { - init_videosite(0); - } elsif ($params[0] eq 'mode') { - shift(@params); - cmd_mode(@params); - } elsif ($params[0] eq 'debug') { - $debug = 1; + if ($linestart !~ m|^/videosite\b|) { + return; + } + + if ('/videosite' eq $linestart) { + # No command enterd so far. Produce a list of possible follow-ups + @matches = grep {/^$word/} keys (%{$videosite_commands}); + } elsif ('/videosite set' eq $linestart) { + # 'set' command entered. Produce a list of modules foreach (@grabbers, @getters) { - $_->setdebug(1); + push(@matches, $_->{'NAME'}) if $_->{'NAME'} =~ m|^$word|; + }; + } elsif ($linestart =~ m|^/videosite set (\w+)$|) { + my $module = $1; + + foreach my $p (@getters, @grabbers) { + if ($p->{'NAME'} eq $module) { + @matches = $p->getparamlist($word); + last; + } } - write_irssi(undef, 'Enabled debugging'); - } elsif ($params[0] eq 'nodebug') { - $debug = 0; - foreach (@grabbers, @getters) { - $_->setdebug(0); + } elsif ($linestart =~ m|/videosite set (\w+) (\w+)$|) { + my $module = $1; + my $param = $2; + + foreach my $p (@getters, @grabbers) { + if ($p->{'NAME'} eq $module) { + @matches = $p->getparamvalues($param, $word); + last; + } } - write_irssi(undef, 'Disabled debugging'); + } + + + push(@{$complist}, sort @matches); + ${$want_space} = 0; + + Irssi::signal_stop(); +} + +sub cmdhandler { + my ($data, $server, $item) = @_; + my ($cmd, @params) = split(/\s+/, $data); + + if (exists($videosite_commands->{$cmd})) { + $videosite_commands->{$cmd}->(@params); } }