Gracefully handle channel not found errors
This commit is contained in:
parent
5ced32ca2b
commit
2eace2a405
2 changed files with 11 additions and 0 deletions
|
@ -9,6 +9,7 @@ from asyncpraw.models.reddit.submission import Submission
|
|||
from asyncpraw.models.reddit.submission import Subreddit as Sub
|
||||
from asyncprawcore.exceptions import Forbidden, NotFound
|
||||
from dis_snek import Snake
|
||||
from dis_snek.client.errors import NotFound as DNotFound
|
||||
from dis_snek.models.discord.embed import Embed
|
||||
from jarvis_core.db import q
|
||||
from jarvis_core.db.models import Subreddit, SubredditFollow
|
||||
|
@ -129,6 +130,10 @@ async def _stream(sub: Sub, bot: Snake) -> None:
|
|||
f"`r/{sub.display_name}` was posted to at <t:{timestamp}:f>",
|
||||
embeds=embeds,
|
||||
)
|
||||
except DNotFound:
|
||||
logger.warning(f"Follow {follow.id}'s channel no longer exists, deleting")
|
||||
follows_to_delete.append(follow)
|
||||
continue
|
||||
except Exception:
|
||||
logger.error(
|
||||
f"Failed to send message to {channel.id} in {channel.guild.name}", exc_info=True
|
||||
|
|
|
@ -5,6 +5,7 @@ from typing import List
|
|||
|
||||
import tweepy.asynchronous
|
||||
from dis_snek import Snake
|
||||
from dis_snek.client.errors import NotFound
|
||||
from dis_snek.models.discord.embed import Embed
|
||||
from jarvis_core.db import q
|
||||
from jarvis_core.db.models import TwitterAccount, TwitterFollow
|
||||
|
@ -135,6 +136,11 @@ class JARVISTwitterStream(AsyncStream):
|
|||
f"`@{status.user.screen_name}` {mod}tweeted this at <t:{timestamp}:f>",
|
||||
embeds=embeds,
|
||||
)
|
||||
except NotFound:
|
||||
logger.warn(f"Follow {follow.id} invalid, deleting")
|
||||
await follow.delete()
|
||||
num_follows -= 1
|
||||
continue
|
||||
except Exception:
|
||||
logger.debug(f"Failed to send message to {channel.id} in {channel.guild.name}")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue