Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore Non-Messageable Channels #879

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions ClemBot.Bot/bot/services/emote_board_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"***GOD-TIER***",
]

VALID_CHANNEL_TYPES = (
discord.Thread,
discord.TextChannel,
discord.VoiceChannel,
discord.StageChannel,
)


class EmoteBoardService(BaseService):
"""
Expand Down Expand Up @@ -58,7 +65,10 @@ async def on_reaction_add(self, event: RawReactionActionEvent) -> None:
assert guild is not None

channel = guild.get_channel_or_thread(event.channel_id)
assert channel is not None and isinstance(channel, discord.abc.Messageable)
assert channel is not None

if not isinstance(channel, VALID_CHANNEL_TYPES):
return

message = await channel.fetch_message(event.message_id)

Expand Down Expand Up @@ -116,7 +126,10 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
assert guild is not None

channel = guild.get_channel_or_thread(event.channel_id)
assert channel is not None and isinstance(channel, discord.abc.Messageable)
assert channel is not None

if not isinstance(channel, VALID_CHANNEL_TYPES):
return

# Attempt to fetch the message, ignore if we do not have permissions.
message: discord.Message
Expand Down Expand Up @@ -153,7 +166,7 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
embed_msg = await channel.fetch_message(message_id)
embed = await self._as_embed(
message,
Expand Down Expand Up @@ -181,7 +194,7 @@ async def on_message_delete(self, event: RawMessageDeleteEvent) -> None:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
embed_msg = await channel.fetch_message(message_id)
await embed_msg.delete()
except NotFound: # Skips over the item if fetch_message() raises `NotFound`
Expand Down Expand Up @@ -217,7 +230,7 @@ async def _create_post(
for channel_id in board.channels:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue
assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
message = await channel.send(embed=embed)
post.channel_message_ids[channel_id] = message.id

Expand Down Expand Up @@ -252,7 +265,7 @@ async def _update_post(
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

if not isinstance(channel, discord.abc.Messageable):
if not isinstance(channel, VALID_CHANNEL_TYPES):
continue

embed_msg = await channel.fetch_message(message_id)
Expand Down
Loading