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',
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";
$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
my $base_uri;
my %bg_process= ();
+my $self_check_timer;
sub background {
my ($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];
}
}
+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;
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();