]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Modernized file opening section. Corrected empty allowed list handling.
authordedeibel <redacted>
Mon, 16 Jan 2017 21:54:21 +0000 (22:54 +0100)
committerdedeibel <redacted>
Fri, 20 Jan 2017 08:43:48 +0000 (09:43 +0100)
scripts/invitejoin.pl

index f873dd5b8d9e7d51dd327e5a3f11068ea5f2c511..38205c201c4b7384b65cb44066f4a7af3c975f4b 100644 (file)
@@ -87,38 +87,29 @@ sub load_allowed_nicks {
     my ($file) = @_;
     @allowed_nicks = ();
     if (-e $file) {
-        local *F;
-        open(F, "<", $file);
+        open(my $fh, "<", $file);
         local $/ = "\n";
 
-        while (<F>) {
+        while (<$fh>) {
             chomp;
             my $new_allowed = new_allowed_nick(split("\t"));
             if (($new_allowed->{net} ne "") && ($new_allowed->{nick} ne "")) {
                 push(@allowed_nicks, $new_allowed);
             }
         }
-        close(F);
+        close($fh);
     }
 }
 
 sub save_allowed_nicks {
     my ($file) = @_;
+    open(my $fh, ">", $file) or die "Can't create $file. Reason: $!";
 
-    if (-e $file) {
-        local *F;
-        open(F, ">", $file);
-
-        for my $allowed (@allowed_nicks) {
-            print(F join("\t", $allowed->{net}, $allowed->{nick}) . "\n");
-        }
-    
-        close(F);
-    } else {
-      open(F, ">", $file) or die "Can't create $file. Reason: $!";
-      close(F);
-      save_allowed_nicks($file);
+    for my $allowed (@allowed_nicks) {
+      print($fh join("\t", $allowed->{net}, $allowed->{nick}) . "\n");
     }
+
+    close($fh);
 }
 
 sub new_allowed_nick {
@@ -205,7 +196,9 @@ sub invitejoin_runsub {
 sub is_allowed_nick {
   my ($server, $nick) = @_;
 
-  return 1 unless @allowed_nicks < 1;
+  # If no allowed nicks are specified (initial configuration) accept
+  # all invite requests, which mimics previous behavior of this script
+  return 1 if @allowed_nicks == 0;
 
   return (grep {
     $_->{net}  eq $server->{tag} &&
git clone https://git.99rst.org/PROJECT