feat(commands/voice): add sponsorblock command

This commit is contained in:
Ryan 2025-01-24 17:51:25 -05:00
parent 256156b9d2
commit 26f81bd58f
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
6 changed files with 60 additions and 5 deletions

View File

@ -22,6 +22,7 @@ class Command(Enum):
RELOAD = "reload"
RESUME = "resume"
SKIP = "skip"
SPONSORBLOCK = "sponsorblock"
STATUS = "status"
UPTIME = "uptime"
VOLUME = "volume"

View File

@ -1,18 +1,20 @@
from .channel import join, leave
from .playback import fast_forward, pause, playing, resume, volume
from .queue import queue_or_play, skip
from .sponsorblock import sponsorblock_command
from .utils import remove_queued
__all__ = [
"fast_forward",
"join",
"leave",
"fast_forward",
"pause",
"playing",
"queue_or_play",
"skip",
"resume",
"pause",
"skip",
"remove_queued",
"resume",
"skip",
"skip",
"sponsorblock_command",
"volume",
]

View File

@ -0,0 +1,44 @@
import disnake
import sponsorblock
import utils
from constants import EMBED_COLOR
from state import players
from .utils import command_allowed
async def sponsorblock_command(message):
if not command_allowed(message, immutable=True):
return
if not message.guild.voice_client.source:
await utils.reply(message, "nothing is playing!")
return
progress = message.guild.voice_client.source.original.progress
video = await sponsorblock.get_segments(players[message.guild.id].current.player.id)
if not video:
await utils.reply(
message, "no sponsorblock segments were found for this video!"
)
return
text = []
for segment in video["segments"]:
begin, end = map(int, segment["segment"])
category_name = sponsorblock.CATEGORY_NAMES.get(segment["category"])
current = "**" if progress >= begin and progress < end else ""
text.append(
f"{current}`{utils.format_duration(begin, short=True)}` - `{utils.format_duration(end, short=True)}`: {category_name if category_name else 'Unknown'}{current}"
)
await utils.reply(
message,
embed=disnake.Embed(
title="Sponsorblock segments",
description="\n".join(text),
color=EMBED_COLOR,
),
)

View File

@ -30,6 +30,7 @@ RELOADABLE_MODULES = [
"commands.voice.playback",
"commands.voice.playing",
"commands.voice.queue",
"commands.voice.sponsorblock",
"commands.voice.utils",
"constants",
"core",

View File

@ -146,6 +146,8 @@ async def on_message(message, edited=False):
await commands.bot.ping(message)
case C.LOOKUP:
await commands.tools.lookup(message)
case C.SPONSORBLOCK:
await commands.voice.sponsorblock_command(message)
except Exception as e:
await utils.reply(
message,

View File

@ -4,6 +4,11 @@ import aiohttp
from state import sponsorblock_cache
CATEGORY_NAMES = {
"music_offtopic": "non-music",
"sponsor": "sponsored",
}
async def get_segments(videoId: str):
if videoId in sponsorblock_cache: