浏览代码

Add URL ignore functions

Morten Brix Pedersen 25 年之前
父节点
当前提交
a60226fe56
共有 1 个文件被更改,包括 18 次插入4 次删除
  1. 18 4
      modules/Pisg/Common.pm

+ 18 - 4
modules/Pisg/Common.pm

@@ -8,12 +8,12 @@ Pisg::Common - some common functions of pisg.
 
 use Exporter;
 @ISA = ('Exporter');
-@EXPORT = qw(add_alias add_aliaswild add_ignore is_ignored find_alias match_url match_email htmlentities);
+@EXPORT = qw(add_alias add_aliaswild add_ignore add_url_ignore is_ignored url_is_ignored find_alias match_url match_email htmlentities);
 
 use strict;
 $^W = 1;
 
-my (%aliases, %aliaswilds, %ignored, %aliasseen);
+my (%aliases, %aliaswilds, %ignored, %aliasseen, %ignored_urls);
 
 # add_alias assumes that the first argument is the true nick and the second is
 # the alias, but will accomidate other arrangements if necessary.
@@ -60,11 +60,25 @@ sub add_ignore
 sub is_ignored
 {
     my $nick = shift;
-    if ($ignored{$nick} || $ignored{find_alias($nick)}) {
+    if ($ignored{$nick} or $ignored{find_alias($nick)}) {
         return 1;
     }
 }
 
+sub url_is_ignored
+{
+    my $url = shift;
+    if ($ignored_urls{$url}) {
+        return 1;
+    }
+}
+
+sub add_url_ignore
+{
+    my $url = shift;
+    $ignored_urls{$url} = 1;
+}
+
 # For efficiency reasons, find_alias() caches aliases when it finds them,
 # because the regexp search through %aliaswilds is *really* expensive.
 # %aliasseen is used to mark nicks for which nothing matches--we can't add
@@ -78,7 +92,7 @@ sub find_alias
     if ($aliases{$lcnick}) {
         return $aliases{$lcnick};
     } elsif ($aliasseen{$lcnick}) {
-	return $aliasseen{$lcnick};
+        return $aliasseen{$lcnick};
     } else {
         foreach (keys %aliaswilds) {
             if ($nick =~ /^$_$/i) {