Skip to content

Commit

Permalink
Merge pull request CloudBotIRC#211 from gzorro20/gonzobot
Browse files Browse the repository at this point in the history
added html unescaping for tweet text
  • Loading branch information
edwardslabs authored Nov 14, 2017
2 parents 0c6c16b + c385195 commit 4883280
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions plugins/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import tweepy
from cloudbot import hook

import html

from cloudbot.util import timeformat

TWITTER_RE = re.compile(r"(?:(?:www.twitter.com|twitter.com)/(?:[-_a-zA-Z0-9]+)/status/)([0-9]+)", re.I)
Expand Down Expand Up @@ -45,17 +47,7 @@ def twitter_url(match):
except tweepy.error.TweepError:
return

# Format the return the text of the tweet
text = " ".join(tweet.text.split())

if user.verified:
prefix = "\u2713"
else:
prefix = ""

time = timeformat.time_since(tweet.created_at, datetime.utcnow())

return "{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, text, time)
return format_tweet(tweet, user)


@hook.command("twitter", "tw", "twatter")
Expand Down Expand Up @@ -128,7 +120,11 @@ def twitter(text):
# ???
return "Invalid Input"

# Format the return the text of the tweet
return format_tweet(tweet, user)


# Format the return the text of the tweet
def format_tweet(tweet, user):
text = " ".join(tweet.text.split())

if user.verified:
Expand All @@ -138,7 +134,7 @@ def twitter(text):

time = timeformat.time_since(tweet.created_at, datetime.utcnow())

return "{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, text, time)
return "{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, html.unescape(text), time)


@hook.command("twuser", "twinfo")
Expand Down

0 comments on commit 4883280

Please sign in to comment.