Skip to content

Commit

Permalink
modified: cogs/user.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Revulate committed Oct 12, 2024
1 parent 14925d4 commit 65b4ad1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cogs/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def format_account_age(self, created_at):
age_str = ", ".join(age_parts)
return f"{age_str} ago (Created on {created_at.strftime('%Y-%m-%d')})"

async def get_ban_info(self, channel_id, user_id):
"""Fetch ban information for a user in a specific channel."""
async def get_ban_info(self, broadcaster_id, user_id):
"""Fetch ban information for a user in a specific broadcaster's channel."""
try:
bans = await self.bot.fetch_channel_bans(channel_id, user_ids=[user_id])
bans = await self.bot.fetch_channel_bans(broadcaster_id, user_ids=[user_id])
return bans[0] if bans else None
except Exception as e:
self.bot.logger.error(f"Error fetching ban info: {e}")
Expand All @@ -56,6 +56,7 @@ async def user_command(self, ctx: commands.Context, username: str = None):
username = ctx.author.name

try:
# Fetch the target user's information
users = await self.bot.fetch_users(names=[username])
if not users:
await ctx.send(f"@{ctx.author.name}, no user found with the name '{username}'.")
Expand All @@ -65,8 +66,18 @@ async def user_command(self, ctx: commands.Context, username: str = None):
broadcaster_type = self.format_enum(user.broadcaster_type)
account_age = self.format_account_age(user.created_at)

# Fetch the broadcaster's user ID
broadcaster_name = ctx.channel.name
broadcasters = await self.bot.fetch_users(names=[broadcaster_name])
if not broadcasters:
await ctx.send(f"@{ctx.author.name}, could not fetch broadcaster information.")
return

broadcaster = broadcasters[0]
broadcaster_id = broadcaster.id

# Fetch ban information
ban_info = await self.get_ban_info(ctx.channel.id, user.id)
ban_info = await self.get_ban_info(broadcaster_id, user.id)

response = (
f"@{ctx.author.name}, User info for {user.display_name} (twitch.tv/{user.name}): "
Expand All @@ -82,10 +93,12 @@ async def user_command(self, ctx: commands.Context, username: str = None):
expiry = (
f" until {ban_info.expires_at.strftime('%Y-%m-%d %H:%M:%S UTC')}" if ban_info.expires_at else ""
)
banned_by = ban_info.moderator.name if ban_info.moderator else "Unknown"

response += (
f" | {ban_type} in this channel{expiry} | "
f"Reason: {ban_info.reason or 'No reason provided'} | "
f"Banned by: {ban_info.moderator.name}"
f"Banned by: {banned_by}"
)

await ctx.send(response)
Expand Down

0 comments on commit 65b4ad1

Please sign in to comment.