Closes #11
This commit is contained in:
@@ -18,6 +18,7 @@ from classes.errors import (
|
||||
EventStageMissingSequenceError,
|
||||
EventStageNotFoundError,
|
||||
GuildNotFoundError,
|
||||
DiscordGuildMemberNotFoundError,
|
||||
)
|
||||
from modules.database import col_events, col_users
|
||||
from modules.utils import get_logger
|
||||
@@ -118,9 +119,25 @@ class PycordBot(LibPycordBot):
|
||||
await user._set(self.cache, current_event_id=event._id, current_stage_id=first_stage._id)
|
||||
|
||||
# Create a channel for each participant
|
||||
user_channel: TextChannel | None = await user.setup_event_channel(
|
||||
self, guild, pycord_guild, event, cache=self.cache
|
||||
)
|
||||
try:
|
||||
user_channel: TextChannel | None = await user.setup_event_channel(
|
||||
self, guild, pycord_guild, event, cache=self.cache
|
||||
)
|
||||
except DiscordGuildMemberNotFoundError:
|
||||
logger.error(
|
||||
"Could not create and configure event channel for user %s in %s (event %s): user not found in the guild",
|
||||
user.id,
|
||||
guild.id,
|
||||
event._id,
|
||||
)
|
||||
|
||||
await self.notify_admins(
|
||||
guild,
|
||||
pycord_guild,
|
||||
f"Event channel could not be created for user with ID `{user.id}` (<@{user.id}>) and event **{event.name}**: user was not found on the server.",
|
||||
)
|
||||
|
||||
continue
|
||||
|
||||
if user_channel is None:
|
||||
logger.error(
|
||||
@@ -374,3 +391,25 @@ class PycordBot(LibPycordBot):
|
||||
processed_attachments.append({"id": attachment.id, "filename": attachment.filename})
|
||||
|
||||
return processed_attachments
|
||||
|
||||
# TODO Add documentation
|
||||
async def send_stage_question(
|
||||
self,
|
||||
channel: TextChannel,
|
||||
event: PycordEvent,
|
||||
stage: Optional[PycordEventStage] = None,
|
||||
use_first_stage: bool = False,
|
||||
) -> None:
|
||||
stage: PycordEventStage = (
|
||||
stage
|
||||
if not use_first_stage or stage is not None
|
||||
else await self.find_event_stage(event.stage_ids[0])
|
||||
)
|
||||
|
||||
stage_files: List[File] | None = stage.get_media_files()
|
||||
|
||||
question_chunks: List[str] = stage.get_question_chunked(2000)
|
||||
question_chunks_length: int = len(question_chunks)
|
||||
|
||||
for index, chunk in enumerate(question_chunks):
|
||||
await channel.send(chunk, files=None if index != question_chunks_length - 1 else stage_files)
|
||||
|
@@ -275,9 +275,10 @@ class PycordUser:
|
||||
guild: Guild,
|
||||
pycord_guild: "PycordGuild",
|
||||
pycord_event: "PycordEvent",
|
||||
ignore_exists: bool = False,
|
||||
cache: Optional[Cache] = None,
|
||||
) -> TextChannel | None:
|
||||
if str(pycord_event._id) in self.event_channels.keys():
|
||||
if not ignore_exists and str(pycord_event._id) in self.event_channels.keys():
|
||||
return None
|
||||
|
||||
discord_member: Member | None = guild.get_member(self.id)
|
||||
@@ -314,6 +315,43 @@ class PycordUser:
|
||||
|
||||
return channel
|
||||
|
||||
# TODO Add documentation
|
||||
async def fix_event_channel(
|
||||
self,
|
||||
bot: Bot,
|
||||
guild: Guild,
|
||||
pycord_guild: "PycordGuild",
|
||||
pycord_event: "PycordEvent",
|
||||
cache: Optional[Cache] = None,
|
||||
) -> TextChannel | None:
|
||||
# Configure channel if not set
|
||||
if str(pycord_event._id) not in self.event_channels.keys():
|
||||
return await self.setup_event_channel(bot, guild, pycord_guild, pycord_event, cache=cache)
|
||||
|
||||
discord_member: Member | None = guild.get_member(self.id)
|
||||
|
||||
if discord_member is None:
|
||||
raise DiscordGuildMemberNotFoundError(self.id, guild.id)
|
||||
|
||||
channel: TextChannel = guild.get_channel(self.event_channels[str(pycord_event._id)])
|
||||
|
||||
if channel is None:
|
||||
return await self.setup_event_channel(
|
||||
bot, guild, pycord_guild, pycord_event, ignore_exists=True, cache=cache
|
||||
)
|
||||
|
||||
await channel.set_permissions(
|
||||
discord_member,
|
||||
overwrite=PermissionOverwrite(
|
||||
view_channel=True,
|
||||
send_messages=True,
|
||||
use_application_commands=True,
|
||||
),
|
||||
reason=f"Updated event channel of {self.id} for event {pycord_event._id}",
|
||||
)
|
||||
|
||||
return channel
|
||||
|
||||
# TODO Add documentation
|
||||
async def lock_event_channel(
|
||||
self,
|
||||
|
Reference in New Issue
Block a user