import music_functions from constants import MUZYKA import logging import discord from discord.ext import commands from communication_subroutine import PREPPED_TRACKS from sys import platform import re class MusicModule(commands.Cog): def __init__(self, bot, logger_name): self.bot = bot self.logger = logging.getLogger(logger_name) @commands.hybrid_command( name="krecimy_pornola", description="Wiadomo co, dla kogo i po co", ) async def krecimy_pornola(self, ctx): """ Download a music number from youtube. :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It represents the context in which the command was invoked, including information such as the message, the channel, the server, and the user who invoked the command. It allows the command to interact with the Discord API and """ await ctx.send("Dej mnie chwilkę") allowed = False for role in ctx.author.roles: if role.name == "Bartender": allowed = True if allowed: self.logger.info("Pornol") async with ctx.typing(): # wyciagnij linka z kontekstu content = ctx.message.content.split() for item_yt in content: if re.match("http.*", item_yt): sciezka, files = await music_functions.get_file(ctx, "Pornol", item_yt) if files: self.logger.info("Pornol udany") await ctx.send(f"Jest w tajnym archiwum pod adresem{sciezka})") else: await ctx.reply("Jak ładnie szefa poprosisz.") @commands.hybrid_command( name="co_na_plejliscie_wariacie", description="Wyswietl kawalki ktore sa na pocztku list radia", guild=discord.Object(id=664789470779932693), ) async def co_na_plejliscie_wariacie(self,ctx): """ Download a music number from youtube. :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It represents the context in which the command was invoked, including information such as the message, the channel, the server, and the user who invoked the command. It allows the command to interact with the Discord API and """ await ctx.send("Dej mnie chwilkę") async with ctx.typing(): self.logger.info("plejlista") self.logger.info(PREPPED_TRACKS) await ctx.send(f"Didżej Hammer i jego sztuczna inteligencja (||he he||) prezentują: \n- obecnie grany jest {(PREPPED_TRACKS['now_playing']).rstrip()} (wg metadanych: {PREPPED_TRACKS['meta']}) \n- następny będzie{(PREPPED_TRACKS['next']).rstrip()} \n- na liście priorytetowej {(PREPPED_TRACKS['priority']).rstrip()} \n- na liście hitów obecnie czeka kawałek {(PREPPED_TRACKS['hit']).rstrip()} \n- na liście wszystkich kawałków {(PREPPED_TRACKS['all']).rstrip()} \n- najświeższym zamówieniem od słuchaczy jest {(PREPPED_TRACKS['requests']).rstrip()} \nZ kolei jingiel to: {(PREPPED_TRACKS['jingles']).rstrip()}") @commands.hybrid_command( name="dej_co_z_jutuba", description="Podaj link do youtube - sciagnie i doda muzyke", guild=discord.Object(id=664789470779932693), ) async def dej_co_z_jutuba(self,ctx): """ Download a music number from youtube. :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It represents the context in which the command was invoked, including information such as the message, the channel, the server, and the user who invoked the command. It allows the command to interact with the Discord API and """ await ctx.send("Dej mnie chwilkę") self.logger.info("Jutub") async with ctx.typing(): # wyciagnij linka z kontekstu content = ctx.message.content.split() for item_yt in content: if re.match("http.*", item_yt): _, files = await music_functions.get_file(ctx, "Youtube", item_yt) if files: for file_iter in files: global MUZYKA # pylint: disable=global-variable-not-assigned MUZYKA["queue"].insert(0, file_iter) music_functions.MUSIC_FILE_LIST.update_file_list(file_iter) MUZYKA["requester"].insert(0, ctx.author) await ctx.send(f"Dodałem do listy {file_iter}") self.logger.info("Jutub udany") @commands.hybrid_command( name="dej_co_ze_spotifaja", description="Podaj link do spotify - sciagnie i doda muzyke", guild=discord.Object(id=664789470779932693), ) async def dej_co_ze_spotifaja(self, ctx): """ Get a playlist or a music number from Spotify. :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It represents the context in which the command was invoked, including information such as the message, the channel, the server, and the user who invoked the command. This parameter is required in all Discord.py commands """ self.logger.info("Spotifaj") await ctx.send("Dej mnie chwilkę") async with ctx.typing(): # wyciagnij linka z kontekstu content = ctx.message.content.split() for item in content: if re.match("http.*", item): dir_path, files = await music_functions.get_file(ctx, "Spotify", item) if platform == "win32": separator = "\\" else: separator = "/" for file in files: file_path = ( dir_path + separator + file["artist"] + " - " + file["name"] + ".mp3" ) global MUZYKA # pylint: disable=global-variable-not-assigned MUZYKA["queue"].insert( 0, dir_path + separator + file["artist"] + " - " + file["name"] + ".mp3", ) MUZYKA["requester"].insert(0, ctx.author) music_functions.MUSIC_FILE_LIST.update_file_list(file_path) await ctx.send( f"Dodałem do listy {dir_path}{file['artist']} - + {file['name']}.mp3" ) self.logger.info("Spotifaj udany") async def setup(bot): logger = logging.getLogger("discord") music_functions.MUSIC_FILE_LIST.refresh_file_list() logger.info("Playlist generation") await bot.add_cog(MusicModule(bot, "discord")) logger.info("Loading music commands module done")