Compare commits
8 Commits
fbdd442a8e
...
b71331a102
Author | SHA1 | Date | |
---|---|---|---|
b71331a102 | |||
d63155d0fb | |||
40cd8238dd | |||
81e30c7e70 | |||
a1d63f1bb1 | |||
1a24754549 | |||
2c6d05b33d | |||
117438be76 |
@ -34,7 +34,7 @@ class ArgumentParser:
|
||||
await utils.reply(message, f"`{e}`")
|
||||
|
||||
|
||||
def range_type(string, min=0, max=100):
|
||||
def range_type(string: str, min=0, max=100):
|
||||
try:
|
||||
value = int(string)
|
||||
except ValueError:
|
||||
|
@ -32,6 +32,8 @@ class Command(Enum):
|
||||
def match_token(token: str) -> list[Command]:
|
||||
if token.lower() == "r":
|
||||
return [Command.RELOAD]
|
||||
elif token.lower() == "s":
|
||||
return [Command.SKIP]
|
||||
|
||||
if exact_match := list(
|
||||
filter(
|
||||
|
@ -171,7 +171,10 @@ async def queue_or_play(message, edited=False):
|
||||
else:
|
||||
players[message.guild.id].queue_add(queued)
|
||||
|
||||
if not message.guild.voice_client.source:
|
||||
if not message.guild.voice_client:
|
||||
await utils.reply(message, "unexpected disconnect from voice channel!")
|
||||
return
|
||||
elif not message.guild.voice_client.source:
|
||||
play_next(message, first=True)
|
||||
elif args.now:
|
||||
message.guild.voice_client.stop()
|
||||
|
26
events.py
26
events.py
@ -1,14 +1,12 @@
|
||||
import asyncio
|
||||
import threading
|
||||
import time
|
||||
from logging import info
|
||||
|
||||
import fun
|
||||
from logging import debug, info, warning
|
||||
|
||||
import commands
|
||||
import core
|
||||
import fun
|
||||
import tasks
|
||||
from state import client, start_time
|
||||
from state import client
|
||||
|
||||
|
||||
def prepare():
|
||||
@ -42,19 +40,29 @@ async def on_message_edit(before, after):
|
||||
await core.on_message(after, edited=True)
|
||||
|
||||
|
||||
async def on_ready():
|
||||
info(f"logged in as {client.user} in {round(time.time() - start_time, 1)}s")
|
||||
|
||||
|
||||
async def on_voice_state_update(member, before, after):
|
||||
await core.on_voice_state_update(member, before, after)
|
||||
|
||||
|
||||
async def on_ready():
|
||||
info(f"logged in as {client.user}")
|
||||
|
||||
|
||||
async def on_connect():
|
||||
debug("connected to the gateway!")
|
||||
|
||||
|
||||
async def on_disconnect():
|
||||
warning("disconnected from the gateway!")
|
||||
|
||||
|
||||
for event_type, handlers in client.get_listeners().items():
|
||||
for handler in handlers:
|
||||
client.remove_listener(handler, event_type)
|
||||
|
||||
client.add_listener(on_bulk_message_delete, "on_bulk_message_delete")
|
||||
client.add_listener(on_connect, "on_connect")
|
||||
client.add_listener(on_disconnect, "on_disconnect")
|
||||
client.add_listener(on_message, "on_message")
|
||||
client.add_listener(on_message_delete, "on_message_delete")
|
||||
client.add_listener(on_message_edit, "on_message_edit")
|
||||
|
2
extra.py
2
extra.py
@ -81,7 +81,7 @@ def messages_per_second(limit=500):
|
||||
)
|
||||
|
||||
|
||||
async def auto_count(channel_id):
|
||||
async def auto_count(channel_id: int):
|
||||
if (channel := await client.fetch_channel(channel_id)) and isinstance(
|
||||
channel, disnake.TextChannel
|
||||
):
|
||||
|
5
fun.py
5
fun.py
@ -4,6 +4,7 @@ import commands
|
||||
|
||||
|
||||
async def on_message(message):
|
||||
if "gn" in commands.tokenize(message.content, remove_prefix=False):
|
||||
if random.random() < 0.01:
|
||||
if random.random() < 0.01 and "gn" in commands.tokenize(
|
||||
message.content, remove_prefix=False
|
||||
):
|
||||
await message.add_reaction(random.choice(["💤", "😪", "😴", "🛌"]))
|
||||
|
@ -1,3 +1,4 @@
|
||||
aiohttp
|
||||
audioop-lts
|
||||
disnake
|
||||
disnake_paginator
|
||||
|
@ -10,11 +10,11 @@ CATEGORY_NAMES = {
|
||||
}
|
||||
|
||||
|
||||
async def get_segments(videoId: str):
|
||||
if videoId in sponsorblock_cache:
|
||||
return sponsorblock_cache[videoId]
|
||||
async def get_segments(video_id: str):
|
||||
if video_id in sponsorblock_cache:
|
||||
return sponsorblock_cache[video_id]
|
||||
|
||||
hashPrefix = hashlib.sha256(videoId.encode()).hexdigest()[:4]
|
||||
hashPrefix = hashlib.sha256(video_id.encode()).hexdigest()[:4]
|
||||
session = aiohttp.ClientSession()
|
||||
response = await session.get(
|
||||
f"https://sponsor.ajay.app/api/skipSegments/{hashPrefix}",
|
||||
@ -22,8 +22,8 @@ async def get_segments(videoId: str):
|
||||
)
|
||||
if response.status == 200 and (
|
||||
results := list(
|
||||
filter(lambda v: videoId == v["videoID"], await response.json())
|
||||
filter(lambda v: video_id == v["videoID"], await response.json())
|
||||
)
|
||||
):
|
||||
sponsorblock_cache[videoId] = results[0]
|
||||
sponsorblock_cache[video_id] = results[0]
|
||||
return results[0]
|
||||
|
@ -88,6 +88,8 @@ class YTDLSource(PCMVolumeTransformer):
|
||||
)
|
||||
|
||||
if "entries" in data:
|
||||
if not data["entries"]:
|
||||
raise Exception("no entries provided by yt-dlp!")
|
||||
data = data["entries"][0]
|
||||
|
||||
return cls(
|
||||
@ -158,7 +160,12 @@ class QueuedSong:
|
||||
name="Uploader",
|
||||
value=self.player.uploader,
|
||||
)
|
||||
embed.add_field(name="Likes", value=f"{self.player.like_count:,}")
|
||||
embed.add_field(
|
||||
name="Likes",
|
||||
value=f"{self.player.like_count:,}"
|
||||
if self.player.like_count
|
||||
else "Unknown",
|
||||
)
|
||||
embed.add_field(name="Views", value=f"{self.player.view_count:,}")
|
||||
embed.add_field(name="Published", value=f"<t:{self.player.timestamp}>")
|
||||
embed.add_field(name="Volume", value=f"{int(self.player.volume * 100)}%")
|
||||
|
Loading…
x
Reference in New Issue
Block a user