Skip to content

Commit

Permalink
Merge pull request #68 from sopel-irc/trust-the-sign_in-method
Browse files Browse the repository at this point in the history
Trust the `sign_in()` method
  • Loading branch information
dgw authored Nov 14, 2024
2 parents 9d52f63 + da3fcc1 commit 770f5ee
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions sopel_twitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def format_tweet(tweet):
:param tweet: the tweet object, as decoded JSON
:return: the formatted tweet
:rtype: tuple
:rtype: str
"""
text = NEWLINE_RUN_REGEX.sub("\n", tweet.text)
text = text.replace("\n", " \u23CE ") # Unicode symbol to indicate line-break
Expand Down Expand Up @@ -216,12 +216,10 @@ def user_command(bot, trigger):
def output_status(bot, trigger, id_):
try:
app = Twitter(_get_tweety_session_name(bot))
# try to use saved session
app.connect()

if not app.is_user_authorized:
# existing session not present
app.sign_in(bot.settings.twitter.username, bot.settings.twitter.password)
# sign_in() checks for an existing session, and tries to use it if
# present. It will sign in with username & password if the session
# doesn't exist or is expired/invalid.
app.sign_in(bot.settings.twitter.username, bot.settings.twitter.password)

tweet = app.tweet_detail(id_)
except tweety_errors.DeniedLogin:
Expand Down Expand Up @@ -289,12 +287,10 @@ def output_status(bot, trigger, id_):
def output_user(bot, trigger, sn):
try:
app = Twitter(_get_tweety_session_name(bot))
# try to use saved session
app.connect()

if not app.is_user_authorized:
# existing session not present
app.sign_in(bot.settings.twitter.username, bot.settings.twitter.password)
# sign_in() checks for an existing session, and tries to use it if
# present. It will sign in with username & password if the session
# doesn't exist or is expired/invalid.
app.sign_in(bot.settings.twitter.username, bot.settings.twitter.password)

user = app.get_user_info(sn)
except tweety_errors.DeniedLogin:
Expand Down

0 comments on commit 770f5ee

Please sign in to comment.