Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Stable to Development #11

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/deploy-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ on:
push:
branches:
- Stable
pull_request:
branches:
- Stable
workflow_dispatch:
branches:
- Stable
Expand Down
13 changes: 9 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import asyncio
import discord
from discord.ext import commands
import os
import logging
from core import Database, EmbedColor, Git
from core import Database, EmbedColor
import signal
from contextlib import suppress

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
Expand Down Expand Up @@ -34,8 +37,6 @@ def __init__(self):
self.db = Database()

self.embed = EmbedColor(self)

self.git = Git(self)

os.makedirs(f"{os.getcwd()}/settings", exist_ok=True)

Expand All @@ -50,6 +51,11 @@ async def setup_hook(self):
raise e

self.logger.info("Finished loading all cogs")

with suppress(NotImplementedError):
for signame in ('SIGINT', 'SIGTERM'):
self.loop.add_signal_handler(getattr(signal, signame), lambda: asyncio.create_task(self.close()))

return await super().setup_hook()

async def shutdown(self):
Expand All @@ -59,7 +65,6 @@ async def shutdown(self):
@commands.Cog.listener()
async def on_ready(self):
self.logger.info(f"Logged in as {self.user.name}")
self.git.update_code.start()
guild = discord.Object(id=138365437791567872)
self.tree.copy_global_to(guild=guild)
fmt = await self.tree.sync(guild=guild)
Expand Down
41 changes: 39 additions & 2 deletions cogs/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ async def predicate(interaction: discord.Interaction):
return False
return True
return app_commands.check(predicate)

def check_user_perms():
async def predicate(interaction: discord.Interaction):
if not interaction.user.guild_permissions.administrator:
return False
return True
return app_commands.check(predicate)

@app_commands.guild_only()
@check_voice_user()
Expand All @@ -109,7 +116,7 @@ async def play(self, interaction: discord.Interaction, url: str=None):
embed.description = f"Could not find tracks with url: `{url}`"
return await interaction.response.send_message(embed=embed)
else:
track = Track(tracks[0].id, tracks[0].info, requester=interaction.user)
track = Track(interaction.user, tracks[0])

embed.description = f"**Added**:\n**[{track.title}](https://www.youtube.com/watch?v={track.identifier} '{track.identifier}')**"
embed.set_footer(text=f"Requested by: {track.requester}", icon_url=track.requester.avatar.url)
Expand Down Expand Up @@ -207,6 +214,7 @@ async def predicate(interaction: discord.Interaction):
@app_commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@music.command(description="Pause the current player")
async def pause(self, interaction: discord.Interaction):
"""Pauses the music player.
Expand All @@ -221,6 +229,7 @@ async def pause(self, interaction: discord.Interaction):
@app_commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@music.command(description="Resumes the current player")
async def resume(self, interaction: discord.Interaction):
"""Unpauses the music player.
Expand All @@ -234,9 +243,11 @@ async def resume(self, interaction: discord.Interaction):

@app_commands.guild_only()
@check_voice_user()
@check_user_perms()
@music.command(description="Stops the current player and disconnects from voice")
async def stop(self, interaction: discord.Interaction):
"""Stops playing music and disconnects the bot from the voice channel."""
"""Stops playing music and disconnects the bot from the voice channel.
"""
embed = self.embed.create_embed(interaction.user)

if not interaction.guild.voice_client:
Expand All @@ -255,6 +266,7 @@ async def stop(self, interaction: discord.Interaction):
@app_commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@music.command(description="Skips the current song")
async def skip(self, interaction: discord.Interaction):
"""Skips the current playing song.
Expand All @@ -276,6 +288,7 @@ async def skip(self, interaction: discord.Interaction):
@commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@app_commands.describe(volume="Volume level (Default: 1.0)")
@music.command(description="Changes the volume of the player")
async def volume(self, interaction: discord.Interaction, volume: app_commands.Range[float, 0.0, 20.0]=None):
Expand All @@ -293,6 +306,7 @@ async def volume(self, interaction: discord.Interaction, volume: app_commands.Ra
@commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@app_commands.describe(position="Time to set to (in seconds)")
@music.command(description="Sets the current position in the track to the specified time")
async def set(self, interaction: discord.Interaction, position: float):
Expand All @@ -313,6 +327,7 @@ async def set(self, interaction: discord.Interaction, position: float):
@commands.guild_only()
@check_voice_user()
@check_voiceclient()
@check_user_perms()
@app_commands.describe(loop="Bool whether to loop")
@music.command(description="Toggle whether the current song should loop")
async def loop(self, interaction: discord.Interaction, loop: bool):
Expand Down Expand Up @@ -341,5 +356,27 @@ def process_sponsorblock(self, sponsorblock_segments: list):
filter_segments.append([start, end])
return filter_segments

@app_commands.guild_only()
@check_voiceclient()
@music.command()
async def queue(self, interaction: discord.Interaction):
"""Return queue for voice player"""
vc: wavelink.Player = interaction.guild.voice_client

embed = self.embed.create_embed(interaction.user)

if(vc.current):
embed.description = f"**Currently playing**:\n**[{vc.current.title}](https://www.youtube.com/watch?v={vc.current.identifier} '{vc.current.identifier}')**\n"

if(vc.queue.count > 0):
embed.description += "\n**Next up**:"
for index, track in enumerate(vc.queue):
if(index > 5):
embed.description += f"\nAnd {vc.queue.count-5} more"
break
embed.description += f"\n**[{track.title}](https://www.youtube.com/watch?v={track.identifier} '{track.identifier}')**"

await interaction.response.send_message(embed=embed)

async def setup(bot: commands.Bot):
await bot.add_cog(Lavalink(bot))
3 changes: 1 addition & 2 deletions core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .database import Database
from .embed import EmbedColor
from .git import Git
from .embed import EmbedColor
80 changes: 0 additions & 80 deletions core/git.py

This file was deleted.