]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
[0x0st] v0.04
authorbw1 <redacted>
Wed, 13 Jan 2021 16:18:42 +0000 (17:18 +0100)
committerbw1 <redacted>
Sun, 24 Jan 2021 21:27:31 +0000 (22:27 +0100)
+ selfcheck

scripts/0x0st.pl

index 30dcf329eebc02f9153fa4302b32f2082be1b7e4..95c7d963954d8b425a6dd3a26f3e872dc91a72bb 100644 (file)
@@ -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 <URL> | -u <URL> | 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();
git clone https://git.99rst.org/PROJECT