mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 23:27:47 +00:00
Commit hoarding is a terrible practice
This commit is contained in:
+33
-5
@@ -1,24 +1,29 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import re
|
||||
from typing import Any
|
||||
from typing import Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import discord
|
||||
import lavalink
|
||||
from discord import Embed
|
||||
from discord.channel import TextChannel
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands.context import Context
|
||||
from discord.ext.commands.errors import CommandError
|
||||
from lavalink.models import AudioTrack
|
||||
from lavalink.models import DefaultPlayer
|
||||
|
||||
from bot import TuneBot
|
||||
from context import CustomContext
|
||||
from tunebot.plugins import ServiceEvent
|
||||
from utils.classes import BaseCog
|
||||
from utils.EmbedGenerator import EmbedGenerator
|
||||
from utils.exceptions import EmbeddedCommandException
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from discord import VoiceChannel
|
||||
|
||||
url_rx = re.compile(r"https?://(?:www\.)?.+")
|
||||
|
||||
|
||||
@@ -212,13 +217,36 @@ class Music(BaseCog):
|
||||
guild = self.bot.get_guild(guild_id)
|
||||
await guild.voice_client.disconnect(force=True)
|
||||
elif isinstance(event, lavalink.events.TrackStartEvent):
|
||||
channel_id = int(event.player.fetch("channel"))
|
||||
channel: TextChannel = self.bot.get_channel(channel_id)
|
||||
embed = await self.create_track_embed(event.player.current)
|
||||
await channel.send(embed=embed)
|
||||
if channel := event.player.fetch("channel"):
|
||||
channel_id = int(channel)
|
||||
channel: TextChannel = self.bot.get_channel(channel_id)
|
||||
embed = await self.create_track_embed(event.player.current)
|
||||
await channel.send(embed=embed)
|
||||
elif isinstance(event, lavalink.events.TrackEndEvent):
|
||||
await self.fill_player_queue(event.player, 1)
|
||||
|
||||
if event.reason == "FINISHED":
|
||||
if event.player.channel_id:
|
||||
channel_id = int(event.player.channel_id)
|
||||
voice_channel: "VoiceChannel" = self.bot.get_channel(channel_id)
|
||||
in_voice: list[int] = []
|
||||
|
||||
for member in voice_channel.members:
|
||||
if member.bot:
|
||||
continue
|
||||
|
||||
in_voice.append(member.id)
|
||||
|
||||
payload: dict[str, Any] = {
|
||||
"last_track": event.track,
|
||||
"in_voice": in_voice,
|
||||
}
|
||||
s = ServiceEvent.TRACK_ENDED
|
||||
await self.bot.plugin_manager.dispatch(s, payload)
|
||||
else:
|
||||
fmt = f"Failed dispatching for TrackEnd event, missing channel_id on player"
|
||||
print(fmt)
|
||||
|
||||
@commands.command(name="connect", aliases=["p", "play", "join"])
|
||||
async def play(self, ctx: CustomContext):
|
||||
"""Start the radio"""
|
||||
|
||||
Reference in New Issue
Block a user