Ejemplo n.º 1
0
    async def _request_wrap(self, ctx, role, date=''):
        auth = ctx.message.author
        chan = ctx.message.channel
        serv = ctx.message.guild

        # 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 ctx.send(error("could not find role, ask a mod to create it")
                           )
            return

        # get list of public roles
        available_roles = self.conf.get(guild_id, {}).get('pub_roles', [])
        role_id = str(role.id)
        guild_id = str(serv.id)

        if role_id in available_roles:  # if role is a public role,
            await auth.add_roles(role)  #   give it
            await ctx.send(ok('you now have that role'))
        else:  # otherwise don't
            await ctx.send(
                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, str(auth.id),
                                  str(chan.id), guild_id)

            await self.bot.get_cog('HeapCog').push(role_end, self.bot)
Ejemplo n.º 2
0
    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.guild
        role = dh.get_role(serv, role)
        guild_id = str(serv.id)
        role_id = str(role.id)

        # if user failed to find specify role, complain
        if not role:
            await ctx.send('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(guild_id, {}).get('pub_roles', [])
        user_roles = discord.utils.find(lambda r: str(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 auth.remove_roles(role)
            await ctx.send(ok('you no longer have that role'))
        else:
            await ctx.send(error('I\'m afraid that I can\'t remove that role'))
Ejemplo n.º 3
0
    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.guild
        role = dh.get_role(serv, role)
        guild_id = str(serv.id)
        role_id = str(role.id)
        available_roles = self.conf.get(guild_id, {}).get('pub_roles', [])

        # if user failed to specify role, complain
        if not role:
            await ctx.send('Please specify a valid role')
            return

        if guild_id not in self.conf:
            self.conf[guild_id] = {'pub_roles': []}
            self.conf.save()
        elif 'pub_roles' not in self.conf[guild_id]:
            self.conf[guild_id]['pub_roles'] = []
            self.conf.save()

        if role_id in available_roles:  # if role is found, remove and report
            self.conf[guild_id]['pub_roles'].remove(guild_id)
            self.conf.save()
            await ctx.send(ok('role removed from public list'))
        else:  # if role is not in server, just report
            await ctx.send(error('role is not in the list'))
Ejemplo n.º 4
0
    async def end(self, bot):
        guld = bot.get_guild(self.serv_id)  # get server info
        auth = dh.get_user(guld, self.auth_id)  # get author info
        chan = dh.get_channel(guld, self.chan_id)  # get channel info
        role = dh.get_role(guld, self.role_id)  # get role info

        # remove the role
        await auth.remove_roles(role)

        # create a message, and report that role has been removed
        msg = f"{auth.mention}: role {role.name} has been removed"
        await chan.send(msg)
Ejemplo n.º 5
0
  async def end(self, bot, index=-1):
    '''
    Ends the timeout associated with this object
    '''
    # get data objects
    serv   = bot.get_guild(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 member.edit(roles=roles)
    await chan.send('{}: your time out is up, permissions restored'.format(
        member.mention
    ))
Ejemplo n.º 6
0
    async def _add_wrap(self, ctx, role):
        serv = ctx.message.guild

        # 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 serv.create_role(name=role_str, mentionable=True)
            await ctx.send(ok(f'New role created: {role_str}'))

        # if still no role, report and stop
        if not role:
            await ctx.send(error("could not find or create role role"))
            return

        guild_id = str(serv.id)
        role_id = str(role.id)

        # The @everyone role (also @here iiuc) cannot be given/taken
        if role.is_everyone:
            await ctx.send(error('umm... no'))
            return

        if guild_id not in self.conf:  # if server does not have a list yet create it
            self.conf[guild_id] = {'pub_roles': [role_id]}
        elif 'pub_roles' not in self.conf[guild_id]:  # if list is corruptted
            self.conf[guild_id]['pub_roles'] = [role_id]  # fix it
        elif role_id in self.conf[guild_id][
                'pub_roles']:  # if role is already there
            await ctx.send('role already in list')  #   report and stop
            return
        else:  # otherwise add it to the list and end
            self.conf[guild_id]['pub_roles'].append(role_id)

        # save any changes to config file, and report success
        self.conf.save()
        await ctx.send(ok('role added to public role list'))