Compare commits

..

No commits in common. "062676df264bae3f72858c970f28f3a43e181ea1" and "e7105f18287c4455a52899276c8ebd91353c3587" have entirely different histories.

8 changed files with 46 additions and 64 deletions

View File

@ -60,7 +60,7 @@ class YTDLSource(PCMVolumeTransformer):
) )
def __repr__(self): def __repr__(self):
return f"<YTDLSource title={self.title} original_url={self.original_url} duration={self.duration}>" return f"<YTDLSource title={self.title} original_url=<{self.original_url}> duration={self.duration}>"
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()

View File

@ -8,9 +8,9 @@ from yt_dlp import version
import arguments import arguments
import commands import commands
import utils
from constants import EMBED_COLOR from constants import EMBED_COLOR
from state import client, start_time from state import client, start_time
from utils import format_duration, reply, surround
async def status(message): async def status(message):
@ -25,41 +25,41 @@ async def status(message):
embed = disnake.Embed(color=EMBED_COLOR) embed = disnake.Embed(color=EMBED_COLOR)
embed.add_field( embed.add_field(
name="Latency", name="Latency",
value=surround(f"{round(client.latency * 1000, 1)} ms"), value=f"```{round(client.latency * 1000, 1)} ms```",
) )
embed.add_field( embed.add_field(
name="Memory", name="Memory",
value=surround(f"{round(memory_usage, 1)} MiB"), value=f"```{round(memory_usage, 1)} MiB```",
) )
embed.add_field( embed.add_field(
name="Threads", name="Threads",
value=surround(threading.active_count()), value=f"```{threading.active_count()}```",
) )
embed.add_field( embed.add_field(
name="Guilds", name="Guilds",
value=surround(len(client.guilds)), value=f"```{len(client.guilds)}```",
) )
embed.add_field( embed.add_field(
name="Members", name="Members",
value=surround(member_count), value=f"```{member_count}```",
) )
embed.add_field( embed.add_field(
name="Channels", name="Channels",
value=surround(channel_count), value=f"```{channel_count}```",
) )
embed.add_field( embed.add_field(
name="Disnake", name="Disnake",
value=surround(disnake.__version__), value=f"```{disnake.__version__}```",
) )
embed.add_field( embed.add_field(
name="yt-dlp", name="yt-dlp",
value=surround(version.__version__), value=f"```{version.__version__}```",
) )
embed.add_field( embed.add_field(
name="Uptime", name="Uptime",
value=surround(format_duration(int(time.time() - start_time), short=True)), value=f"```{utils.format_duration(int(time.time() - start_time), short=True)}```",
) )
await reply(message, embed=embed) await utils.reply(message, embed=embed)
async def uptime(message): async def uptime(message):
@ -78,13 +78,15 @@ async def uptime(message):
return return
if args.since: if args.since:
await reply(message, f"{round(start_time)}") await utils.reply(message, f"{round(start_time)}")
else: else:
await reply(message, f"up {format_duration(int(time.time() - start_time))}") await utils.reply(
message, f"up {utils.format_duration(int(time.time() - start_time))}"
)
async def ping(message): async def ping(message):
await reply( await utils.reply(
message, message,
embed=disnake.Embed( embed=disnake.Embed(
title="Pong :ping_pong:", title="Pong :ping_pong:",
@ -95,7 +97,7 @@ async def ping(message):
async def help(message): async def help(message):
await reply( await utils.reply(
message, message,
", ".join( ", ".join(
[f"`{command.value}`" for command in commands.Command.__members__.values()] [f"`{command.value}`" for command in commands.Command.__members__.values()]

View File

@ -4,10 +4,9 @@ from .utils import command_allowed
async def join(message): async def join(message):
if message.author.voice:
if message.guild.voice_client: if message.guild.voice_client:
await message.guild.voice_client.move_to(message.channel) return await message.guild.voice_client.move_to(message.channel)
else: elif message.author.voice:
await message.author.voice.channel.connect() await message.author.voice.channel.connect()
else: else:
await utils.reply(message, "you are not connected to a voice channel!") await utils.reply(message, "you are not connected to a voice channel!")

View File

@ -3,7 +3,7 @@ import disnake
import audio import audio
import sponsorblock import sponsorblock
import utils import utils
from constants import EMBED_COLOR, SPONSORBLOCK_CATEGORY_NAMES from constants import EMBED_COLOR
from state import players from state import players
from .utils import command_allowed from .utils import command_allowed
@ -28,12 +28,11 @@ async def sponsorblock_command(message):
text = [] text = []
for segment in video["segments"]: for segment in video["segments"]:
begin, end = map(int, segment["segment"]) begin, end = map(int, segment["segment"])
if (category := segment["category"]) in SPONSORBLOCK_CATEGORY_NAMES: category_name = sponsorblock.CATEGORY_NAMES.get(segment["category"])
category = SPONSORBLOCK_CATEGORY_NAMES[category]
current = "**" if progress >= begin and progress < end else "" current = "**" if progress >= begin and progress < end else ""
text.append( text.append(
f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category}{current}" f"{current}`{audio.utils.format_duration(begin)}` - `{audio.utils.format_duration(end)}`: {category_name if category_name else 'Unknown'}{current}"
) )
await utils.reply( await utils.reply(

View File

@ -19,11 +19,6 @@ BAR_LENGTH = 35
EMBED_COLOR = 0xFF6600 EMBED_COLOR = 0xFF6600
OWNERS = [531392146767347712] OWNERS = [531392146767347712]
PREFIX = "%" PREFIX = "%"
SPONSORBLOCK_CATEGORY_NAMES = {
"music_offtopic": "non-music",
"selfpromo": "self promotion",
"sponsor": "sponsored",
}
RELOADABLE_MODULES = [ RELOADABLE_MODULES = [
"arguments", "arguments",
"audio", "audio",
@ -57,21 +52,21 @@ RELOADABLE_MODULES = [
"yt_dlp.version", "yt_dlp.version",
] ]
PUBLIC_FLAGS = { PUBLIC_FLAGS = {
1 << 0: "Discord Employee", 1: "Discord Employee",
1 << 1: "Discord Partner", 2: "Discord Partner",
1 << 2: "HypeSquad Events", 4: "HypeSquad Events",
1 << 3: "Bug Hunter Level 1", 8: "Bug Hunter Level 1",
1 << 6: "HypeSquad Bravery", 64: "HypeSquad Bravery",
1 << 7: "HypeSquad Brilliance", 128: "HypeSquad Brilliance",
1 << 8: "HypeSquad Balance", 256: "HypeSquad Balance",
1 << 9: "Early Supporter", 512: "Early Supporter",
1 << 10: "Team User", 1024: "Team User",
1 << 14: "Bug Hunter Level 2", 16384: "Bug Hunter Level 2",
1 << 16: "Verified Bot", 65536: "Verified Bot",
1 << 17: "Verified Bot Developer", 131072: "Verified Bot Developer",
1 << 18: "Discord Certified Moderator", 262144: "Discord Certified Moderator",
1 << 19: "HTTP Interactions Only", 524288: "HTTP Interactions Only",
1 << 22: "Active Developer", 4194304: "Active Developer",
} }
BADGE_EMOJIS = { BADGE_EMOJIS = {
"Discord Employee": "<:DiscordStaff:879666899980546068>", "Discord Employee": "<:DiscordStaff:879666899980546068>",

View File

@ -1,21 +1,13 @@
import hashlib import hashlib
import json
import aiohttp import aiohttp
from state import sponsorblock_cache from state import sponsorblock_cache
categories = json.dumps( CATEGORY_NAMES = {
[ "music_offtopic": "non-music",
"interaction", "sponsor": "sponsored",
"intro", }
"music_offtopic",
"outro",
"preview",
"selfpromo",
"sponsor",
]
)
async def get_segments(video_id: str): async def get_segments(video_id: str):
@ -26,7 +18,7 @@ async def get_segments(video_id: str):
session = aiohttp.ClientSession() session = aiohttp.ClientSession()
response = await session.get( response = await session.get(
f"https://sponsor.ajay.app/api/skipSegments/{hashPrefix}", f"https://sponsor.ajay.app/api/skipSegments/{hashPrefix}",
params={"categories": categories}, params={"categories": '["sponsor", "music_offtopic"]'},
) )
if response.status == 200 and ( if response.status == 200 and (
results := list( results := list(

View File

@ -1,4 +1,4 @@
from .common import LimitedSizeDict, filter_secrets, format_duration, surround from .common import LimitedSizeDict, filter_secrets, format_duration
from .discord import ( from .discord import (
ChannelResponseWrapper, ChannelResponseWrapper,
MessageInteractionWrapper, MessageInteractionWrapper,
@ -24,5 +24,4 @@ __all__ = [
"MessageInteractionWrapper", "MessageInteractionWrapper",
"reply", "reply",
"snowflake_timestamp", "snowflake_timestamp",
"surround",
] ]

View File

@ -3,10 +3,6 @@ from collections import OrderedDict
from constants import SECRETS from constants import SECRETS
def surround(inner, outer="```"):
return outer + str(inner) + outer
def format_duration(duration: int, natural: bool = False, short: bool = False): def format_duration(duration: int, natural: bool = False, short: bool = False):
def format_plural(noun, count): def format_plural(noun, count):
if short: if short: