cleanup variables in hotpath explicitly
This commit is contained in:
@@ -26,7 +26,7 @@ if (-f "/bin/wget") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $script_name = "Image URL Auto Grabber and Downloader, wget flavour";
|
my $script_name = "Image URL Auto Grabber and Downloader, wget flavour";
|
||||||
HexChat::register($script_name, '0.8.2', 'Automatically grabs and downloads image URLs via wget', \&freehooks);
|
HexChat::register($script_name, '0.8.4', 'Automatically grabs and downloads image URLs via wget', \&freehooks);
|
||||||
|
|
||||||
HexChat::print("$script_name loaded\n");
|
HexChat::print("$script_name loaded\n");
|
||||||
my @hooks;
|
my @hooks;
|
||||||
@@ -45,7 +45,15 @@ sub hookfn {
|
|||||||
foreach (@words) {
|
foreach (@words) {
|
||||||
if ($_ =~ m{https?://([a-zA-Z0-9.-]+\.[a-zA-Z]+)/(?:.*)}) {
|
if ($_ =~ m{https?://([a-zA-Z0-9.-]+\.[a-zA-Z]+)/(?:.*)}) {
|
||||||
$active = 1;
|
$active = 1;
|
||||||
threads->create(\&cdlfunc, $_)->detach;
|
my $t = undef;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$t = threads->create('cdlfunc', $_);
|
||||||
|
sleep 1 unless(defined($t));
|
||||||
|
} unless (defined($t));
|
||||||
|
|
||||||
|
$t->detach;
|
||||||
|
undef $t;
|
||||||
|
|
||||||
if ($active == 1) {
|
if ($active == 1) {
|
||||||
HexChat::hook_timer( 100, sub { return REMOVE if ($active == 0); return KEEP; } );
|
HexChat::hook_timer( 100, sub { return REMOVE if ($active == 0); return KEEP; } );
|
||||||
@@ -53,6 +61,9 @@ sub hookfn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@words = -1; undef @words;
|
||||||
|
undef $nick; undef $text; undef $modechar;
|
||||||
|
|
||||||
return HexChat::EAT_NONE;
|
return HexChat::EAT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +81,11 @@ sub cdlfunc($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dlfunc($url, $savepath);
|
dlfunc($url, $savepath);
|
||||||
|
undef $savepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
$active = 0;
|
$active = 0;
|
||||||
|
undef $url; undef $extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dlfunc(@) {
|
sub dlfunc(@) {
|
||||||
@@ -93,9 +106,11 @@ sub dlfunc(@) {
|
|||||||
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
$rename = 0 if (($format =~ /^PNG/) and ($file =~ /png$/i));
|
||||||
rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1);
|
rename $file, sprintf("%s.%s", $file, lc($format)) if ($rename == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $im; undef $rename;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
undef $url; undef $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub is_picture($) {
|
sub is_picture($) {
|
||||||
@@ -104,6 +119,11 @@ sub is_picture($) {
|
|||||||
my $r = undef;
|
my $r = undef;
|
||||||
|
|
||||||
$r = `$wgetpath --no-check-certificate -q --method=HEAD -S --timeout=5 "$url" 2>&1`;
|
$r = `$wgetpath --no-check-certificate -q --method=HEAD -S --timeout=5 "$url" 2>&1`;
|
||||||
|
undef $url;
|
||||||
|
|
||||||
|
if ($? != 0) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (split(/\n/, $r)) {
|
foreach (split(/\n/, $r)) {
|
||||||
next unless($_ =~ /Content\-Type: (.+)/);
|
next unless($_ =~ /Content\-Type: (.+)/);
|
||||||
@@ -112,14 +132,17 @@ sub is_picture($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (defined($r)) {
|
if (defined($r)) {
|
||||||
if ($r =~ /^image\/gif/) {return 'gif';};
|
if ($r =~ /^image\/gif/) { $r = 'gif'; }
|
||||||
if ($r =~ /^image\/jpe?g/){return 'jpeg';};
|
elsif ($r =~ /^image\/jpe?g/){ $r = 'jpeg';}
|
||||||
if ($r =~ /^image\/png/) {return 'png';};
|
elsif ($r =~ /^image\/png/) { $r = 'png'; }
|
||||||
if ($r =~ /^video\/webm/) {return 'webm';};
|
elsif ($r =~ /^video\/webm/) { $r = 'webm';}
|
||||||
if ($r =~ /^video\/mp4/) {return 'mp4';};
|
elsif ($r =~ /^video\/mp4/) { $r = 'mp4'; }
|
||||||
|
else { $r = undef; }
|
||||||
|
} else {
|
||||||
|
$r = undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub urlencode($) {
|
sub urlencode($) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ my $help = 'Usage:
|
|||||||
/notify show - shows whitelists and their statuses
|
/notify show - shows whitelists and their statuses
|
||||||
';
|
';
|
||||||
|
|
||||||
register($script_name, '0.7.1', 'Sends *nix desktop notifications', \&freehooks);
|
register($script_name, '0.7.2', 'Sends *nix desktop notifications', \&freehooks);
|
||||||
|
|
||||||
HexChat::print("$script_name loaded\n");
|
HexChat::print("$script_name loaded\n");
|
||||||
my @hooks;
|
my @hooks;
|
||||||
@@ -31,7 +31,7 @@ push @hooks, hook_print('Channel Message', \&hookfn);
|
|||||||
push @hooks, hook_print('Channel Msg Hilight', \&hookfn);
|
push @hooks, hook_print('Channel Msg Hilight', \&hookfn);
|
||||||
push @hooks, hook_print('Channel Action', \&hookfn);
|
push @hooks, hook_print('Channel Action', \&hookfn);
|
||||||
push @hooks, hook_print('Channel Action Hilight', \&hookfn);
|
push @hooks, hook_print('Channel Action Hilight', \&hookfn);
|
||||||
push @hooks, hook_command 'notify', \¬ify_cmd, { 'help_text' => $help };
|
push @hooks, hook_command('notify', \¬ify_cmd);
|
||||||
|
|
||||||
my $active = 0;
|
my $active = 0;
|
||||||
share($active);
|
share($active);
|
||||||
@@ -91,7 +91,7 @@ sub hookfn {
|
|||||||
my $t = undef;
|
my $t = undef;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$t = threads->create(\¬ify, $topic, $text);
|
$t = threads->create('notify', $topic, $text);
|
||||||
sleep 1 unless(defined($t));
|
sleep 1 unless(defined($t));
|
||||||
} unless (defined($t));
|
} unless (defined($t));
|
||||||
|
|
||||||
@@ -101,6 +101,11 @@ sub hookfn {
|
|||||||
hook_timer( 500, \&timeraction);
|
hook_timer( 500, \&timeraction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $nick; undef $text; undef $modechar;
|
||||||
|
undef $channel; undef $network;
|
||||||
|
undef $flag;
|
||||||
|
undef $nicklist; undef $chanlist; undef $netlist;
|
||||||
|
|
||||||
return EAT_NONE;
|
return EAT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +113,7 @@ sub notify(@) {
|
|||||||
my($topic, $text) = @_;
|
my($topic, $text) = @_;
|
||||||
system("notify-send", "-u", "normal", "-t", "12000", "-a", "hexchat", $topic, "-i", "hexchat", $text);
|
system("notify-send", "-u", "normal", "-t", "12000", "-a", "hexchat", $topic, "-i", "hexchat", $text);
|
||||||
$active = 0;
|
$active = 0;
|
||||||
|
undef $topic; undef $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub timeraction {
|
sub timeraction {
|
||||||
@@ -318,11 +324,13 @@ sub notify_cmd {
|
|||||||
sub loadliststatus($){
|
sub loadliststatus($){
|
||||||
my $listtype = shift;
|
my $listtype = shift;
|
||||||
my $list = HexChat::plugin_pref_get($listtype);
|
my $list = HexChat::plugin_pref_get($listtype);
|
||||||
|
|
||||||
unless (defined($list)) {
|
unless (defined($list)) {
|
||||||
savesetting('list', '0');
|
savesetting('list', '0');
|
||||||
$list = 0;
|
$list = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $listtype;
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,6 +343,7 @@ sub loadlist($){
|
|||||||
$val = '';
|
$val = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $setting;
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,6 +356,7 @@ sub savesetting(@) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undef $setting;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user