REF: Made sure everything conforms to Flake8's standards

FIX: Fixed the Permission issues with logger
FEAT: Changed how the XP system works. Now does a scaling curve with xp being 1-5
This commit is contained in:
Dan
2024-06-22 08:55:26 -04:00
parent 4d9214e378
commit 39603b1e06
12 changed files with 327 additions and 195 deletions

View File

@ -1,8 +1,10 @@
import logging
import discord
from discord import app_commands
import spotipy
from discord import app_commands
from spotipy.oauth2 import SpotifyOAuth
import config
# Set up logging
@ -21,7 +23,7 @@ class SpotifyModule:
scope=(
"user-library-read user-read-playback-state "
"user-modify-playback-state user-read-currently-playing"
)
),
)
)
self.add_commands()
@ -39,7 +41,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Current Track",
description="No song is currently playing",
color=discord.Color.red()
color=discord.Color.red(),
)
)
logger.info("No song is currently playing")
@ -49,15 +51,16 @@ class SpotifyModule:
embed = discord.Embed(
title="Current Track",
description=f"{track['name']} by {artist}",
color=discord.Color.green()
color=discord.Color.green(),
)
embed.add_field(
name="Album", value=track['album']['name'],
inline=False
name="Album", value=track["album"]["name"], inline=False
)
embed.set_thumbnail(url=track['album']['images'][0]['url'])
embed.set_thumbnail(url=track["album"]["images"][0]["url"])
await interaction.followup.send(embed=embed)
logger.info(f"Currently playing: {track['name']} by {artist}") # noqa: E501
logger.info(
f"Currently playing: {track['name']} by {artist}"
) # noqa: E501
except Exception as e:
await interaction.followup.send(f"An error occurred: {e}")
logger.error(f"Error in current_track command: {e}")
@ -74,7 +77,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Play Track",
description="No results found",
color=discord.Color.red()
color=discord.Color.red(),
)
)
logger.info(f"No results found for query: {query}")
@ -90,7 +93,7 @@ class SpotifyModule:
title="Play Track",
description="No active devices found."
"Please open Spotify on a device.",
color=discord.Color.red()
color=discord.Color.red(),
)
)
logger.info("No active devices found for playback")
@ -100,22 +103,23 @@ class SpotifyModule:
embed = discord.Embed(
title="Now Playing",
description=f"{track['name']} by {', '.join([a['name'] for a in track['artists']])}", # noqa: E501
color=discord.Color.green()
color=discord.Color.green(),
)
embed.add_field(
name="Album", value=track['album']['name'], inline=False
name="Album", value=track["album"]["name"], inline=False
)
embed.set_thumbnail(url=track['album']['images'][0]['url'])
embed.set_thumbnail(url=track["album"]["images"][0]["url"])
await interaction.followup.send(embed=embed)
logger.info(f"Now playing: {track['name']} by {', '.join([a['name'] for a in track['artists']])}") # noqa: E501
logger.info(
f"Now playing: {track['name']} by {', '.join([a['name'] for a in track['artists']])}"
) # noqa: E501
except Exception as e:
await interaction.followup.send(f"An error occurred: {e}")
logger.error(f"Error in play_track command: {e}")
@app_commands.command(
name="play_playlist",
description="Play a playlist by searching for it"
"or providing a link"
description="Play a playlist by searching for it" "or providing a link",
)
async def play_playlist(interaction: discord.Interaction, query: str):
await interaction.response.defer()
@ -132,7 +136,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Play Playlist",
description="No results found",
color=discord.Color.red()
color=discord.Color.red(),
)
)
logger.info(f"No results found for query: {query}")
@ -147,7 +151,7 @@ class SpotifyModule:
title="Play Playlist",
description="No active devices found."
"Please open Spotify on a device.",
color=discord.Color.red()
color=discord.Color.red(),
)
)
logger.info("No active devices found for playback")
@ -156,13 +160,19 @@ class SpotifyModule:
self.sp.start_playback(context_uri=uri)
embed = discord.Embed(
title="Now Playing Playlist",
description=f"{playlist['name']} by {playlist['owner']['display_name']}" if not query.startswith("https://open.spotify.com/playlist/") else "Playing playlist", # noqa: E501
color=discord.Color.green()
description=(
f"{playlist['name']} by {playlist['owner']['display_name']}"
if not query.startswith("https://open.spotify.com/playlist/")
else "Playing playlist"
), # noqa: E501
color=discord.Color.green(),
)
if not query.startswith("https://open.spotify.com/playlist/"):
embed.set_thumbnail(url=playlist['images'][0]['url'])
embed.set_thumbnail(url=playlist["images"][0]["url"])
await interaction.followup.send(embed=embed)
logger.info(f"Now playing playlist: {playlist['name']} by {playlist['owner']['display_name']}") # noqa: E501
logger.info(
f"Now playing playlist: {playlist['name']} by {playlist['owner']['display_name']}"
) # noqa: E501
except Exception as e:
await interaction.followup.send(f"An error occurred: {e}")
logger.error(f"Error in play_playlist command: {e}")
@ -178,7 +188,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Pause",
description="Playback paused.",
color=discord.Color.green()
color=discord.Color.green(),
)
)
logger.info("Playback paused")
@ -197,7 +207,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Resume",
description="Playback resumed.",
color=discord.Color.green()
color=discord.Color.green(),
)
)
logger.info("Playback resumed")
@ -205,9 +215,7 @@ class SpotifyModule:
await interaction.followup.send(f"An error occurred: {e}")
logger.error(f"Error in resume command: {e}")
@app_commands.command(
name="next", description="Skip to the next track"
)
@app_commands.command(name="next", description="Skip to the next track")
async def next_track(interaction: discord.Interaction):
await interaction.response.defer()
try:
@ -216,7 +224,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Next Track",
description="Skipped to the next track.",
color=discord.Color.green()
color=discord.Color.green(),
)
)
logger.info("Skipped to the next track")
@ -235,7 +243,7 @@ class SpotifyModule:
embed=discord.Embed(
title="Previous Track",
description="Returned to the previous track.",
color=discord.Color.green()
color=discord.Color.green(),
)
)
logger.info("Returned to the previous track")