code cleanup, fix minor issue with loading not yet created setting
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# TODO: code cleanup
|
# TODO: a bit more code cleanup, refactor enable|disable sub-commands
|
||||||
use strict;
|
use strict;
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
use HexChat qw(:all);
|
use HexChat qw(:all);
|
||||||
@@ -10,6 +10,7 @@ sub loadlist($);
|
|||||||
sub savesetting(@);
|
sub savesetting(@);
|
||||||
sub notify(@);
|
sub notify(@);
|
||||||
sub hookfn;
|
sub hookfn;
|
||||||
|
sub freehooks;
|
||||||
sub timeraction;
|
sub timeraction;
|
||||||
sub notify_cmd;
|
sub notify_cmd;
|
||||||
|
|
||||||
@@ -23,14 +24,15 @@ my $help = 'Usage:
|
|||||||
/notify show - shows whitelists and their statuses
|
/notify show - shows whitelists and their statuses
|
||||||
';
|
';
|
||||||
|
|
||||||
register($script_name, '0.7beta', 'Sends *nix desktop notifications');
|
register($script_name, '0.7rc1', 'Sends *nix desktop notifications', \&freehooks);
|
||||||
|
|
||||||
HexChat::print("$script_name loaded\n");
|
HexChat::print("$script_name loaded\n");
|
||||||
hook_print('Channel Message', \&hookfn);
|
my @hooks;
|
||||||
hook_print('Channel Msg Hilight', \&hookfn);
|
push @hooks, hook_print('Channel Message', \&hookfn);
|
||||||
hook_print('Channel Action', \&hookfn);
|
push @hooks, hook_print('Channel Msg Hilight', \&hookfn);
|
||||||
hook_print('Channel Action Hilight', \&hookfn);
|
push @hooks, hook_print('Channel Action', \&hookfn);
|
||||||
hook_command 'notify', \¬ify_cmd, { 'help_text' => $help };
|
push @hooks, hook_print('Channel Action Hilight', \&hookfn);
|
||||||
|
push @hooks, hook_command 'notify', \¬ify_cmd, { 'help_text' => $help };
|
||||||
|
|
||||||
my $active = 0;
|
my $active = 0;
|
||||||
share($active);
|
share($active);
|
||||||
@@ -43,8 +45,6 @@ sub hookfn {
|
|||||||
$channel = '' unless(defined($channel));
|
$channel = '' unless(defined($channel));
|
||||||
$network = '' unless(defined($network));
|
$network = '' unless(defined($network));
|
||||||
|
|
||||||
HexChat::print("nick $nick; channel $channel; net $network\n");
|
|
||||||
|
|
||||||
# load settings, parse whitelists here
|
# load settings, parse whitelists here
|
||||||
my $flag = 1; # show notification
|
my $flag = 1; # show notification
|
||||||
my $nicklist = loadliststatus('nicklist');
|
my $nicklist = loadliststatus('nicklist');
|
||||||
@@ -53,19 +53,17 @@ HexChat::print("nick $nick; channel $channel; net $network\n");
|
|||||||
$flag = 0 if (($nicklist != 0) or ($chanlist != 0) or ($netlist != 0));
|
$flag = 0 if (($nicklist != 0) or ($chanlist != 0) or ($netlist != 0));
|
||||||
|
|
||||||
if ($nicklist != 0) {
|
if ($nicklist != 0) {
|
||||||
my $nicks = loadlist('nicks');
|
my @nicklist = split(/ /, loadlist('nicks'));
|
||||||
my @nicklist = split(/ /, $nicks);
|
|
||||||
|
|
||||||
foreach my $n (@nicklist) {
|
foreach (@nicklist) {
|
||||||
next unless(defined($n));
|
next unless(defined($_));
|
||||||
next if($n eq '');
|
next if($_ eq '');
|
||||||
$flag = 1 if ($n eq $nick);
|
$flag = 1 if ($_ eq $nick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($chanlist != 0) and ($flag == 0)) {
|
if (($chanlist != 0) and ($flag == 0)) {
|
||||||
my $chans = loadlist('chans');
|
my @chanlist = split(/ /, loadlist('chans'));
|
||||||
my @chanlist = split(/ /, $chans);
|
|
||||||
|
|
||||||
foreach (@chanlist) {
|
foreach (@chanlist) {
|
||||||
next unless(defined($_));
|
next unless(defined($_));
|
||||||
@@ -75,8 +73,7 @@ HexChat::print("nick $nick; channel $channel; net $network\n");
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (($netlist != 0) and ($flag == 0)) {
|
if (($netlist != 0) and ($flag == 0)) {
|
||||||
my $nets = loadlist('nets');
|
my @netlist = split(/ /, loadlist('nets'));
|
||||||
my @netlist = split(/ /, $nets);
|
|
||||||
|
|
||||||
foreach (@netlist) {
|
foreach (@netlist) {
|
||||||
next unless(defined($_));
|
next unless(defined($_));
|
||||||
@@ -162,7 +159,7 @@ sub notify_cmd {
|
|||||||
} elsif ($cmd eq 'enable') {
|
} elsif ($cmd eq 'enable') {
|
||||||
if($entity eq 'nick') {
|
if($entity eq 'nick') {
|
||||||
if (HexChat::plugin_pref_set('nicklist', '1') == 0) {
|
if (HexChat::plugin_pref_set('nicklist', '1') == 0) {
|
||||||
HexChat::print("Unable to save settings for $script_name]n");
|
HexChat::print("Unable to save settings for $script_name\n");
|
||||||
} else {
|
} else {
|
||||||
HexChat::print("Nicks whitelist now enabled\n");
|
HexChat::print("Nicks whitelist now enabled\n");
|
||||||
}
|
}
|
||||||
@@ -206,35 +203,29 @@ sub notify_cmd {
|
|||||||
} elsif ($cmd eq 'show') {
|
} elsif ($cmd eq 'show') {
|
||||||
my $str = '';
|
my $str = '';
|
||||||
|
|
||||||
my $nicklist = loadliststatus('nicklist');
|
if (loadliststatus('nicklist') == 0) {
|
||||||
if ($nicklist == 0) {
|
|
||||||
$str .= "Nicks whitelist: disabled\n";
|
$str .= "Nicks whitelist: disabled\n";
|
||||||
} else {
|
} else {
|
||||||
$str .= "Nicks whitelist: enabled\n";
|
$str .= "Nicks whitelist: enabled\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $nicks = loadlist('nicks');
|
$str .= "Whitelisted nicks = " . loadlist('nicks') ."\n";
|
||||||
$str .= "Whitelisted nicks = $nicks\n";
|
|
||||||
|
|
||||||
my $chanlist = loadliststatus('chanlist');
|
if (loadliststatus('chanlist') == 0) {
|
||||||
if ($chanlist == 0) {
|
|
||||||
$str .= "Channel whitelist: disabled\n";
|
$str .= "Channel whitelist: disabled\n";
|
||||||
} else {
|
} else {
|
||||||
$str .= "Channel whitelist: enabled\n";
|
$str .= "Channel whitelist: enabled\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $chans = loadlist('chans');
|
$str .= "Whitelisted channels = " . loadlist('chans') . "\n";
|
||||||
$str .= "Whitelisted channels = $chans\n";
|
|
||||||
|
|
||||||
my $netlist = loadliststatus('netlist');
|
if (loadliststatus('netlist') == 0) {
|
||||||
if ($netlist == 0) {
|
|
||||||
$str .= "Networks whitelist: disabled\n";
|
$str .= "Networks whitelist: disabled\n";
|
||||||
} else {
|
} else {
|
||||||
$str .= "Networks whitelist: enabled\n";
|
$str .= "Networks whitelist: enabled\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $nets = loadlist('nets');
|
$str .= "Whitelisted networks = " . loadlist('nets') . "\n";
|
||||||
$str .= "Whitelisted networks = $nets\n";
|
|
||||||
|
|
||||||
HexChat::print($str);
|
HexChat::print($str);
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
@@ -242,8 +233,7 @@ sub notify_cmd {
|
|||||||
my $str = '';
|
my $str = '';
|
||||||
if ((defined($entity)) and (defined($value))) {
|
if ((defined($entity)) and (defined($value))) {
|
||||||
if ($entity eq 'nick') {
|
if ($entity eq 'nick') {
|
||||||
my $nicks = loadlist('nicks');
|
my $nicks .= loadlist('nicks') . " $value";
|
||||||
$nicks .= " $value";
|
|
||||||
|
|
||||||
unless (defined(savesetting('nicks', $nicks))) {
|
unless (defined(savesetting('nicks', $nicks))) {
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
@@ -252,8 +242,7 @@ sub notify_cmd {
|
|||||||
HexChat::print("Nicks whitelist now: $nicks\n");
|
HexChat::print("Nicks whitelist now: $nicks\n");
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
} elsif ($entity eq 'chan') {
|
} elsif ($entity eq 'chan') {
|
||||||
my $chans = loadlist('chans');
|
my $chans .= loadlist('chans') . " $value";
|
||||||
$chans .= " $value";
|
|
||||||
|
|
||||||
unless (defined(savesetting('chans', $chans))) {
|
unless (defined(savesetting('chans', $chans))) {
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
@@ -262,8 +251,7 @@ sub notify_cmd {
|
|||||||
HexChat::print("Channels whitelist now: $chans\n");
|
HexChat::print("Channels whitelist now: $chans\n");
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
} elsif ($entity eq 'net') {
|
} elsif ($entity eq 'net') {
|
||||||
my $nets = loadlist('nets');
|
my $nets .= loadlist('nets') . " $value";
|
||||||
$nets .= " $value";
|
|
||||||
|
|
||||||
unless (defined(savesetting('nets', $nets))) {
|
unless (defined(savesetting('nets', $nets))) {
|
||||||
return HexChat::EAT_ALL;
|
return HexChat::EAT_ALL;
|
||||||
@@ -278,14 +266,13 @@ sub notify_cmd {
|
|||||||
} elsif ($cmd eq 'del') {
|
} elsif ($cmd eq 'del') {
|
||||||
if ((defined($entity)) and (defined($value))) {
|
if ((defined($entity)) and (defined($value))) {
|
||||||
if ($entity eq 'nick') {
|
if ($entity eq 'nick') {
|
||||||
my $nicks = loadlist('nicks');
|
my @nicklist = split(/ /, loadlist('nicks'));
|
||||||
my @nicklist = split(/ /, $nicks);
|
|
||||||
|
|
||||||
for (my $i = 0; $i < @nicklist; $i++) {
|
for (my $i = 0; $i < @nicklist; $i++) {
|
||||||
$nicklist[$i] = '' if ($nicklist[$i] eq $value);
|
$nicklist[$i] = '' if ($nicklist[$i] eq $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nicks = join(' ', @nicklist);
|
my $nicks = join(' ', @nicklist);
|
||||||
$nicks =~ s/ +/ /g;
|
$nicks =~ s/ +/ /g;
|
||||||
|
|
||||||
unless (defined(savesetting('nicks', $nicks))) {
|
unless (defined(savesetting('nicks', $nicks))) {
|
||||||
@@ -297,14 +284,13 @@ sub notify_cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($entity eq 'chan') {
|
if ($entity eq 'chan') {
|
||||||
my $chans = loadlist('chans');
|
my @chanlist = split(/ /, loadlist('chans'));
|
||||||
my @chanlist = split(/ /, $chans);
|
|
||||||
|
|
||||||
for (my $i = 0; $i < @chanlist; $i++) {
|
for (my $i = 0; $i < @chanlist; $i++) {
|
||||||
$chanlist[$i] = '' if ($chanlist[$i] eq $value);
|
$chanlist[$i] = '' if ($chanlist[$i] eq $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$chans = join(' ', @chanlist);
|
my $chans = join(' ', @chanlist);
|
||||||
$chans =~ s/ +/ /g;
|
$chans =~ s/ +/ /g;
|
||||||
|
|
||||||
unless (defined(savesetting('chans', $chans))) {
|
unless (defined(savesetting('chans', $chans))) {
|
||||||
@@ -316,14 +302,13 @@ sub notify_cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($entity eq 'net') {
|
if ($entity eq 'net') {
|
||||||
my $nets = loadlist('nets');
|
my @netlist = split(/ /, loadlist('nets'));
|
||||||
my @netlist = split(/ /, $nets);
|
|
||||||
|
|
||||||
for (my $i = 0; $i < @netlist; $i++) {
|
for (my $i = 0; $i < @netlist; $i++) {
|
||||||
$netlist[$i] = '' if ($netlist[$i] eq $value);
|
$netlist[$i] = '' if ($netlist[$i] eq $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nets = join(' ', @netlist);
|
my $nets = join(' ', @netlist);
|
||||||
$nets =~ s/ +/ /g;
|
$nets =~ s/ +/ /g;
|
||||||
|
|
||||||
unless (defined(savesetting('nets', $nets))) {
|
unless (defined(savesetting('nets', $nets))) {
|
||||||
@@ -358,7 +343,7 @@ sub loadlist($){
|
|||||||
my $setting = shift;
|
my $setting = shift;
|
||||||
my $val = HexChat::plugin_pref_get($setting);
|
my $val = HexChat::plugin_pref_get($setting);
|
||||||
|
|
||||||
unless (defined($setting)) {
|
unless (defined($val)) {
|
||||||
savesetting($setting, '');
|
savesetting($setting, '');
|
||||||
$val = '';
|
$val = '';
|
||||||
}
|
}
|
||||||
@@ -377,3 +362,11 @@ sub savesetting(@) {
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub freehooks {
|
||||||
|
foreach (@hooks) {
|
||||||
|
HexChat::unhook($_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return HexChat::EAT_ALL;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user