Bugfixes
This commit is contained in:
parent
e453762d37
commit
f48af6fc80
1 changed files with 7 additions and 5 deletions
|
@ -29,14 +29,16 @@ async def twitter(bot: Snake, logger: Logger) -> None:
|
|||
|
||||
# Go through all actively followed accounts
|
||||
async for account in accounts:
|
||||
logger.debug(f"Checking account {account.handle}")
|
||||
# Check if account needs updated (handle changes)
|
||||
if account.last_sync + timedelta(hours=1) <= datetime.utcnow():
|
||||
logger.debug(f"Account {account.handle} out of sync, updating")
|
||||
user = api.get_user(id=account.twitter_id)
|
||||
user = api.get_user(user_id=account.twitter_id)
|
||||
account.update(q(handle=user.screen_name, last_sync=datetime.utcnow()))
|
||||
|
||||
# Get new tweets
|
||||
if tweets := api.user_timeline(id=account.twitter_id, since_id=account.last_tweet):
|
||||
if tweets := api.user_timeline(user_id=account.twitter_id, since_id=account.last_tweet):
|
||||
logger.debug(f"{account.handle} has new tweets")
|
||||
tweets = sorted(tweets, key=lambda x: x.id)
|
||||
follows = TwitterFollow.find(q(twitter_id=account.twitter_id))
|
||||
follows_to_delete = []
|
||||
|
@ -45,12 +47,12 @@ async def twitter(bot: Snake, logger: Logger) -> None:
|
|||
# Go through follows and send tweet if necessary
|
||||
async for follow in follows:
|
||||
num_follows += 1
|
||||
guild = await bot.fetch_guild(follow.guild_id)
|
||||
guild = await bot.fetch_guild(follow.guild)
|
||||
if not guild:
|
||||
logger.warning(f"Follow {follow.id}'s guild no longer exists, deleting")
|
||||
follows_to_delete.append(follow)
|
||||
continue
|
||||
channel = await guild.fetch_channel(follow.channel_id)
|
||||
channel = await bot.fetch_channel(follow.channel)
|
||||
if not channel:
|
||||
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
||||
follows_to_delete.append(follow)
|
||||
|
@ -74,7 +76,7 @@ async def twitter(bot: Snake, logger: Logger) -> None:
|
|||
if num_follows == 0:
|
||||
accounts_to_delete.append(account)
|
||||
else:
|
||||
newest = tweets[0]
|
||||
newest = tweets[-1]
|
||||
account.update(q(last_tweet=newest.id))
|
||||
await account.commit()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue