From 4f3c82f9c0caf490fb54d41813a832892a04aa8f Mon Sep 17 00:00:00 2001 From: codey Date: Sat, 29 Mar 2025 06:41:03 -0400 Subject: [PATCH] do away with sing embeds globally --- cogs/sing.py | 54 ++++++++++++++++++----------------------------- util/sing_util.py | 2 +- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/cogs/sing.py b/cogs/sing.py index 7cd864b..b47e78b 100644 --- a/cogs/sing.py +++ b/cogs/sing.py @@ -91,32 +91,23 @@ class Sing(commands.Cog): short_lyrics = " ".join(search_result_wrapped_short) # Replace with shortened lyrics for non spamchans short_lyrics = regex.sub(r'\p{Vert_Space}', ' / ', short_lyrics.strip()) return await ctx.respond(f"**{search_result_song}** by **{search_result_artist}**\n-# {short_lyrics}") - embeds: list[Optional[discord.Embed]] = [] - embed_url: str = f"[on codey.lol](https://codey.lol/#{urllib.parse.quote(search_artist)}/{urllib.parse.quote(search_song)})" + c: int = 0 - footer: str = "To be continued..." #Placeholder + out_messages: list = [] + footer: str = "" # Placeholder for section in search_result_wrapped: c+=1 - if c == len(search_result_wrapped): + if c == len(search_result_wrapped): footer = f"Found on: {search_result_src}" - section = self.control_strip_regex.sub('', section) # if ctx.guild.id == 1145182936002482196: # section = section.upper() - embed: discord.Embed = discord.Embed( - title=f"{search_result_song} by {search_result_artist}", - description=discord.utils.escape_markdown(section) - ) - embed.add_field(name="Confidence", value=search_result_confidence, - inline=True) - embed.add_field(name="Time Taken", value=search_result_time_taken, - inline=True) - embed.add_field(name="Link", value=embed_url) - embed.set_footer(text=footer) - embeds.append(embed) - await ctx.respond(embed=embeds[0]) - for _embed in embeds[1:]: - if isinstance(_embed, discord.Embed): - await ctx.send(embed=_embed) + section = regex.sub(r'\p{Vert_Space}', ' / ', section.strip()) + msg: str = f"**{search_result_song}** by **{search_result_artist}**\n-# {section}\n{footer}" + if c > 1: + msg = "\n".join(msg.split("\n")[1:]) + out_messages.append(msg.strip()) + for msg in out_messages: + await ctx.send(msg) except Exception as e: traceback.print_exc() await ctx.respond(f"ERR: {str(e)}") @@ -176,27 +167,22 @@ class Sing(commands.Cog): short_lyrics = regex.sub(r'\p{Vert_Space}', ' / ', short_lyrics.strip()) return await ctx.respond(f"**{search_result_song}** by **{search_result_artist}**\n-# {short_lyrics}") - embeds: list[Optional[discord.Embed]] = [] + out_messages: list = [] + footer: str = "" c: int = 0 - footer: str = "To be continued..." #Placeholder for section in search_result_wrapped: c+=1 if c == len(search_result_wrapped): footer = f"Found on: {search_result_src}" # if ctx.guild.id == 1145182936002482196: # section = section.upper() - embed: discord.Embed = discord.Embed( - title=f"{search_result_song} by {search_result_artist}", - description=discord.utils.escape_markdown(section) - ) - embed.add_field(name="Confidence", value=search_result_confidence, inline=True) - embed.add_field(name="Time Taken", value=search_result_time_taken, inline=True) - embed.add_field(name="Link", value=f"[on codey.lol](https://codey.lol/#{urllib.parse.quote(search_result_artist)}/{urllib.parse.quote(search_result_song)})") - embed.set_footer(text=footer) - embeds.append(embed) - - for _embed in embeds: - await ctx.send(embed=_embed) + section = regex.sub(r'\p{Vert_Space}', ' / ', section.strip()) + msg: str = f"**{search_result_song}** by **{search_result_artist}**\n-# {section}\n{footer}" + if c > 1: + msg = "\n".join(msg.split("\n")[1:]) + out_messages.append(msg.strip()) + for msg in out_messages: + await ctx.send(msg) except Exception as e: traceback.print_exc() return await ctx.respond(f"ERR: {str(e)}") diff --git a/util/sing_util.py b/util/sing_util.py index 4b0ab78..834eaed 100644 --- a/util/sing_util.py +++ b/util/sing_util.py @@ -130,7 +130,7 @@ class Utility: if not lyrics: return None response_obj['lyrics'] = textwrap.wrap(text=lyrics.strip(), - width=4000, drop_whitespace=False, + width=1500, drop_whitespace=False, replace_whitespace=False, break_long_words=True, break_on_hyphens=True, max_lines=8) response_obj['lyrics_short'] = textwrap.wrap(text=lyrics.strip(),