From 062676df264bae3f72858c970f28f3a43e181ea1 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Wed, 26 Feb 2025 16:21:29 -0500 Subject: [PATCH] fix: handle missing sponsorblock category names --- commands/voice/sponsorblock.py | 5 +++-- constants.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/voice/sponsorblock.py b/commands/voice/sponsorblock.py index b26547f..0bdcedd 100644 --- a/commands/voice/sponsorblock.py +++ b/commands/voice/sponsorblock.py @@ -28,11 +28,12 @@ async def sponsorblock_command(message): text = [] for segment in video["segments"]: begin, end = map(int, segment["segment"]) - category_name = SPONSORBLOCK_CATEGORY_NAMES.get(segment["category"]) + if (category := segment["category"]) in SPONSORBLOCK_CATEGORY_NAMES: + category = SPONSORBLOCK_CATEGORY_NAMES[category] current = "**" if progress >= begin and progress < end else "" text.append( - f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category_name if category_name else 'Unknown'}{current}" + f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category}{current}" ) await utils.reply( diff --git a/constants.py b/constants.py index 91d84a8..a0b2f64 100644 --- a/constants.py +++ b/constants.py @@ -21,6 +21,7 @@ OWNERS = [531392146767347712] PREFIX = "%" SPONSORBLOCK_CATEGORY_NAMES = { "music_offtopic": "non-music", + "selfpromo": "self promotion", "sponsor": "sponsored", } RELOADABLE_MODULES = [