Skip to content

Commit

Permalink
added reason to blocing and post in staff channel
Browse files Browse the repository at this point in the history
  • Loading branch information
99oblivius committed Jul 23, 2024
1 parent 4cc21c3 commit 84ae0c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/cogs/queues/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ async def on_ready(self):
@nextcord.slash_command(name="block", description="Block a user from queuing", guild_ids=[GUILD_ID])
async def block_from_queue(self, interaction: nextcord.Interaction,
user: nextcord.Member | nextcord.User,
reason: str = nextcord.SlashOption(required=True),
period: str = nextcord.SlashOption(
name="period",
description="Time period (format: 0w0d0h0m)",
required=False,
default="-1")
):
if len(reason) > 1024:
return await interaction.response.send_message("Invalid reason. Reason, too long. Try and keep it bellow 1024 characters.", ephemeral=True)
now = datetime.now(timezone.utc)
period_match = re.match(r"(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?", period)
if period == "-1":
Expand All @@ -73,9 +76,17 @@ async def block_from_queue(self, interaction: nextcord.Interaction,
if user.id in (u.user_id for u in blocked_users):
description = "Updated "

await self.bot.store.set_user_block(interaction.guild.id, user.id, expiration, interaction.user.id)
await self.bot.store.set_user_block(interaction.guild.id, user.id, expiration, reason, interaction.user.id)
self.bot.queue_manager.remove_user(user.id)
await self.bot.store.unqueue_user_guild(interaction.guild.id, user.id)
settings = await self.bot.store.get_settings(interaction.guild.id)
staff_channel = interaction.guild.get_channel(settings.staff_channel)
if staff_channel:
embed = nextcord.Embed(
title="Match Making",
description=f"{user.mention} was blocked from participating in match making for```{reason}```",
color=VALORS_THEME1_1)
await staff_channel.send(embed=embed)

log.debug(f"{interaction.user.display_name} blocked {user.display_name} from queueing for {period}")
stamp = int(expiration.timestamp())
Expand Down
6 changes: 3 additions & 3 deletions src/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ async def get_user_blocks(self, guild_id: int) -> List[MMBotBlockedUsers]:
return result.scalars().all()

@log_db_operation
async def set_user_block(self, guild_id: int, user_id: int, expiration: datetime, blocked_by: int):
async def set_user_block(self, guild_id: int, user_id: int, expiration: datetime, reason: str, blocked_by: int):
async with self._session_maker() as session:
now = datetime.now(timezone.utc)
existing_block = await session.execute(
Expand All @@ -472,11 +472,11 @@ async def set_user_block(self, guild_id: int, user_id: int, expiration: datetime
.where(
MMBotBlockedUsers.guild_id == guild_id,
MMBotBlockedUsers.user_id == user_id)
.values(expiration=expiration, blocked_by=blocked_by))
.values(reason=reason, expiration=expiration, blocked_by=blocked_by))
else:
await session.execute(
insert(MMBotBlockedUsers)
.values(guild_id=guild_id, user_id=user_id, expiration=expiration, blocked_by=blocked_by))
.values(guild_id=guild_id, user_id=user_id, expiration=expiration, reason=reason, blocked_by=blocked_by))
await session.commit()


Expand Down
1 change: 1 addition & 0 deletions src/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class MMBotBlockedUsers(Base):
guild_id = Column(BigInteger, nullable=False)
user_id = Column(BigInteger, nullable=False)
blocked_by = Column(BigInteger, nullable=False)
reason = Column(Text)
expiration = Column(TIMESTAMP(timezone=True), server_default=func.now())

__table_args__ = (
Expand Down

0 comments on commit 84ae0c7

Please sign in to comment.