async def empty(self, context): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel guild_instance.emptyPlaylist() await guild_instance.textChannel.send( embed=discord.Embed(title="The playlist has been emptied.", color=discord.Color.green())) await context.message.delete()
async def botIsConnectedToGuildVoice(context): server_id = context.message.guild.id guild_instance = getGuildInstance(server_id, create_if_missing=False) if guild_instance is None or guild_instance.voiceClient is None: embed = discord.Embed(title="I'm not connected yet.", colour=discord.Color.red()) await context.message.channel.send(embed=embed) return False else: return True
async def remove(self, context, ind: int): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel try: ind = int(ind) - 1 await guild_instance.remove(ind) except ValueError: await guild_instance.textChannelsend( embed=discord.Embed(title="Index out of range", color=discord.Color.green())) await context.message.delete()
async def skip(self, context, ind=None): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel if ind is None: await guild_instance.skip() else: try: ind = int(ind) - 1 await guild_instance.skip(ind) except ValueError: await guild_instance.textChannel.send( embed=discord.Embed(title="Index out of range", color=discord.Color.green())) await context.message.delete()
async def playlist(self, context): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel if guild_instance.loop == 0: loop = "off" elif guild_instance.loop == 1: loop = "single" else: loop = "all" text = f"• **Actual:** {guild_instance.currentSong.title} \n• **Loop:** {loop}\n \n" for num, video in enumerate(guild_instance.playlist): text += '**' + str(num + 1) + ") " + '**' + video.title + "\n \n" embed = discord.Embed(title="Playlist:", description=text, colour=discord.Color.green()) await guild_instance.textChannel.send(embed=embed) await context.message.delete()
async def play(self, context, url): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel if url.startswith("http"): yt_playlist = re.search("(youtube.com|youtu.be)(\/playlist\?list=)([a-zA-Z0-9\-\_]+)", url) yt_video = re.search("(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*)", url) spotify_playlist = re.search("(https:\/\/open.spotify.com)(\/user\/spotify\/playlist\/|\/playlist\/)(\w+)", url) spotify_album = re.search("(https:\/\/open.spotify.com)(\/user\/spotify\/playlist\/|\/album\/)(\w+)", url) if yt_playlist is not None: await guild_instance.getYoutubePlaylist(yt_playlist[3]) elif yt_video is not None: await guild_instance.addVideoToPlaylist(yt_video[2]) elif spotify_playlist is not None: await guild_instance.getSpotifyPlaylist(spotify_playlist[3]) elif spotify_album is not None: await guild_instance.getSpotifyAlbum(spotify_album[3]) else: await guild_instance.textChannel.send( embed=discord.Embed(title="Wrong URL", colour=discord.Color.red())) return elif url.isnumeric(): await guild_instance.addToPlaylistFromSearchList(int(url) - 1) else: await guild_instance.youtubeSearch(context.message.content[5:]) await context.message.delete() return await context.message.delete() await guild_instance.player(context.message.author.voice.channel)
async def loop(self, context, msg): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel if msg == "off": guild_instance.loop = 0 await context.message.channel.send( embed=discord.Embed(title="Loop set to off", color=discord.Color.green())) elif msg == "single": guild_instance.loop = 1 #guild_instance.playlist.append(guild_instance.currentSong) await context.message.channel.send( embed=discord.Embed(title="Loop set to single", color=discord.Color.green())) elif msg == "all": guild_instance.loop = 2 await context.message.channel.send( embed=discord.Embed(title="Loop set to all", color=discord.Color.green())) await context.message.delete()
async def song(self, context): guild_instance = getGuildInstance(context.message.guild.id) guild_instance.textChannel = context.message.channel embed = discord.Embed(colour=discord.Color.green()) if guild_instance.voiceClient is not None and guild_instance.voiceClient.is_playing(): msg = "------------------------------" ind = round(len(msg) * (guild_instance.currentSong.perCentPlayed())) msg = msg[:ind] + "**|**" + msg[ind + 1:] embed.title = guild_instance.currentSong.title embed.description = msg else: embed.title = "No song is playing." await guild_instance.textChannel.send(embed=embed) await context.message.delete()
async def shuffle(self, context): guild_instance = getGuildInstance(context.message.guild.id, create_if_missing=False) await guild_instance.shuffleList() await context.message.delete()