[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2023-10-30 17:50:54 +00:00
parent 341164a0d2
commit db1c66dd40
2 changed files with 46 additions and 40 deletions

View File

@ -13,11 +13,9 @@ The classes listed here are as they appear in Pomice. When you use them within y
the way you use them will be different. Here's an example on how you would use the `TrackStartEvent` within an event listener in a cog: the way you use them will be different. Here's an example on how you would use the `TrackStartEvent` within an event listener in a cog:
```py ```py
@commands.Cog.listener @commands.Cog.listener
async def on_pomice_track_start(self, player: Player, track: Track): async def on_pomice_track_start(self, player: Player, track: Track):
... ...
``` ```
## Event definitions ## Event definitions

View File

@ -10,63 +10,71 @@ import re
from discord.ext import commands from discord.ext import commands
URL_REG = re.compile(r'https?://(?:www\.)?.+') URL_REG = re.compile(r"https?://(?:www\.)?.+")
class MyBot(commands.Bot): class MyBot(commands.Bot):
def __init__(self) -> None:
super().__init__(
command_prefix="!",
activity=discord.Activity(
type=discord.ActivityType.listening, name="to music!"
),
)
def __init__(self) -> None: self.add_cog(Music(self))
super().__init__(command_prefix='!', activity=discord.Activity(type=discord.ActivityType.listening, name='to music!'))
self.add_cog(Music(self)) async def on_ready(self) -> None:
print("I'm online!")
async def on_ready(self) -> None: await self.cogs["Music"].start_nodes()
print("I'm online!")
await self.cogs["Music"].start_nodes()
class Music(commands.Cog): class Music(commands.Cog):
def __init__(self, bot) -> None:
self.bot = bot
def __init__(self, bot) -> None: self.pomice = pomice.NodePool()
self.bot = bot
self.pomice = pomice.NodePool() async def start_nodes(self):
await self.pomice.create_node(
bot=self.bot,
host="127.0.0.1",
port="3030",
password="youshallnotpass",
identifier="MAIN",
)
print(f"Node is ready!")
async def start_nodes(self): @commands.command(name="join", aliases=["connect"])
await self.pomice.create_node(bot=self.bot, host='127.0.0.1', port='3030', async def join(
password='youshallnotpass', identifier='MAIN') self, ctx: commands.Context, *, channel: discord.TextChannel = None
print(f"Node is ready!") ) -> None:
if not channel:
channel = getattr(ctx.author.voice, "channel", None)
@commands.command(name='join', aliases=['connect'])
async def join(self, ctx: commands.Context, *, channel: discord.TextChannel = None) -> None:
if not channel:
channel = getattr(ctx.author.voice, 'channel', None)
if not channel: if not channel:
raise commands.CheckFailure('You must be in a voice channel to use this command' raise commands.CheckFailure(
'without specifying the channel argument.') "You must be in a voice channel to use this command"
"without specifying the channel argument."
)
await ctx.author.voice.channel.connect(cls=pomice.Player)
await ctx.send(f"Joined the voice channel `{channel}`")
await ctx.author.voice.channel.connect(cls=pomice.Player) @commands.command(name="play")
await ctx.send(f'Joined the voice channel `{channel}`') async def play(self, ctx, *, search: str) -> None:
if not ctx.voice_client:
@commands.command(name='play')
async def play(self, ctx, *, search: str) -> None:
if not ctx.voice_client:
await ctx.invoke(self.join) await ctx.invoke(self.join)
player = ctx.voice_client player = ctx.voice_client
results = await player.get_tracks(query=f'{search}') results = await player.get_tracks(query=f"{search}")
if not results: if not results:
raise commands.CommandError('No results were found for that search term.') raise commands.CommandError("No results were found for that search term.")
if isinstance(results, pomice.Playlist): if isinstance(results, pomice.Playlist):
await player.play(track=results.tracks[0]) await player.play(track=results.tracks[0])
else: else:
await player.play(track=results[0]) await player.play(track=results[0])