From 5320eae4891c0bb3825484e33c311ea7c4e67cc6 Mon Sep 17 00:00:00 2001 From: Peter of the Norse Date: Wed, 31 Jan 2024 10:41:27 -0700 Subject: [PATCH] Switch to filtering on cp1252 so that western accented characters will work in images --- charts/agimus/Chart.yaml | 4 ++-- cogs/badge_tags.py | 2 +- cogs/profile.py | 4 +--- commands/badges.py | 12 ++++++------ commands/userinfo.py | 2 +- common.py | 6 ++++++ 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/charts/agimus/Chart.yaml b/charts/agimus/Chart.yaml index fd1699ee..4ca0a499 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.4.3 -appVersion: v2.4.3 \ No newline at end of file +version: v2.4.4 +appVersion: v2.4.4 \ No newline at end of file diff --git a/cogs/badge_tags.py b/cogs/badge_tags.py index 1ff480be..036a8ae3 100644 --- a/cogs/badge_tags.py +++ b/cogs/badge_tags.py @@ -538,7 +538,7 @@ async def showcase(self, ctx:discord.ApplicationContext, public:str, tag:str): await ctx.defer(ephemeral=not public) # Set up text values for paginated pages - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Tagged Badges - {tag}" + title = f"{remove_emoji(ctx.author.display_name)}'s Tagged Badges - {tag}" total_badges_cnt = len(all_badge_info) tagged_badges_cnt = len(tagged_badges) collected = f"{tagged_badges_cnt} TAGGED ON THE USS HOOD" diff --git a/cogs/profile.py b/cogs/profile.py index 2a327c3b..6ee93c93 100644 --- a/cogs/profile.py +++ b/cogs/profile.py @@ -130,9 +130,7 @@ async def display(self, ctx:discord.ApplicationContext, public:str): logger.info(f"{Fore.CYAN}{member.display_name} is looking at their own {Back.WHITE}{Fore.BLACK}profile card!{Back.RESET}{Fore.RESET}") # clean up username - user_name = f"{member.display_name}" - user_name_encode = user_name.encode("utf-8", errors="ignore") - user_name = user_name_encode.decode().strip() + user_name = remove_emoji(member.display_name) # get rank ranks = ["admiral", "captain", "commander", "lt. commander", "lieutenant", "ensign", "cadet"] diff --git a/commands/badges.py b/commands/badges.py index fed5b2b3..a4f99604 100644 --- a/commands/badges.py +++ b/commands/badges.py @@ -117,16 +117,16 @@ async def showcase(ctx:discord.ApplicationContext, public:str, filter:str, sortb if filter is not None: if filter == 'unlocked': - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Collection - Unlocked" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Collection - Unlocked" user_badges = db_get_user_unlocked_badges(ctx.author.id) elif filter == 'locked': - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Collection - Locked" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Collection - Locked" user_badges = db_get_user_locked_badges(ctx.author.id) elif filter == 'special': - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Collection - Special" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Collection - Special" user_badges = db_get_user_special_badges(ctx.author.id) else: - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Collection" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Collection" user_badges = db_get_user_badges(ctx.author.id, sortby) if not user_badges: @@ -316,7 +316,7 @@ async def sets(ctx:discord.ApplicationContext, public:str, category:str, selecti user_all_badge_cnt = db_get_badge_count_for_user(ctx.author.id) # Set up text values for paginated pages - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Set: {category_title} - {selection}" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Set: {category_title} - {selection}" collected = f"{user_set_badge_cnt} OF {len(set_badges)}" filename_prefix = f"badge_set_{ctx.author.id}_{selection.lower().replace(' ', '-').replace('/', '-')}-page-" @@ -446,7 +446,7 @@ async def completion(ctx:discord.ApplicationContext, public:str, category:str, c # Format data for the returned embed category_title = category.replace('_', ' ').title() total_badges = len(all_badges) - title = f"{ctx.author.display_name.encode('ascii', errors='ignore').decode().strip()}'s Badge Completion - {category_title}" + title = f"{remove_emoji(ctx.author.display_name)}'s Badge Completion - {category_title}" collected = f"{len(user_badges)} TOTAL ON THE USS HOOD" filename_prefix = f"badge_set_completion_{ctx.author.id}_affiliations-page-" diff --git a/commands/userinfo.py b/commands/userinfo.py index e56947ed..0128c1dd 100644 --- a/commands/userinfo.py +++ b/commands/userinfo.py @@ -100,7 +100,7 @@ async def top_channels(ctx:discord.ApplicationContext, public:str): @to_thread def generate_user_stats_top_channels_image(ctx, user_member, labels, values): user_discord_id = user_member.id - user_name = user_member.display_name.encode("ascii", errors="ignore").decode().strip() + user_name = remove_emoji(user_member.display_name) fig_filename = f"fig-u{user_discord_id}-t{int(time.time())}.png" fig_filepath = f"./images/viz/figs/{fig_filename}" diff --git a/common.py b/common.py index 5cc91aa9..095a6ab7 100755 --- a/common.py +++ b/common.py @@ -427,3 +427,9 @@ def print_agimus_ansi_art(): with open(f"data/ansi/{ansi_file}") as f: agimus_ansi = f.readlines() logger.info(''.join(agimus_ansi)) + +def remove_emoji(s: str) -> str: + """ + Cleans out values unprintable in our font. cp1252 because there are a handful of chars in the font not in latin_1 + """ + return s.replace("€", '').encode("cp1252", errors="ignore").decode("cp1252").strip()