From bce1469330c5b58385c5df60a3485990906086de Mon Sep 17 00:00:00 2001 From: Zane Mattingly Date: Sat, 1 Jun 2024 17:25:50 -0700 Subject: [PATCH] Tags, Shop, and Profile Fixes (#531) * various small fixes * flip this back to debug --- charts/agimus/Chart.yaml | 4 ++-- cogs/badge_tags.py | 15 +++++++++------ cogs/profile.py | 8 ++++---- cogs/shop.py | 7 ++++--- common.py | 11 ++++++++++- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/charts/agimus/Chart.yaml b/charts/agimus/Chart.yaml index ce73f286..61fb1a9f 100644 --- a/charts/agimus/Chart.yaml +++ b/charts/agimus/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: agimus description: A helm chart for a discord bot that also runs a mysql db type: application -version: v2.9.0 -appVersion: v2.9.0 \ No newline at end of file +version: v2.9.1 +appVersion: v2.9.1 \ No newline at end of file diff --git a/cogs/badge_tags.py b/cogs/badge_tags.py index 63b8046e..5ef82314 100644 --- a/cogs/badge_tags.py +++ b/cogs/badge_tags.py @@ -167,13 +167,18 @@ async def callback(self, interaction:discord.Interaction): class TagBadgeView(discord.ui.View): - def __init__(self, cog, user_discord_id, badge_info, associated_tags): + def __init__(self, user_discord_id, badge_info, user_badge_tags, associated_tags): super().__init__() - self.cog = cog self.tag_ids = [] - self.add_item(TagSelector(user_discord_id, associated_tags)) + self.add_item(TagSelector(user_badge_tags, associated_tags)) self.add_item(TagButton(user_discord_id, badge_info)) +async def generateTagBadgeView(user_discord_id, badge_info): + user_badge_tags = await db_get_user_badge_tags(user_discord_id) + associated_tags = await db_get_associated_badge_tags(user_discord_id, badge_info['badge_filename']) + + return TagBadgeView(user_discord_id, badge_info, user_badge_tags, associated_tags) + class TagCarouselView(discord.ui.View): def __init__(self, user_discord_id, badge_info, user_badge_tags, associated_tags): @@ -462,9 +467,7 @@ async def tag(self, ctx:discord.ApplicationContext, badge:str): return badge_info = await db_get_badge_info_by_name(badge) - associated_tags = await db_get_associated_badge_tags(ctx.author.id, badge_info['badge_filename']) - - view = TagBadgeView(self, ctx.author.id, badge_info, associated_tags) + view = await generateTagBadgeView(ctx.author.id, badge_info) embed = discord.Embed( title=badge, color=discord.Color.dark_purple() diff --git a/cogs/profile.py b/cogs/profile.py index 2ee8187e..46562e45 100644 --- a/cogs/profile.py +++ b/cogs/profile.py @@ -261,8 +261,8 @@ async def display(self, ctx:discord.ApplicationContext, public:str): draw.text( (283, 80), f"USS HOOD PERSONNEL FILE #{str(member.id)[-4:]}", fill=random.choice(lcars_colors), font=level_font, align="right") draw.text( (79, 95), f"AGIMUS MAIN TERMINAL", fill="#dd4444", font=agimus_font, align="center",) draw.text( (470, 182), f"{user_name[0:32]}", fill="white", font=name_font, align="center", anchor="ms") - if user['tagline']: - draw.text( (470, 233), f"\"{user['tagline']}\"", fill="white", font=entry_font, align="center", anchor="ms") + if user['profile_tagline']: + draw.text( (470, 233), f"\"{user['profile_tagline']}\"", fill="white", font=entry_font, align="center", anchor="ms") draw.text( (578, 381), f"LEVEL: {user['level']:03d}", fill="white", font=level_font, align="right" ) title_color = random.choice(lcars_colors[1:3]) draw.text( (250, 385), f"CURRENT RANK:", fill=title_color, font=title_font, align="left") @@ -342,8 +342,8 @@ async def display(self, ctx:discord.ApplicationContext, public:str): # put polaroid on - if user["photo"] and user["photo"] != "none": - profile_photo = user['photo'].replace(" ", "_") + if user["profile_photo"] and user["profile_photo"] != "none": + profile_photo = user['profile_photo'].replace(" ", "_") photo_image = Image.open("./images/profiles/template_pieces/lcars/photo-frame.png").convert("RGBA") photo_content = Image.open(f"./images/profiles/polaroids/{profile_photo}.jpg").convert("RGBA") diff --git a/cogs/shop.py b/cogs/shop.py index 17181262..33778f22 100644 --- a/cogs/shop.py +++ b/cogs/shop.py @@ -130,12 +130,12 @@ async def get_role_pages(self, user_id: int = None): role_pages.append(card_page) return role_pages - def get_style_pages(self, user_id: int = None): + async def get_style_pages(self, user_id: int = None): """ Returns an array of ShopPages for styles """ style_pages = [] - user_styles = [s['item_name'] for s in db_get_user_profile_styles_from_inventory(user_id)] + user_styles = [s['item_name'] for s in await db_get_user_profile_styles_from_inventory(user_id)] for idx, style in enumerate(self.shop_data["styles"]): if style['name'] in user_styles: @@ -434,8 +434,9 @@ async def styles(self, ctx: discord.ApplicationContext): view = discord.ui.View() view.add_item(BuyButton(self)) + style_pages = await self.get_style_pages(ctx.user.id) paginator = pages.Paginator( - pages=self.get_style_pages(ctx.user.id), + pages=style_pages, use_default_buttons=False, custom_buttons=self.get_custom_buttons(), trigger_on_display=True, diff --git a/common.py b/common.py index 0a81d403..d3eeae01 100755 --- a/common.py +++ b/common.py @@ -175,7 +175,16 @@ def uniq_channels(config): async def get_user(discord_id:int): async with AgimusDB(dictionary=True) as query: # get user basic info - sql = "SELECT users.*, profile_photos.photo as photo, profile_taglines.tagline as tagline FROM users LEFT JOIN profile_taglines ON profile_taglines.user_discord_id = users.discord_id LEFT JOIN profile_photos ON profile_photos.user_discord_id = users.discord_id WHERE discord_id = %s" + sql = """ + SELECT + users.*,`x + profile_photos.photo AS profile_photo, + profile_taglines.tagline AS profile_tagline + FROM users + LEFT JOIN profile_taglines ON profile_taglines.user_discord_id = users.discord_id + LEFT JOIN profile_photos ON profile_photos.user_discord_id = users.discord_id + WHERE users.discord_id = %s + """ vals = (discord_id,) await query.execute(sql, vals) user_data = await query.fetchone()