Skip to content

Commit

Permalink
Compatability update for upcoming Discord username changes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhsm committed May 4, 2023
1 parent eb179e2 commit 5d6f344
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dictator/cogs/informational.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def info(self, ctx, user: discord.User):

# User hasn't lived a single life yet
if user_info[0] == 0:
embed = discord.Embed(title=f'\'{user.name}#{user.discriminator}\' (or {user_info[2]}) has not lived any lives yet.', colour=0xffbb35)
embed = discord.Embed(title=f'\'{user.name}\' (or {user_info[2]}) has not lived any lives yet.', colour=0xffbb35)
await ctx.author.send(embed=embed)
return

Expand All @@ -52,7 +52,7 @@ async def info(self, ctx, user: discord.User):
member = ctx.guild.get_member(user.id)

# Form embed
embed = discord.Embed(title=f'Results for the user \'{user.name}#{user.discriminator}\':', colour=0xffbb35)
embed = discord.Embed(title=f'Results for the user \'{user.name}\':', colour=0xffbb35)
embed.add_field(name='Time played:', value=f'{round(user_info[0] / 60, 1)} hours')
embed.add_field(name='Blocked:', value='Yes' if user_info[1] else 'No')
embed.add_field(name='Joined guild:', value=member.joined_at.date() if member else 'Unknown')
Expand Down
16 changes: 8 additions & 8 deletions dictator/cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ async def ban(self, ctx, username, *, reason='The ban hammer has spoken.'):

username = self.username_is_player_id(username)

if not self.valid_username_format(username):
await ctx.author.send(f"Invalid username format: `{username}`")
raise commands.UserInputError
# if not self.valid_username_format(username):
# await ctx.author.send(f"Invalid username format: `{username}`")
# raise commands.UserInputError

# Check if user is already banned
with db_conn() as db:
Expand Down Expand Up @@ -62,7 +62,7 @@ async def ban(self, ctx, username, *, reason='The ban hammer has spoken.'):
# Embed log
embed = discord.Embed(title='Banned a user from the game', colour=discord.Colour.red())
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar)
embed.add_field(name='Member:', value=f'{discord_user.name}#{discord_user.discriminator}', inline=True)
embed.add_field(name='Member:', value=f'{discord_user.name}', inline=True)
embed.add_field(name='Username:', value=f'{username}', inline=True)
embed.add_field(name='Reason:', value=f'{reason}', inline=True)
embed.add_field(name='Notification:', value='Successful' if notify_user else 'Failed', inline=True)
Expand All @@ -77,9 +77,9 @@ async def unban(self, ctx, username, *, reason='It\'s your lucky day!'):

username = self.username_is_player_id(username)

if not self.valid_username_format(username):
await ctx.author.send(f"Invalid username format: `{username}`")
raise commands.UserInputError
# if not self.valid_username_format(username):
# await ctx.author.send(f"Invalid username format: `{username}`")
# raise commands.UserInputError

# Check that user is banned
with db_conn() as db:
Expand Down Expand Up @@ -119,7 +119,7 @@ async def unban(self, ctx, username, *, reason='It\'s your lucky day!'):
# Embed log
embed = discord.Embed(title='Unbanned a user from the game', colour=discord.Colour.green())
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar)
embed.add_field(name='Member:', value=f'{discord_user.name}#{discord_user.discriminator}', inline=True)
embed.add_field(name='Member:', value=f'{discord_user.name}', inline=True)
embed.add_field(name='Username:', value=f'{username}', inline=True)
embed.add_field(name='Reason:', value=f'{reason}', inline=True)
embed.add_field(name='Notification:', value='Successful' if notify_user else 'Failed', inline=True)
Expand Down
9 changes: 3 additions & 6 deletions dictator/cogs/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ async def create_user(self, user, username=None):
await user.send(f'Hey {user.mention}, you already have an account! Here is your login information:\n**Username:** {username}\n**Key:** {key}')
return

# Can't be having usernames too long, database allows for up to 255 but seriously?
if len(username) > 45:
username = username[0:45]

username += '-' + user.discriminator
if len(username) > 32:
username = username[0:32]

# Check if username is already in use
check_name = await self.search_username(username)
Expand Down Expand Up @@ -120,7 +117,7 @@ async def create_user(self, user, username=None):
embed.add_field(name='User notification:', value='Successful' if notify_user else 'Failed', inline=True)
await debug_log_channel.send(embed=embed)

print(f'Successfully created an account for {user.name}#{user.discriminator} using the username {username}.')
print(f'Successfully created an account for {user.name} using the username {username}.')

# Generate a string consisting of 20 random chars, split into 4 chunks of 5 and seperated by -
async def create_key(self):
Expand Down

0 comments on commit 5d6f344

Please sign in to comment.