Files
TuneBot/plugins/lastfm_scrobbler/cog.py
T

47 lines
1.6 KiB
Python

from typing import TYPE_CHECKING
from discord.ext import commands
from context import CustomContext
from utils.classes import PluginCog
if TYPE_CHECKING:
from bot import TuneBot
class LastFMScrobblerCog(PluginCog, name="LastFMScrobbler"):
def __init__(self, bot: "TuneBot") -> None:
super().__init__(bot)
self.plugin = self.get_plugin_instance("lastfm-scrobbler")
@commands.group(name="lfm", invoke_without_command=True)
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
async def lfm(self, ctx: CustomContext):
"""Enable/Disable LastFM Scrobbling"""
embed = ctx.create_embed()
embed.title = f"LastFM scrobbler usage:"
embed.description = f"```{ctx.prefix}lfm enable\n{ctx.prefix}lfm del```"
await ctx.send(embed=embed)
@lfm.command(name="enable", aliases=["set"])
async def lfm_aut(self, ctx: CustomContext):
"""Enable LastFM Scrobbling"""
embed = ctx.create_embed()
embed.title = f"Start scrobbling"
auth_url = self.plugin.config["auth_url"] + "?user_id=" + str(ctx.author.id)
embed.description = f"[Login]({auth_url})"
await ctx.send(embed=embed)
@lfm.command(name="delete", aliases=["del"])
async def lfm_del(self, ctx: CustomContext):
"""Disable LastFM Scrobbling"""
db_key = self.plugin.config["session_key_table"]
await self.bot.global_utils.raw_table_del_entry(db_key, [ctx.author.id])
embed = ctx.create_embed()
embed.title = f"Stopped scrobbling"
await ctx.send(embed=embed)
def setup(bot: "TuneBot"):
bot.add_cog(LastFMScrobblerCog(bot))