Skip to content

Commit

Permalink
PEP8 and some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zenrac committed Feb 29, 2020
1 parent 5cac460 commit 34f72eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
37 changes: 25 additions & 12 deletions cogs/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -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"])
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions cogs/useful.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:")
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 34f72eb

Please sign in to comment.