Merge remote-tracking branch 'origin/release-1.0.0' into release-1.0.0

release-1.0.0
DustyP 8 years ago
commit 66cbaffc7a

@ -62,7 +62,7 @@ class Geeksbot(commands.Bot):
self.voice_chans = {} self.voice_chans = {}
self.spam_list = {} self.spam_list = {}
self.owner_id = 351794468870946827 self.owner_id = 351794468870946827
self.__version__ = '1.0.0b' self.__version__ = 'v1.0.0b2'
self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key']) self.gcs_service = build('customsearch', 'v1', developerKey=self.bot_secrets['google_search_key'])
self.tpe = futures.ThreadPoolExecutor() self.tpe = futures.ThreadPoolExecutor()
self.geo_api = '2d4e419c2be04c8abe91cb5dd1548c72' self.geo_api = '2d4e419c2be04c8abe91cb5dd1548c72'

@ -147,54 +147,59 @@ class Admin:
@add.command(name='allowed_channels', aliases=['channel', 'ac']) @add.command(name='allowed_channels', aliases=['channel', 'ac'])
async def _allowed_channels(self, ctx, *, channels): async def _allowed_channels(self, ctx, *, channels):
"""Allows Admin to restrict what channels Geeksbot is allowed to access """Allows Admin to restrict what channels Geeksbot is allowed to access
This only takes effect if channel_lockdown is enabled.""" This only takes effect if channel_lockdown is enabled.
If one of the channels passed is not found then it is ignored."""
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()
for channel in channels: channels_add = list()
chnl = discord.utils.get(ctx.guild.channels, name=channel) admin_log.info(channels)
if chnl is None: allowed_channels = await self.bot.db_con.fetchval('select allowed_channels from guild_config '
await ctx.send(f'{channel} is not a valid text channel in this guild.') 'where guild_id = $1', ctx.guild.id)
else: if allowed_channels == 'null':
admin_log.info('Chan found') allowed_channels = None
if await self.bot.db_con.fetchval('select allowed_channels from guild_config '
'where guild_id = $1', ctx.guild.id): channels = [discord.utils.get(ctx.guild.channels, name=channel)
if chnl.id in json.loads(await self.bot.db_con.fetchval('select allowed_channels ' for channel in channels if channel is not None]
'from guild_config '
'where guild_id = $1', if allowed_channels and channels:
ctx.guild.id)): allowed_channels = [int(channel) for channel in json.loads(allowed_channels)]
admin_log.info('Chan found in config') existing_channels = [channel for channel in channels if channel.id in allowed_channels]
await ctx.send(f'{channel} is already in the list of allowed channels. Skipping...') channels_add = [channel for channel in channels if channel.id not in allowed_channels]
else: allowed_channels += [channel.id for channel in channels if channel.id not in allowed_channels]
admin_log.info('Chan not found in config') await self.bot.db_con.execute('update guild_config set allowed_channels = $2 where guild_id = $1',
allowed_channels = json.loads(await self.bot.db_con.fetchval('select allowed_channels ' ctx.guild.id, json.dumps(allowed_channels))
'from guild_config ' elif channels:
'where guild_id = $1', admin_log.info('Config is empty')
ctx.guild.id))\ allowed_channels = [channel.id for channel in channels]
.append(chnl.id) await self.bot.db_con.execute('update guild_config set allowed_channels = $2 '
await self.bot.db_con.execute('update guild_config set allowed_channels = $2 ' 'where guild_id = $1', ctx.guild.id,
'where guild_id = $1', ctx.guild.id, allowed_channels) json.dumps(allowed_channels))
added = f'{added}\n{channel}' else:
else: await ctx.send('None of those are valid text channels for this guild.')
admin_log.info('Chan not found in config') return
allowed_channels = [chnl.id]
await self.bot.db_con.execute('update guild_config set allowed_channels = $2 ' if existing_channels:
'where guild_id = $1', ctx.guild.id, allowed_channels) channel_str = '\n'.join([str(channel.name) for channel in existing_channels])
added = f'{added}\n{channel}' await ctx.send(f'The following channels were skipped because they are already in the config:\n'
if added != '': f'{channel_str}\n')
await ctx.send(f'The following channels have been added to the allowed channel list: {added}') if channels_add:
channel_str = '\n'.join([str(channel.name) for channel in channels_add])
await ctx.send('The following channels have been added to the allowed channel list:\n'
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.')
else: else:
await ctx.send('This command must be run from inside a guild.') await ctx.send('This command must be run from inside a guild.')
@commands.command() # TODO Fix view_code
@commands.command(hidden=True)
@commands.is_owner() @commands.is_owner()
async def view_code(self, ctx, code_name): async def view_code(self, ctx, code_name):
pag = utils.Paginator(self.bot, prefix='```py', suffix='```') pag = utils.Paginator(self.bot, prefix='```py', suffix='```')
pag.add(inspect.getsource(self.bot.get_command(code_name).callback)) pag.add(inspect.getsource(self.bot.all_commands[code_name].callback))
for page in pag.pages(): for page in pag.pages():
await ctx.send(page) await ctx.send(page)

@ -57,7 +57,7 @@ class Fun:
else: else:
await ctx.send(f'{member.display_name} is not infected...') await ctx.send(f'{member.display_name} is not infected...')
@commands.command() @commands.command(hidden=True)
@commands.is_owner() @commands.is_owner()
async def print_infections(self, ctx): async def print_infections(self, ctx):
await ctx.author.send(f'```{self.bot.infected}```') await ctx.author.send(f'```{self.bot.infected}```')

@ -41,23 +41,21 @@ class Git:
pag.add('\uFFF7\n\uFFF8') pag.add('\uFFF7\n\uFFF8')
pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command('git show --stat | ' pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command('git show --stat | '
'sed "s/.*@.*[.].*/ /g"')), 10)) 'sed "s/.*@.*[.].*/ /g"')), 10))
msg = await ctx.send('Starting Book') book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
book = Book(pag, (msg, ctx.channel, self.bot, ctx.message))
await book.create_book() await book.create_book()
@git.command() @git.command()
@commands.is_owner() @commands.is_owner()
async def status(self, ctx): async def status(self, ctx):
pag = Paginator(max_line_length=60, max_lines=30, max_chars=1014) pag = Paginator(self.bot, max_line_length=44, max_lines=30, embed=True)
em = discord.Embed(style='rich', pag.set_embed_meta(title='Git Status',
title=f'Git Pull', color=self.bot.embed_color,
color=embed_color) thumbnail=f'{ctx.guild.me.avatar_url}')
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
result = await asyncio.wait_for(self.bot.loop.create_task(run_command('git status')), 10) result = await asyncio.wait_for(self.bot.loop.create_task(run_command('git status')), 10)
pag.add(result) pag.add(result)
for page in pag.pages(): book = Book(pag, (None, ctx.channel, self.bot, ctx.message))
em.add_field(name='', value=f'{page}') await book.create_book()
await ctx.send(embed=em)
def setup(bot): def setup(bot):

