X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=irc.git;a=blobdiff_plain;f=commands.py;h=6049640b62fddce7749fa01f1d5b5b3c83b3099b;hp=db8ace677d2c1a16ebb519d4fd508cdd8fc12dd3;hb=244cd25795f26cf35f7853c836f07ac1d52ff110;hpb=5fa2edeb4cd0277dbd76bd94b1bc72e057f1b610 diff --git a/commands.py b/commands.py index db8ace6..6049640 100644 --- a/commands.py +++ b/commands.py @@ -324,14 +324,15 @@ 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 def urlq(bot, cmd, nick, conn, public,urldb): if (not urlre.search(cmd)): - bot.automsg(False,nick,"Please use 'url' only with http or https URLs") + bot.automsg(False,nick,"Please use 'url' only with http, https, nsfw, or nsfws URLs") return urlstring=urlre.search(cmd).group(1) @@ -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) @@ -398,19 +401,16 @@ def twitterq(bot,cmd,nick,conn,public,twitapi): urlstring = urlre.search(cmd).group(1) if (urlstring.find("twitter.com") !=-1): stringout = getTweet(urlstring,twitapi) - try: - bot.automsg(public, nick, stringout) - except UnicodeEncodeError: - bot.automsg(public, nick, "Sorry, that tweet contained non-ASCII characters") + bot.automsg(public, nick, stringout) def getTweet(urlstring,twitapi): parts = string.split(urlstring,'/') tweetID = parts[-1] try: status = twitapi.GetStatus(tweetID) - tweeter_screen = status.user.screen_name - tweeter_name = status.user.name - tweetText = status.text + tweeter_screen = status.user.screen_name.encode('UTF-8', 'replace') + tweeter_name = status.user.name.encode('UTF-8', 'replace') + tweetText = status.text.encode('UTF-8', 'replace') stringout = "tweet by %s (%s): %s" %(tweeter_screen,tweeter_name,tweetText) except twitter.TwitterError: terror = sys.exc_info()