fixed bug in _allowed_channels

release-1.0.0
DustyP 8 years ago
parent 512588a34c
commit 8c7f33c166

@ -152,7 +152,7 @@ class Admin:
if ctx.guild: if ctx.guild:
if await checks.is_admin(self.bot, ctx): if await checks.is_admin(self.bot, ctx):
channels = channels.lower().replace(' ', '').split(',') channels = channels.lower().replace(' ', '').split(',')
added = '' existing_channels = list()
admin_log.info(channels) admin_log.info(channels)
allowed_channels = await self.bot.db_con.fetchval('select allowed_channels from guild_config ' allowed_channels = await self.bot.db_con.fetchval('select allowed_channels from guild_config '
'where guild_id = $1', ctx.guild.id) 'where guild_id = $1', ctx.guild.id)
@ -164,6 +164,7 @@ class Admin:
if allowed_channels and channels: if allowed_channels and channels:
allowed_channels = [int(channel) for channel in json.loads(allowed_channels)] allowed_channels = [int(channel) for channel in json.loads(allowed_channels)]
existing_channels = [channel for channel in channels if channel.id in allowed_channels]
channels = [channel.id for channel in channels if channel.id not in allowed_channels] channels = [channel.id for channel in channels if channel.id not in allowed_channels]
allowed_channels += channels allowed_channels += channels
await self.bot.db_con.execute('update guild_config set allowed_channels = $2 where guild_id = $1', await self.bot.db_con.execute('update guild_config set allowed_channels = $2 where guild_id = $1',
@ -178,10 +179,14 @@ class Admin:
await ctx.send('None of those are valid text channels for this guild.') await ctx.send('None of those are valid text channels for this guild.')
return return
if existing_channels:
channel_str = '\n'.join([str(channel.name) for channel in existing_channels])
await ctx.send(f'The following channels were skipped because they are already in the config:\n'
f'{channel_str}\n')
if channels: if channels:
channel_str = '\n'.join([str(channel.name) for channel in channels]) channel_str = '\n'.join([str(channel.name) for channel in channels])
await ctx.send('The following channels have been added to the allowed channel list: ' await ctx.send('The following channels have been added to the allowed channel list:\n'
f'{channel_str}') f'{channel_str}\n')
await ctx.message.add_reaction('') await ctx.message.add_reaction('')
else: else:
await ctx.send(f'You are not authorized to run this command.') await ctx.send(f'You are not authorized to run this command.')

Loading…
Cancel
Save