@ -18,10 +18,10 @@ class Patreon:
async def get_patreon_links(self, ctx, target: discord.Member=None): async def get_patreon_links(self, ctx, target: discord.Member=None):
"""Prints Patreon information for creators on the server.""" """Prints Patreon information for creators on the server."""
if await self.bot.db_con.fetchval('select patreon_enabled from guild_config where guild_id = $1', ctx.guild.id): if await self.bot.db_con.fetchval('select patreon_enabled from guild_config where guild_id = $1', ctx.guild.id):
patreon_info = await self.bot.db_con.fetchval('select patreon_message,patreon_links from guild_config ' patreon_info = await self.bot.db_con.fetchrow('select patreon_message,patreon_links from guild_config '
'where guild_id = $1', ctx.guild.id) 'where guild_id = $1', ctx.guild.id)
message = patreon_info[0].replace('\\n', '\n') message = patreon_info['patreon_message'].replace('\\n', '\n')
patreon_links = json.loads(patreon_info[1]) patreon_links = json.loads(patreon_info['patreon_links'])
for key in patreon_links: for key in patreon_links:
message = message + '\n{0}: {1}'.format(key, patreon_links[key]) message = message + '\n{0}: {1}'.format(key, patreon_links[key])
if target is None: if target is None:

@ -254,17 +254,12 @@ class Utils:
if channel: if channel:
chan = discord.utils.get(ctx.guild.channels, id=channel) chan = discord.utils.get(ctx.guild.channels, id=channel)
msg = '' msg = ''
admin_roles = []
roles = await self.bot.db_con.fetchval(f'select admin_roles,rcon_admin_roles from guild_config ' roles = await self.bot.db_con.fetchval(f'select admin_roles,rcon_admin_roles from guild_config '
f'where $1', ctx.guild.id) f'where guild_id = $1', ctx.guild.id)
request_id = await self.bot.db_con.fetchval(f'select id from admin_requests where ' request_id = await self.bot.db_con.fetchval(f'select id from admin_requests where '
f'issuing_member_id = $1 and request_time = $2', f'issuing_member_id = $1 and request_time = $2',
ctx.author.id, ctx.message.created_at) ctx.author.id, ctx.message.created_at)
for item in roles: admin_roles = json.loads(roles).values()
i = json.loads(item)
for j in i:
if i[j] not in admin_roles:
admin_roles.append(i[j])
for role in admin_roles: for role in admin_roles:
msg = '{0} {1}'.format(msg, discord.utils.get(ctx.guild.roles, id=role).mention) msg = '{0} {1}'.format(msg, discord.utils.get(ctx.guild.roles, id=role).mention)
msg += f"New Request ID: {request_id} " \ msg += f"New Request ID: {request_id} " \
@ -372,7 +367,7 @@ class Utils:
except ValueError: except ValueError:
await ctx.send(f'{request_id} is not a valid request id.') await ctx.send(f'{request_id} is not a valid request id.')
else: else:
request = await self.bot.db_con.fetchval(f'select * from admin_requests where id = $1', request = await self.bot.db_con.fetchrow(f'select * from admin_requests where id = $1',
request_id) request_id)
if request: if request:
if request[3] == ctx.guild.id: if request[3] == ctx.guild.id:
@ -704,7 +699,7 @@ class Utils:
@commands.command(name='help', aliases=['h']) @commands.command(name='help', aliases=['h'])
@commands.cooldown(1, 5, commands.BucketType.user) @commands.cooldown(1, 5, commands.BucketType.user)
async def custom_help(self, ctx, *, command: str=None): async def custom_help(self, ctx, *, command: str=None):
pag = utils.Paginator(self.bot, embed=True, max_line_length=48) pag = utils.Paginator(self.bot, embed=True, max_line_length=40)
prefixes = await self.bot.get_custom_prefix(self.bot, ctx.message) prefixes = await self.bot.get_custom_prefix(self.bot, ctx.message)
if isinstance(prefixes, list): if isinstance(prefixes, list):
prefixes = ', '.join(prefixes) prefixes = ', '.join(prefixes)
@ -732,7 +727,7 @@ class Utils:
for com in sorted(command.commands, key=lambda x: x.name): for com in sorted(command.commands, key=lambda x: x.name):
if not com.hidden: if not com.hidden:
pag.add(f'# {com.name}') pag.add(f'# {com.name}')
pag.add(f'> {com.short_doc}', truncate=True) pag.add(f'> {com.short_doc}', truncate=True)
except AttributeError as e: except AttributeError as e:
pass pass
pag.add('\uFFF7') pag.add('\uFFF7')

Loading…
Cancel
Save