X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=blobdiff_plain;f=videosite-irssi.pl;h=86e370d147aea1eb92f90c60976129884bb4ed28;hp=3db9af162f8c994e2c211d422af9db2f570610ef;hb=01fc17a9fd2a11cd5826a2581fe662e96ac5912c;hpb=958d41cb7f0bebd3a0ed2533af2ffbef07bf272b diff --git a/videosite-irssi.pl b/videosite-irssi.pl index 3db9af1..86e370d 100644 --- a/videosite-irssi.pl +++ b/videosite-irssi.pl @@ -9,6 +9,9 @@ use File::Spec; use Module::Load; use XML::Simple; use JSON -support_by_pp; +use Carp; + +$SIG{ __DIE__ } = sub { Carp::confess( @_ ) }; # # List of foreground colors. This list is not complete, it just @@ -211,7 +214,8 @@ sub videosite_hook { my ($cmdline, $server, $witem) = @_; my %event = ( message => $cmdline, - ewpf => sub { defined($witem)?$witem->print($_[0]):Irssi::print($_[0]) }, + ewpf => sub { defined($witem)?$witem->print($_[0], MSGLEVEL_CLIENTCRAP):Irssi::print($_[0]) }, + window => defined($witem)?$witem->{server}->{real_address} . "/" . $witem->{name}:"", ); libvideosite::handle_command(\%event); @@ -223,28 +227,45 @@ sub videosite_hook { # sub message_hook { my ($server, $msg, $nick, $userhost, $channel) = @_; - my $evitem = $server->window_item_find($channel); + my $witem = $server->window_item_find($channel); my %event = ( message => $msg, - ewpf => sub { defined($evitem)?$evitem->print($_[0]):Irssi::print($_[0]) }, + ewpf => sub { defined($witem)?$witem->print($_[0], MSGLEVEL_CLIENTCRAP):Irssi::print($_[0]) }, + window => defined($witem)?$witem->{server}->{real_address} . "/" . $witem->{name}:"", ); libvideosite::check_for_link(\%event); } sub videosite_reset { + my $libpath; + + # Find out the script directory, and add it to @INC. + # This is necessary to find libvideosite.pm + $libpath = File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts'); + + # If the library is already loaded unload it + foreach (keys(%INC)) { + if ($INC{$_} eq File::Spec->catfile($libpath, 'libvideosite.pm')) { + delete($INC{$_}); + } + } + + push(@INC, $libpath); + load 'libvideosite'; + unless(libvideosite::register_api({ io => sub { Irssi::print($_[0]) }, config_init => \&config_init, config_get => \&config_get, config_set => \&config_set, config_has => \&config_has, - config_save => \&config_save, + config_save => sub { 1 }, config_del => \&config_del, color => \&colorpair, module_path => sub { return File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts') }, quote => sub { s/%/%%/g; return $_ }, - _debug => sub { 1 }, + reload => \&videosite_reset, })) { Irssi::print(sprintf("videosite API register failed: %s", $libvideosite::error)); return 0; @@ -259,11 +280,6 @@ sub videosite_reset { } sub videosite_init { - # Find out the script directory, and add it to @INC. - # This is necessary to find libvideosite.pm - - push(@INC, File::Spec->catfile(Irssi::get_irssi_dir(), 'scripts')); - load 'libvideosite'; if (videosite_reset()) { signal_add_last("message public", sub { message_hook(@_) });