X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=videosite.pl;h=54a1280099f9e3635c2dc51e96b3f95fc0d3fce5;hb=34c1819276e42705e9f191ea602abb17ca9ef9fc;hp=3ae1e83fdfe0fd03a82e0475f37226af3a10a5ce;hpb=1d562536b9c6135697a468ae572cb4afce36db34;p=videosite.git diff --git a/videosite.pl b/videosite.pl index 3ae1e83..54a1280 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,36 @@ sub init_videosite { write_irssi(undef, 'videosite initialized'); } +sub sig_complete { + my ($complist, $window, $word, $linestart, $want_space) = @_; + my @matches; + + 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) { + push(@matches, $_->{'NAME'}) if $_->{'NAME'} =~ m|^$word|; + }; + } + + push(@{$complist}, sort @matches); + ${$want_space} = 0; + + Irssi::signal_stop(); +} + sub cmdhandler { my ($data, $server, $item) = @_; - my @params = split(/\s+/, $data); + my ($cmd, @params) = split(/\s+/, $data); - 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; - foreach (@grabbers, @getters) { - $_->setdebug(1); - } - write_irssi(undef, 'Enabled debugging'); - } elsif ($params[0] eq 'nodebug') { - $debug = 0; - foreach (@grabbers, @getters) { - $_->setdebug(0); - } - write_irssi(undef, 'Disabled debugging'); + if (exists($videosite_commands->{$cmd})) { + $videosite_commands->{$cmd}->(@params); } }