Skip to content

Commit

Permalink
spotify cog
Browse files Browse the repository at this point in the history
  • Loading branch information
tookender committed Nov 2, 2023
1 parent 91f152c commit 7696687
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extensions/utility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from .source import SourceCog
from .embed import EmbedCog
from .download import DownloadCog
from .spotify import SpotifyCog


class Utility(ConfigCog, InfoCog, NeofetchCog, PingCog, SourceCog, EmbedCog, DownloadCog):
class Utility(ConfigCog, InfoCog, NeofetchCog, PingCog, SourceCog, EmbedCog, DownloadCog, SpotifyCog):
pass


Expand Down
37 changes: 37 additions & 0 deletions extensions/utility/spotify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import discord
from discord.ext import commands

from bot import Korii
import config
from io import BytesIO


class SpotifyCog(commands.Cog):
def __init__(self, bot: Korii):
self.bot = bot

@commands.hybrid_command()
async def spotify(self, ctx: commands.Context, member: discord.Member = commands.Author):
await ctx.typing()

spotify: discord.Spotify | None = discord.utils.find( # type: ignore
lambda activity: isinstance(activity, discord.Spotify), member.activities
)

if not spotify:
return await ctx.send("❌ | no spotify activity found")

headers = {"Authorization": f"Bearer {config.JEYY_API_TOKEN}"}
parameters = {
"title": spotify.title,
"cover_url": spotify.album_cover_url,
"duration_seconds": spotify.duration.seconds,
"start_timestamp": spotify.start.timestamp(),
"artists": spotify.artists,
}

request = await self.bot.session.get("https://api.jeyy.xyz/v2/discord/spotify", parameters=parameters, headers=headers)
bytes = BytesIO(await request.read())
file = discord.File(bytes, "spotify.png")

return await ctx.send(f"<:spotify:1169757922532794368> **{member.display_name}** is listening to **{spotify.title}**", file=file)

0 comments on commit 7696687

Please sign in to comment.