From 34f72eb31e281f542ea51f01db999fb57368bd4a Mon Sep 17 00:00:00 2001 From: Zenrac Date: Sat, 29 Feb 2020 03:22:55 +0100 Subject: [PATCH] PEP8 and some comments --- cogs/music.py | 37 +++++++++++++++++++++++++------------ cogs/useful.py | 9 ++++++--- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cogs/music.py b/cogs/music.py index 643b7eb..3fa00ed 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -776,7 +776,7 @@ async def prepare_url(self, query, node=None, source='ytsearch'): return await self.prepare_url(query=self.list_radiolist['Monstercat'], node=node) query = self.remove_optional_parameter(query) if match_local(query): - new = query.replace('/', '\\') # local file + new = query.replace('/', '\\') # local file else: new = f'{source}:{query}' results = await self.bot.lavalink.get_tracks(query=new, node=node) @@ -1429,7 +1429,8 @@ async def get_player(self, guild, create: bool = False, user_id: int = None): if settings.defaultnode and guild.get_member(int(settings.defaultnode)): user_id = settings.defaultnode - node = self.bot.lavalink.node_manager.get_node_by_name(str(user_id)) + node = self.bot.lavalink.node_manager.get_node_by_name( + str(user_id)) if create: player = self.bot.lavalink.players.create( @@ -5454,6 +5455,7 @@ async def hostconfig_set(self, ctx, ip: str, password: str = "youshallnotpass", if ctx.guild and ip: try: await ctx.message.delete() + # TODO: Translations await ctx.send('Please use this command in DMs for your privacy!') except discord.HTTPException: pass @@ -5464,7 +5466,7 @@ async def hostconfig_set(self, ctx, ip: str, password: str = "youshallnotpass", 'User-Id': str(self.bot.user.id) } - msg = await ctx.send('Connecting...') + msg = await ctx.send('Connecting...') # TODO: Translations try: ws = await self.session.ws_connect('ws://{}:{}'.format(ip, port), headers=headers) @@ -5473,6 +5475,7 @@ async def hostconfig_set(self, ctx, ip: str, password: str = "youshallnotpass", await ws.close() + # TODO: Translations await msg.edit(content="Successfully connected to the server!") settings = await SettingsDB.get_instance().get_glob_settings() @@ -5488,7 +5491,8 @@ async def hostconfig_set(self, ctx, ip: str, password: str = "youshallnotpass", 'resume_timeout': 600 } - node = self.bot.lavalink.node_manager.get_node_by_name(str(ctx.author.id), True) + node = self.bot.lavalink.node_manager.get_node_by_name( + str(ctx.author.id), True) if node: await self.bot.lavalink.node_manager.destroy_node(node) @@ -5519,17 +5523,23 @@ async def hostconfig_now(self, ctx): settings = await SettingsDB.get_instance().get_glob_settings() if str(ctx.author.id) not in settings.custom_hosts.keys(): return await ctx.send('No config currently registered! Use `{}hostconfig set` to set one.'.format(get_server_prefixes(self.bot, ctx.guild))) - if ctx.guild: - await ctx.send('Please check your DMs!') info = settings.custom_hosts[str(ctx.author.id)] + # TODO: Translations embed = discord.Embed(description="Your server configuration") embed.add_field(name='IP', value=info['host'], inline=False) embed.add_field(name='Password', value=info['password'], inline=False) embed.add_field(name='Port', value=info['port'], inline=False) - node = self.bot.lavalink.node_manager.get_node_by_name(str(ctx.author.id)) - text = "Server is currently " + ("connected" if node else "disconnected") + node = self.bot.lavalink.node_manager.get_node_by_name( + str(ctx.author.id)) + text = "Server is currently " + \ + ("connected" if node else "disconnected") embed.set_footer(text=text) - await ctx.author.send(embed=embed) + try: + await ctx.author.send(embed=embed) + except discord.HTTPException: + return await ctx.send(get_str(ctx, "cant-send-pm")) + if ctx.guild: + await ctx.send(get_str(ctx, "message-send-to-mp")) @checks.has_permissions(manage_guild=True) @hostconfig.command(name="link", aliases=["connect", "setserver"]) @@ -5546,12 +5556,12 @@ async def hostconfig_link(self, ctx): return await ctx.send("Your node is not linked to this server anymore.") settings_glob = await SettingsDB.get_instance().get_glob_settings() if str(ctx.author.id) not in settings_glob.custom_hosts.keys(): + # TODO: Translations return await ctx.send('No config currently registered!') settings.defaultnode = str(ctx.author.id) await SettingsDB.get_instance().set_guild_settings(settings) await ctx.send("Your node is now linked to this server.") - @hostconfig.command(name="switch", aliases=["move", "change"]) @commands.cooldown(rate=1, per=15, type=commands.BucketType.guild) async def hostconfig_switch(self, ctx): @@ -5564,7 +5574,8 @@ async def hostconfig_switch(self, ctx): if str(ctx.author.id) not in settings.custom_hosts.keys(): return await ctx.send('No config currently registered!') info = settings.custom_hosts[str(ctx.author.id)] - node = self.bot.lavalink.node_manager.get_node_by_name(str(ctx.author.id)) + node = self.bot.lavalink.node_manager.get_node_by_name( + str(ctx.author.id)) if not node: return await ctx.send("Your node doesn't seem to be connected!") if ctx.guild.id not in self.bot.lavalink.players.players: @@ -5575,9 +5586,11 @@ async def hostconfig_switch(self, ctx): is_user = True if player.node == node: await ctx.send('This player is already on your node! Moving it to another node...') - node = self.bot.lavalink.node_manager.find_ideal_node(str(ctx.guild.id)) + node = self.bot.lavalink.node_manager.find_ideal_node( + str(ctx.guild.id)) is_user = False if not node: + # TODO: Translations return await ctx.send('No other node available!') await ctx.send('Moving...') await player.change_node(node) diff --git a/cogs/useful.py b/cogs/useful.py index 2849cc3..37c0eab 100644 --- a/cogs/useful.py +++ b/cogs/useful.py @@ -684,7 +684,8 @@ async def serverinfo(self, ctx, *, guild=None): member = ctx.guild.get_member(int(settings.defaultnode)) if member: # TODO: Translations - data.add_field(name='Default music node', value=f"Hosted by {member}", inline=False) + data.add_field(name='Default music node', + value=f"Hosted by {member}", inline=False) if guild.icon_url: data.set_author(name=guild.name, url=guild.icon_url) @@ -1004,7 +1005,8 @@ async def pbar(self, ctx, *, bar): settings.donation['bar'] = bar await SettingsDB.get_instance().set_glob_settings(settings) try: - await self.bot.cogs['Update'].message_status(bypass=True) # try to update status + # try to update status + await self.bot.cogs['Update'].message_status(bypass=True) except KeyError: pass await ctx.send(":ok_hand:") @@ -1867,7 +1869,8 @@ async def settings(self, ctx, *, guild=None): member = ctx.guild.get_member(int(settings.defaultnode)) if member: # TODO: Translations and move it - msg.append(struct.format("Default music node", f'Hosted by {member}')) + msg.append(struct.format( + "Default music node", f'Hosted by {member}')) embed.add_field(name=get_str(ctx, "cmd-settings-player"), value='\n'.join(msg), inline=False)