chiark / gitweb /
mention gitweb
[irc.git] / commands.py
index 08faf54c7b0c386bee1699cef811dffef264f5c4..0075272c54d7f585291e3619217644f7744baf8c 100644 (file)
@@ -327,6 +327,7 @@ class UrlLog:
 
 #(?:) is a regexp that doesn't group        
 urlre = re.compile("((?:(?:http)|(?:nsfw))s?://[^ ]+)( |$)")
+hturlre= re.compile("(http)(s?://[^ ]+)( |$)")
 urlcomplaints = ["a contemporary","an interesting","a fascinating","an overused","a vastly overused"]
 
 ### Deal with /msg bot url or ~url in channel
@@ -395,6 +396,17 @@ def canonical_url(urlstring):
         urlstring.replace(middle,"/hi/")
   return urlstring
 
+# automatically make nsfw urls for you and pass them on to url
+def nsfwq(bot,cmd,nick,conn,public,urldb):
+  if (not hturlre.search(cmd)):
+    bot.automsg(False,nick,"Please use 'nsfw' only with http or https URLs")
+    return
+  newcmd=hturlre.sub(nsfwify,cmd)
+  urlq(bot,newcmd,nick,conn,public,urldb)
+
+def nsfwify(match):
+    a,b,c=match.groups()
+    return 'nsfw'+b+c
 
 #get tweet text
 def twitterq(bot,cmd,nick,conn,public,twitapi):