chiark / gitweb /
support nsfw urls
authorMatthew Vernon <matthew@debian.org>
Fri, 1 Apr 2011 21:56:40 +0000 (22:56 +0100)
committerMatthew Vernon <matthew@debian.org>
Fri, 1 Apr 2011 21:56:40 +0000 (22:56 +0100)
Servus should now understand nsfw:// and nsfws:// urls, and understand
that these are the same as the relevant http:// and https:// URL

commands.py

index db8ace6..e6eb80c 100644 (file)
@@ -324,8 +324,9 @@ class UrlLog:
     def urltype(self):
         z=min(len(urlcomplaints)-1, self.count-1)
         return urlcomplaints[z]
-        
-urlre = re.compile("(https?://[^ ]+)( |$)")
+
+#(?:) is a regexp that doesn't group        
+urlre = re.compile("((?:(?:http)|(?:nsfw))s?://[^ ]+)( |$)")
 urlcomplaints = ["a contemporary","an interesting","a fascinating","an overused","a vastly overused"]
 
 ### Deal with /msg bot url or ~url in channel
@@ -380,6 +381,8 @@ def urlexpire(urldb,expire):
 
 # canonicalise BBC URLs (internal use only)
 def canonical_url(urlstring):
+  if "nsfw://" in urlstring or "nsfws://" in urlstring:
+      urlstring=urlstring.replace("nsfw","http",1)
   if (urlstring.find("news.bbc.co.uk") != -1):
     for middle in ("/low/","/mobile/"):
       x = urlstring.find(middle)