chiark / gitweb /
Add nsfw and nws commands
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 13 Apr 2011 14:44:26 +0000 (15:44 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Wed, 13 Apr 2011 14:44:26 +0000 (15:44 +0100)
These (nws is just an alias for nsfw for the lazy typist) are the same
as url, but do the http -> nsfw conversion for you. So you can do

/msg servus nsfw http://some.naughty.url/
and it'll paste nsfw://some.naughty.url/ into #chiark for you.

Servus-chiark.py
commands.py
servus.html

index 0af2dbce4424bc423676a1581ed22e6ba35b1bf3..ec35a7ff039bacbd071a1a9ca5c5902e93d6b333 100644 (file)
@@ -174,6 +174,8 @@ commands = {"karma": (c.karmaq,karmadb),
            "define": c.defineq,
             "google": c.googleq,
            "url": (c.urlq,urldb),
+           "nsfw": (c.nsfwq,urldb),
+           "nws": (c.nsfwq,urldb),
            "units": c.unitq,
            "help": c.helpq,
 #          "game": (c.gameq,game),
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):
index 0c842ad6d8bda263c7e8f0843acc5796aad95aeb..1a2568fc66a29dea00c4c4bc3cf0a121595b500d 100644 (file)
@@ -49,6 +49,8 @@ class="code">~command</span>. Alternatively, you may pass commands by
 <li><a href="#karmadel">karmadel</a></li>
 <li><a href="#karmalist">karmalist</a></li>
 <li><a href="#list">list</a></li>
+<li><a href="#nsfw">nsfw</a></li>
+<li><a href="nws">nws</a></li>
 <li><a href="#quiet">quiet</a></li>
 <li><a href="#quit">quit</a></li>
 <li><a href="#reload">reload</a></li>
@@ -147,6 +149,14 @@ removed from channel for excess flooding).</p>
 class="code">/msg</span>) a list of the commands Servus
 understands</p> 
 
+<h3><a name="nsfw">nsfw</a></h3>
+<p>This command is the same as <a href="#url">url</a>, only you should
+use it for URLs that are not work-safe. Servus will replace the "http"
+in your URL with "nsfw", before passing it to <a href="#url">url</a>.</p>
+
+<h3><a name="nws">nws</a></h3>
+<p>This is an alias for <a href="nsfw">nsfw</a>.</p>
+
 <h3><a name="quiet">quiet</a></h3>
 <p>This command prevents the use of <span
 class="code">trout</span>, <span class="code">flirt</span>, and <span