From c2ccdb71d64791efaf943bbe7a8a855eff9556f4 Mon Sep 17 00:00:00 2001 From: ZRunner Date: Wed, 2 Oct 2024 22:27:05 +0200 Subject: [PATCH] fix(discord-jobs): fields too long --- modules/fun/fun.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/fun/fun.py b/modules/fun/fun.py index 1d132d162..06c27e26a 100644 --- a/modules/fun/fun.py +++ b/modules/fun/fun.py @@ -494,10 +494,16 @@ async def discord_jobs(self, interaction: discord.Interaction, query: str | None ) ] desc = await self.bot._(interaction, "fun.discordjobs.filtered-count", count=len(jobs)) - formatted_jobs = [ - f"[{x['title'] if len(x['title'])<50 else x['title'][:49]+'…'}]({x['absolute_url']})" - for x in jobs - ] + formatted_jobs: list[str] = [] + for job in jobs: + max_title_length = min(50, 102 - len(job["absolute_url"] - 4)) + if len(title) < max_title_length: + title: str = job["title"] + else: + title = job["title"][:max_title_length-1] + "…" + if title.endswith(" (…"): + title = title[:-3] + "…" + formatted_jobs.append(f"[{title}]({job['absolute_url']})") _title = await self.bot._(interaction, "fun.discordjobs.title") class JobsPaginator(Paginator): "Paginator used to display jobs offers"