chiark / gitweb /
send tweets as UTF-8
[irc.git] / commands.py
index e6eb80cee6c728f2dbf19ab2e9a7cf04910be0ca..6049640b62fddce7749fa01f1d5b5b3c83b3099b 100644 (file)
@@ -332,7 +332,7 @@ urlcomplaints = ["a contemporary","an interesting","a fascinating","an 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)
@@ -401,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()