async def check_guild(self,ctx): ''' check that guild exists in db ''' db = DBase(ctx) results = await db.hunt_get_row('Guild_id') if not results: await ctx.send('Not in this guild.') return results
async def check_hunt_role(self, ctx): ''' check if user has role for current hunt ''' query = 'hunt_role_id' db = DBase(ctx) results = await db.hunt_get_row(query) # guild does not exist in db if not results: await ctx.send('Not in this guild.') return False res = list(results) # no hunt role set if res[0] == 'none': return True else: roleid = int(res[0]) status = discord.utils.get(ctx.author.roles, id=roleid) # role is not correct if not status: await ctx.send('Missing role for current hunt. ') return False # role is correct else: return True
async def login_delete(self, ctx, *, guildID=None): if not guildID: await ctx.send('To use: `!del <guildID>') return db = DBase(ctx) await db.hunt_delete_row(guildID)
async def login_insert(self, ctx, *, query=None): ''' adds a row the hunt db table to initiate puzzle manager commands ''' if not query: await ctx.send('To use: `!ins <guildName> <guildID>') return guildname,guildID = query.split(' ') db = DBase(ctx) await db.hunt_insert_row(guildname,guildID)
async def infofetch(self,ctx): ''' fetch and display team login and links info ''' query = 'hunt_url, hunt_username, hunt_password, hunt_folder, hunt_nexus, hunt_role_id' db = DBase(ctx) results = await db.hunt_get_row(query) if results == 0: await ctx.send('Unexpected error in database query? idk') return # parse results res = list(results) field1 = '**Website**: '+res[0]+'\n' field2 = '**Username**: '+res[1]+'\n' field3 = '**Password**: '+res[2]+'\n' if res[3].find('http') != -1: field4 = '**Folder**: [Link here]('+res[3]+')\n' else: field4 = '**Folder**: '+res[3]+'\n' if res[4].find('http') != -1: field5 = '**Nexus**: [Link here]('+res[4]+')\n' else: field5 = '**Nexus**: '+res[4]+'\n' final = field1+field2+field3+field4+field5 role = res[5] # set up embed embed = discord.Embed( colour=discord.Colour.gold(), description=final ) # role should be either 'none' or numeric ID if role.lower() == 'none': embed.set_footer(text='Role: '+role) await ctx.send(embed=embed) return roleID = int(role) if self.check_role(ctx.author, roleID): roleName = discord.utils.get(ctx.guild.roles, id=roleID) embed.set_footer(text='Role: '+str(roleName)) await ctx.send(embed=embed) else: await ctx.send('Missing role for the current hunt.')
async def infoupdate(self,ctx,query): ''' query: list of arguments to update in form ['field1=text1','field2=text2'] \n ''' # parse argument flags flagdict = self.get_flags() updatestring = f"" for item in query: field,value = item.split('=',1) if field not in flagdict: await ctx.send('Flag does not exist: '+field) return line = f""+flagdict[field]+" = '"+value+"'" if field == 'role': if value.lower() == 'none': line += f", hunt_role = 'none'" else: try: roleID = int(value) except: await ctx.send('Role must be either `none` or id number.') return roleName = discord.utils.get(ctx.guild.roles, id=roleID) line += f", hunt_role = '"+str(roleName)+"'" if item != query[-1]: line += ", " updatestring += line # update db db = DBase(ctx) await db.hunt_update_row(updatestring)
async def hunt_setup(self, ctx): """ This awful sequence of checks and API calls presumably makes sure stuff won't break later """ if not await self.check_hunt_role(ctx): return checks = {} # channel category check category = ctx.message.channel.category.name checks['Category for Hunt'] = '`' + category + '`' # permissions check perms = ctx.channel.category.permissions_for(ctx.me) checks['Manage Messages'] = ':+1:' if perms.manage_messages else ':x:' checks['Manage Channels'] = ':+1:' if perms.manage_channels else ':x:' checks['Add Reactions'] = ':+1:' if perms.add_reactions else ':x:' # db hunt fetch links query = 'hunt_folder, hunt_nexus' db = DBase(ctx) results = await db.hunt_get_row(query) res = list(results) checks['Google Folder'] = '[Link](' + res[0] + ')' if 'http' in res[ 0] else res[0] checks['Nexus Sheet'] = '[Link](' + res[1] + ')' if 'http' in res[ 1] else res[1] # nexus sheet check API call try: nexus_url = await self.nexus_get_url(ctx) nexussheet = self.nexus_get_sheet(nexus_url) checks['Nexus Sheet Access'] = ':+1:' except: checks['Nexus Sheet Access'] = ':x:' # nexus sheet check hardcoded columns try: data_all = nexussheet.get_all_values() headings = data_all[0] lib = self.nexus_sort_columns(headings) checks['Nexus Sheet Format'] = ':+1:' except: checks['Nexus Sheet Format'] = ':x:' # nexus sheet fetch puzzle template link try: template_url = data_all[1][lib['Spreadsheet Link'][0]] checks[ 'Template Sheet'] = '[Link](' + template_url + ')' if 'http' in template_url else template_url except: checks['Template Sheet'] = ':x:' # template sheet check API call try: template_key = max(template_url.split('/'), key=len) gclient = self.drive.gclient() wkbook = gclient.open_by_key(template_key) wkbook.sheet1 checks['Template Sheet Access'] = ':+1:' except: checks['Template Sheet Access'] = ':x:' # format checks topic = '' status = '' for item in checks: topic += item + '\n' status += checks[item] + '\n' # set up embed embed = discord.Embed(title='Checks', colour=discord.Colour(0xfffff0), description='Share hunt folder with\n`' + self.drive.googledata['client_email'] + '`\n') embed.add_field(name='Topic', value=topic, inline=True) embed.add_field(name='Status', value=status, inline=True) await ctx.send(embed=embed)
async def nexus_get_url(self, ctx): query = 'hunt_nexus' db = DBase(ctx) url = await db.hunt_get_row(query) return url[0]