Change how/when invalid reddit follows are deleted
This commit is contained in:
parent
da2445f04f
commit
3d091a7cb4
1 changed files with 7 additions and 8 deletions
|
@ -106,21 +106,23 @@ async def _stream(sub: Sub, bot: Snake) -> None:
|
||||||
continue
|
continue
|
||||||
logger.debug(f"Got new post in {sub.display_name}")
|
logger.debug(f"Got new post in {sub.display_name}")
|
||||||
follows = SubredditFollow.find(q(display_name=sub.display_name))
|
follows = SubredditFollow.find(q(display_name=sub.display_name))
|
||||||
follows_to_delete = []
|
|
||||||
num_follows = 0
|
num_follows = 0
|
||||||
|
|
||||||
async for follow in follows:
|
async for follow in follows:
|
||||||
num_follows += 1
|
num_follows += 1
|
||||||
|
|
||||||
guild = await bot.fetch_guild(follow.guild)
|
guild = await bot.fetch_guild(follow.guild)
|
||||||
if not guild:
|
if not guild:
|
||||||
logger.warning(f"Follow {follow.id}'s guild no longer exists, deleting")
|
logger.warning(f"Follow {follow.id}'s guild no longer exists, deleting")
|
||||||
follows_to_delete.append(follow)
|
await follow.delete()
|
||||||
|
num_follows -= 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
channel = await bot.fetch_channel(follow.channel)
|
channel = await bot.fetch_channel(follow.channel)
|
||||||
if not channel:
|
if not channel:
|
||||||
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
||||||
follows_to_delete.append(follow)
|
await follow.delete()
|
||||||
|
num_follows -= 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
embeds = await post_embeds(sub, post)
|
embeds = await post_embeds(sub, post)
|
||||||
|
@ -133,17 +135,14 @@ async def _stream(sub: Sub, bot: Snake) -> None:
|
||||||
)
|
)
|
||||||
except DNotFound:
|
except DNotFound:
|
||||||
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
||||||
follows_to_delete.append(follow)
|
await follow.delete()
|
||||||
|
num_follows -= 1
|
||||||
continue
|
continue
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Failed to send message to {channel.id} in {channel.guild.name}", exc_info=True
|
f"Failed to send message to {channel.id} in {channel.guild.name}", exc_info=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Delete invalid follows
|
|
||||||
for follow in follows_to_delete:
|
|
||||||
await follow.delete()
|
|
||||||
|
|
||||||
if num_follows == 0:
|
if num_follows == 0:
|
||||||
s = await Subreddit.find_one(q(display_name=sub.display_name))
|
s = await Subreddit.find_one(q(display_name=sub.display_name))
|
||||||
if s:
|
if s:
|
||||||
|
|
Loading…
Add table
Reference in a new issue