feat(commands/voice): add sponsorblock command
This commit is contained in:
44
commands/voice/sponsorblock.py
Normal file
44
commands/voice/sponsorblock.py
Normal 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,
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user