async def _request_wrap(self, ctx, role, date=''): auth = ctx.message.author chan = ctx.message.channel serv = ctx.message.server # attempt to find the role if a string was given, # if not found, stop if type(role) != discord.Role: role = dh.get_role(serv, role) if not role: await self.bot.say( error("could not find role, ask a mod to create it")) return # get list of public roles available_roles = self.conf.get(serv.id, {}).get('pub_roles', []) if role.id in available_roles: # if role is a public role, await self.bot.add_roles(auth, role) # give it await self.bot.say(ok('you now have that role')) else: # otherwise don't await self.bot.say( error('I\'m afraid that I can\'t give you that role')) return if date: # if a timeout was specified end_time = dh.get_end_time(date)[0] role_end = RoleRemove(end_time, role.id, auth.id, chan.id, serv.id) self.heap['heap'].push(role_end) self.heap.save() await role_end.begin(self.bot)
async def _delete(self, ctx, role: str): """ removes role from list of public roles """ # attempt to find specified role and get list of roles in server serv = ctx.message.server role = dh.get_role(serv, role) available_roles = self.conf.get(serv.id, {}).get('pub_roles', []) # if user failed to specify role, complain if not role: await self.bot.say('Please specify a valid role') return if serv.id not in self.conf: self.conf[serv.id] = {'pub_roles': []} self.conf.save() elif 'pub_roles' not in self.conf[serv.id]: self.conf[serv.id]['pub_roles'] = [] self.conf.save() if role.id in available_roles: # if role is found, remove and report self.conf[serv.id]['pub_roles'].remove(role.id) self.conf.save() await self.bot.say(ok('role removed from public list')) else: # if role is not in server, just report await self.bot.say(error('role is not in the list'))
async def _unrequest(self, ctx, role: str): """removes role from requester(if in list)""" # attempt to find role that user specied for removal auth = ctx.message.author serv = ctx.message.server role = dh.get_role(serv, role) # if user failed to find specify role, complain if not role: await self.bot.say('Please specify a valid role') return # get a list of roles that are listed as public and the user roles available_roles = self.conf.get(serv.id, {}).get('pub_roles', []) user_roles = discord.utils.find(lambda r: r.id == role.id, auth.roles) # ONLY remove roles if they are in the public roles list # Unless there is no list, # in which case any of the user's roles can be removed if role.id in available_roles or user_roles: await self.bot.remove_roles(auth, role) await self.bot.say(ok('you no longer have that role')) else: await self.bot.say( error('I\'m afraid that I can\'t remove that role'))
async def end(self, bot, index=-1): ''' Ends the timeout associated with this object ''' # get data objects serv = bot.get_server(self.server_id) chan = dh.get_channel(serv, self.channel_id) member = dh.get_user(serv, self.user_id) roles = [dh.get_role(dh, role_id) for role_id in self.roles] # restore perms and notify user await bot.replace_roles(member, *roles) await bot.send_message( chan, '{}: your time out is up, permissions restored'.format( member.mention))
async def _add_wrap(self, ctx, role): serv = ctx.message.server # find the role, # if it is not found, create a new role role_str = role if type(role) != discord.Role: role = dh.get_role(serv, role_str) if not role: role = await self.bot.create_role(serv, name=role_str, mentionable=True) await self.bot.say(ok(f'New role created: {role_str}')) # if still no role, report and stop if not role: await self.bot.say(error("could not find or create role role")) return # The @everyone role (also @here iiuc) cannot be given/taken if role.is_everyone: await self.bot.say(error('umm... no')) return if serv.id not in self.conf: # if server does not have a list yet create it self.conf[serv.id] = {'pub_roles': [role.id]} elif 'pub_roles' not in self.conf[serv.id]: # if list is corruptted self.conf[serv.id]['pub_roles'] = [role.id] # fix it elif role.id in self.conf[ serv.id]['pub_roles']: # if role is already there await self.bot.say('role already in list') # report and stop return else: # otherwise add it to the list and end self.conf[serv.id]['pub_roles'].append(role.id) # save any changes to config file, and report success self.conf.save() await self.bot.say(ok('role added to public role list'))