From: Matthew Vernon Date: Wed, 13 Apr 2011 14:44:26 +0000 (+0100) Subject: Add nsfw and nws commands X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=commitdiff_plain;h=5b64cc351cc73ba65fee7fd3be1b7988802babac Add nsfw and nws commands 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. --- diff --git a/Servus-chiark.py b/Servus-chiark.py index 0af2dbc..ec35a7f 100644 --- a/Servus-chiark.py +++ b/Servus-chiark.py @@ -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), diff --git a/commands.py b/commands.py index 08faf54..0075272 100644 --- a/commands.py +++ b/commands.py @@ -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): diff --git a/servus.html b/servus.html index 0c842ad..1a2568f 100644 --- a/servus.html +++ b/servus.html @@ -49,6 +49,8 @@ class="code">~command. Alternatively, you may pass commands by
  • karmadel
  • karmalist
  • list
  • +
  • nsfw
  • +
  • nws
  • quiet
  • quit
  • reload
  • @@ -147,6 +149,14 @@ removed from channel for excess flooding).

    class="code">/msg) a list of the commands Servus understands

    +

    nsfw

    +

    This command is the same as url, 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 url.

    + +

    nws

    +

    This is an alias for nsfw.

    +

    quiet

    This command prevents the use of trout, flirt, and