Validate all follows before starting streams

This commit is contained in:
Zeva Rose 2022-04-21 10:23:15 -06:00
parent 3d091a7cb4
commit 4157989040
2 changed files with 38 additions and 0 deletions

View file

@ -164,6 +164,25 @@ async def reddit(bot: Snake) -> None:
logger.debug("Starting Task-reddit")
red = Reddit(**config.reddit)
logger.debug("Validating follows")
async for sub in Subreddit.find():
count = 0
async for follow in SubredditFollow.find(q(display_name=sub.display_name)):
count += 1
guild = await bot.fetch_guild(follow.guild)
channel = await bot.fetch_channel(follow.channel)
if not guild or not channel:
logger.debug(f"Follow {follow.id} no longer valid, deleting")
await follow.delete()
count -= 1
continue
if count == 0:
logger.debug(f"Subreddit {sub.display_name} has no followers, removing")
await sub.delete()
while True:
subs = Subreddit.find(q(display_name__nin=running))

View file

@ -166,6 +166,25 @@ async def twitter(bot: Snake) -> None:
auth = tweepy.AppAuthHandler(config.twitter["consumer_key"], config.twitter["consumer_secret"])
api = tweepy.API(auth)
logger.debug("Starting Task-twitter")
logger.debug("Validating follows")
async for account in TwitterAccount.find():
count = 0
async for follow in TwitterFollow.find(q(twitter_id=account.twitter_id)):
count += 1
guild = await bot.fetch_guild(follow.guild)
channel = await bot.fetch_channel(follow.channel)
if not guild or not channel:
logger.debug(f"Follow {follow.id} invalid, deleting")
await follow.delete()
count -= 1
continue
if count == 0:
logger.debug(f"Account {account.handle} has no followers, removing")
await account.delete()
while True:
accounts = TwitterAccount.find()