From: bw1 Date: Wed, 13 Jan 2021 16:18:42 +0000 (+0100) Subject: [0x0st] v0.04 X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=240e8437c19e05e7e801c7981b81bc7c61deadb7;p=irssi-scripts.irssi.org.git [0x0st] v0.04 + selfcheck --- diff --git a/scripts/0x0st.pl b/scripts/0x0st.pl index 30dcf32..95c7d96 100644 --- a/scripts/0x0st.pl +++ b/scripts/0x0st.pl @@ -8,7 +8,7 @@ use LWP::UserAgent; use Storable qw/store_fd fd_retrieve/; use File::Glob qw/:bsd_glob/; -$VERSION = '0.03'; +$VERSION = '0.04'; %IRSSI = ( authors => 'bw1', contact => 'bw1@aol.at', @@ -16,9 +16,10 @@ $VERSION = '0.03'; description => 'upload file to https://0x0.st/', license => 'ISC', url => 'https://scripts.irssi.org/', - changed => '2020-04-12', + changed => '2021-01-13', modules => 'POSIX HTTP::Request::Common LWP::UserAgent Storable File::Glob', commands=> '0x0st', + selfcheckcmd=> '0x0st -c', ); my $help = << "END"; @@ -28,11 +29,13 @@ my $help = << "END"; $VERSION %9Syntax%9 /0x0st [-p] [-s | -u | file ] + /0x0st -c %9Description%9 $IRSSI{description} -p past url to channel -s shorten url -u file from url + -c self check %9See also%9 https://0x0.st/ https://github.com/lachs0r/0x0 @@ -43,6 +46,7 @@ my $test_str; my $base_uri; my %bg_process= (); +my $self_check_timer; sub background { my ($cmd) =@_; @@ -147,6 +151,12 @@ sub cmd { $cmd->{cmd}=\&shorten; $cmd->{args}=[$arg]; background( $cmd ); + } elsif (exists $opt->{c}) { + $cmd->{cmd}=\&shorten; + $cmd->{args}=['https://scripts.irssi.org/']; + $cmd->{last}=[\&self_check]; + $self_check_timer= Irssi::timeout_add_once(2000, \&self_check, ''); + background( $cmd ); } else { $cmd->{cmd}=\&upload; $cmd->{args}=[$arg]; @@ -157,6 +167,29 @@ sub cmd { } } +sub self_check { + my ( $arg )=@_; + my $s='ok'; + my @res; + if ( ref($arg) ne 'HASH' ) { + $s = 'Error: timeout'; + } else { + @res= @{$arg->{res}}; + Irssi::timeout_remove($self_check_timer); + Irssi::print("0x0st: surl: $res[0] stat: $res[1]", MSGLEVEL_CLIENTCRAP); + if ( 2 != scalar (@res ) ) { + $s = 'Error: arg count'; + } elsif ( $res[1] != 200 ) { + $s = "Error: HTTP status code ($res[1])"; + } elsif ( $res[0] !~ m/^http/ ) { + $s = "Error: result ($res[0])"; + } + } + Irssi::print("0x0st: selfckeck $s", MSGLEVEL_CLIENTCRAP); + my $schs_version = $Irssi::Script::selfcheckhelperscript::VERSION; + Irssi::command("selfcheckhelperscript $s") if (defined $schs_version); +} + sub cmd_help { my ($args, $server, $witem)=@_; $args=~ s/\s+//g; @@ -177,6 +210,6 @@ Irssi::settings_add_str($IRSSI{name} ,$IRSSI{name}.'_base_uri', 'https://0x0.st/ Irssi::command_bind($IRSSI{name}, \&cmd); Irssi::command_bind('help', \&cmd_help); -Irssi::command_set_options($IRSSI{name},"p u s"); +Irssi::command_set_options($IRSSI{name},"p u s c"); sig_setup_changed();