]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Reformatted prints
authorJere Toivonen <redacted>
Tue, 22 Mar 2016 01:23:12 +0000 (03:23 +0200)
committerJere Toivonen <redacted>
Tue, 22 Mar 2016 01:23:12 +0000 (03:23 +0200)
scripts/replace.pl

index 5051167c2cd13c8a802b024a9a4451467eb62621..7445eabd428933d8e9b204d132c43b3fcb543959 100644 (file)
@@ -1,14 +1,15 @@
 # replace.pl - replaces a regexp with a string
 #
 # Commands:
-# REPLACE ADD <regex> - <string>
-# REPLACE DEL <regex>
+# REPLACE ADD <regexp> - <string>
+# REPLACE DEL <regexp>
 # REPLACE LIST
 # REPLACE HELP
 #
 # Example usage:
 # REPLACE ADD \S*dQw4w9WgXcQ\S* - Rick Roll
 # <@anon> Hey check out this cool video https://www.youtube.com/watch?v=dQw4w9WgXcQ
+# shows as:
 # <@anon> Hey check out this cool video Rick Roll
 #
 # Changelog:
@@ -25,18 +26,18 @@ $VERSION = '1.0';
     authors     => 'Jere Toivonen',
     contact     => 'jere@flamero.fi',
     name        => 'replace',
-    description => 'Replaces words with another words',
+    description => 'Replaces regexps with predefined strings',
     license     => 'MIT',
     url         => 'http://flamero.fi',
-    changed     => '21 March 2016',
+    changed     => '22 March 2016',
 );
 
 my %replaces;
 
 sub help_replace {
     my $help_str = 
-    "REPLACE ADD <regex> - <replace>
-REPLACE DEL <regex>
+    "REPLACE ADD <regexp> - <replace>
+REPLACE DEL <regexp>
 REPLACE LIST";
 
     Irssi::print($help_str, MSGLEVEL_CLIENTCRAP);
@@ -48,7 +49,7 @@ sub add_replace {
 
     $replaces{$new_key} = $new_replace;
 
-    Irssi::print("Added replace: $new_key  -  $new_replace", MSGLEVEL_CLIENTCRAP);
+    Irssi::print("Added replace: $new_key - $new_replace", MSGLEVEL_CLIENTCRAP);
 }
 
 sub list_replace {
@@ -56,15 +57,20 @@ sub list_replace {
 
     Irssi::print("List of replaces:", MSGLEVEL_CLIENTCRAP);
     foreach my $key (keys %replaces) {
-        Irssi::print("$key  - $replaces{$key}", MSGLEVEL_CLIENTCRAP);
+        Irssi::print("$key - $replaces{$key}", MSGLEVEL_CLIENTCRAP);
     }
 }
 
 sub del_replace {
     my ($data, $server, $witem) = @_;
 
+    if (!%replaces) {
+        Irssi::print("No replaces to delete", MSGLEVEL_CLIENTCRAP);
+        return;
+    }
+
     foreach my $key (keys %replaces) {
-        if($data eq $key) {
+        if ($data eq $key) {
             Irssi::print("Deleted replace $key - $replaces{$key}", MSGLEVEL_CLIENTCRAP);
             delete $replaces{$key};
         } else {
@@ -94,7 +100,7 @@ Irssi::command_bind('replace add',\&add_replace);
 Irssi::command_bind('replace delete',\&del_replace);
 Irssi::command_bind('replace list',\&list_replace);
 Irssi::command_bind 'replace' => sub {
-        my ($data, $server, $witem) = @_;
-        $data =~ s/\s+$//g;
-        Irssi::command_runsub('replace', $data, $server, $witem);
+    my ($data, $server, $witem) = @_;
+    $data =~ s/\s+$//g;
+    Irssi::command_runsub('replace', $data, $server, $witem);
 }
git clone https://git.99rst.org/PROJECT