From e885b1351b613808ac04a889a4e95a2d44a43a4a Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:11:11 +0530 Subject: [PATCH 1/2] Fix a tiny typo in a path name --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index b500905..e0c2dd7 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ # Check for Databases and Autogenerate them if not os.path.isdir("db"): os.mkdir("db") -if not os.path.isfile("db/profile.json"): +if not os.path.isfile("db/profiles.json"): with open("db/profiles.json", 'x', encoding="utf-8") as f: json.dump({}, f) if not os.path.isfile("db/user_ratings.json"): with open("db/user_ratings.json", 'x', encoding="utf-8") as f: json.dump({}, f) From 8e92f77da882eb25853b60bd309f74278a05edf2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:43:35 +0530 Subject: [PATCH 2/2] Add support for custom user profile banners in `/profile` --- main.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e0c2dd7..ac12068 100644 --- a/main.py +++ b/main.py @@ -27,7 +27,7 @@ # Pre-initialization Commands def save() -> int: with open("db/user_ratings.json", 'w+') as f: json.dump(user_ratings, f, indent=4) - # with open("db/profiles.json", 'w+') as f: json.dump(profile_metadata, f, indent=4) TODO: Uncomment this line once full profile metadata support is ready + with open("db/profiles.json", 'w+') as f: json.dump(profile_metadata, f, indent=4) # TODO: Uncomment this line once full profile metadata support is ready return 0 def parse_rating(user_id: Union[int, str]) -> int: @@ -54,6 +54,7 @@ async def on_ready(): @client.event async def on_message(ctx): if str(ctx.author.id) not in user_ratings: user_ratings[str(ctx.author.id)] = {} + if str(ctx.author.id) not in profile_metadata: profile_metadata[str(ctx.author.id)] = {"profile_banner_url": None} save() # Slash Commands @@ -112,7 +113,8 @@ async def profile(ctx: ApplicationContext, user: discord.User = None): localembed.add_field(name="Joined Discord at", value=f"{user.created_at.strftime('%d %B, %Y')}") localembed.add_field(name="User id", value=user.id) localembed.add_field(name="Rating", value=f"{str(parse_rating(user.id))} stars") - # localembed.set_image(url=) TODO: Make profile metadata database, then activate this property + if profile_metadata[str(user.id)]["profile_banner_url"] is not None: + localembed.set_image(url=profile_metadata[str(user.id)]["profile_banner_url"]) await ctx.respond(embed=localembed) @client.slash_command( @@ -128,6 +130,23 @@ async def rating(ctx: ApplicationContext, user: discord.User = None): ) await ctx.respond(embed=localembed) +# User Profile Customization Commands +# customization = discord.commands.SlashCommandGroup("customize", "Commands used to customize the user's /profile command.") Disable because command doesn't sync with this + +@client.slash_command( + name="profile_banner", + description="Set a banner to display on your /profile command! (url only)" +) +@option(name="image_url", description="The url of your new profile banner (leave blank to disable)", type=str, default=None) +async def banner(ctx: ApplicationContext, image_url: str = None): + """Set a banner to display on your /profile command! (url only)""" + if (image_url is not None) and ("https://" not in image_url): + return await ctx.respond("Your custom banner url must contain `https://`!", ephemeral=True) + profile_metadata[str(ctx.author.id)]["profile_banner_url"] = image_url + if image_url is None: localembed = discord.Embed(description=":white_check_mark: Your custom profile banner has been successfully removed.", color=discord.Color.green()) + else: localembed = discord.Embed(description=":white_check_mark: Your custom profile banner has been successfully set! Check it out using `/profile`.", color=discord.Color.green()) + return await ctx.respond(embed=localembed) + # User Commands @client.user_command(name="View Profile") async def _profile(ctx: ApplicationContext, user: discord.User): @@ -141,7 +160,8 @@ async def _profile(ctx: ApplicationContext, user: discord.User): localembed.add_field(name="Joined Discord at", value=f"{user.created_at.strftime('%d %B, %Y')}") localembed.add_field(name="User id", value=user.id) localembed.add_field(name="Rating", value=f"{str(parse_rating(user.id))} stars") - # localembed.set_image(url=) TODO: Make profile metadata database, then activate this property + if profile_metadata[str(user.id)]["profile_banner_url"] is not None: + localembed.set_image(url=profile_metadata[str(user.id)]["profile_banner_url"]) await ctx.respond(embed=localembed) @client.user_command(name="View Rating")