Beispiel #1
0
    async def joinable(self, ctx, *, role_name):
        """
        Toggles whether a role is joinable
        """
        if role_name[0] == '"' and role_name[-1] == '"':
            role_name = role_name[1:-1]
        role = get_role(ctx.guild.id, role_name)
        if role is None:
            em = discord.Embed(
                title="Error",
                description="Could not find role {}".format(role_name),
                color=red)
            return await ctx.channel.send(embed=em)
        if role['is_joinable'] == 1:
            update_query = "UPDATE `gssp`.`roles` SET `is_joinable`='0' WHERE `role_id`=%s;"
            text = "not joinable"
        else:
            update_query = "UPDATE `gssp`.`roles` SET `is_joinable`='1' WHERE `role_id`=%s;"
            text = "joinable"
        cursor.execute(update_query, (role['role_id'], ))
        em = discord.Embed(title="Success",
                           description="Set {} ({} to {}".format(
                               role['role_name'], role['role_id'], text),
                           color=green)
        cnx.commit()

        await ctx.channel.send(embed=em)
Beispiel #2
0
 def generate_overwrites(old_channel):
     overwrites = dict()
     for overwrite in old_channel['overwrites']:
         allow = discord.Permissions(overwrite['allow_permission'])
         deny = discord.Permissions(overwrite['deny_permission'])
         permission_pair = discord.PermissionOverwrite.from_pair(
             allow, deny)
         target = None  # we do this incase down the road there's a new type of grantee we haven't handled
         # if a user isn't in the new server, we can't add overwrites for them
         if overwrite['grantee']['type'] == "User":
             target = clone_target.get_member(
                 overwrite['grantee']['id'])
         # this is the code which will convert the old_id in the overwrite into the new_id
         elif overwrite['grantee']['type'] == "Role":
             role = get_role(old_id=overwrite['grantee']['old_id'])
             if role is not None:
                 target = clone_target.get_role(role['new_id'])
             else:
                 old_role = ctx.guild.get_role(
                     overwrite['grantee']['old_id'])
                 if old_role.name == "@everyone":
                     target = clone_target.default_role
                 else:
                     print(
                         "Could not find new role pair for old role with ID {}"
                         .format(overwrite['grantee']['old_id']))
         if target is not None:
             overwrites[target] = permission_pair
     return overwrites
Beispiel #3
0
 async def output_join_role(self, ctx, role_name):
     """Join a ping group / role given a name"""
     if role_name[0] == '"' and role_name[-1] == '"':
         role_name = role_name[1:-1]
     role = get_role(ctx.guild.id, role_name)
     try:
         if not role['is_joinable']:
             return await ctx.channel.send(
                 "**FAIL** : This role cannot currently be joined.")
     except TypeError:
         return await ctx.channel.send(
             "**FAIL** : Could not find role - are you sure this isn't a Discord based role?"
         )
     cur_members = role['members']
     if ctx.author.id in cur_members:
         return await ctx.channel.send(
             "**FAIL** : You are already a member of this role!")
     cur_members.append(ctx.author.id)
     updated_role = DbRole(role['role_id'],
                           role['role_name'],
                           role['is_pingable'],
                           members=cur_members)
     updated_role.save_members()
     return await ctx.channel.send(
         "**SUCCESS** : You have now joined {}".format(role['role_name']))
Beispiel #4
0
 async def pingable(self, ctx, *, role_name):
     """Change a role from not pingable to pingable or vice versa"""
     if role_name[0] == '"' and role_name[-1] == '"':
         role_name = role_name[1:-1]
     role = get_role(ctx.guild.id, role_name)
     if role is None:
         return await ctx.channel.send(
             embed=discord.Embed(title='Error',
                                 description='Could not find that role',
                                 color=red))
     if role['is_pingable'] == 1:
         update_query = "UPDATE `gssp`.`roles` SET `is_pingable`='0' WHERE `role_id`=%s AND `guild_id` = %s;"
         text = "not pingable"
     else:
         update_query = "UPDATE `gssp`.`roles` SET `is_pingable`='1' WHERE `role_id`=%s AND `guild_id` = %s;"
         text = "pingable"
     cursor.execute(update_query, (
         role['role_id'],
         ctx.guild.id,
     ))
     cnx.commit()
     await ctx.channel.send(
         embed=discord.Embed(title="SUCCESS",
                             description="Set {} ({}) to {}".format(
                                 role['role_name'], role['role_id'], text),
                             color=green))
    async def rename(self, ctx, role_name=None, new_name=None):
        """
        Changes the name of a role

        Params:
            role_name : name of the role to be changed
            new_name : name the role should be
        """

        # Removes excess spaces at the beginning of a role name
        if role_name[0] == '"' and role_name[-1] == '"':
            role_name = role_name[1:-1]

        role_check = get_role(ctx.guild.id, role_name)
        em = discord.Embed(title='Success',
                           description="Renamed {} to {}".format(
                               role_name, new_name),
                           color=green)
        if role_check is None:
            em = discord.Embed(
                title="Error",
                description="{} is not in the DB".format(role_name),
                color=red)
        else:
            query = "UPDATE `gssp`.`roles` SET `role_name` = %s WHERE (`role_name` = %s AND `guild_id` = %s);"
            cursor.execute(query, (new_name, role_name, ctx.guild.id))
            cnx.commit()
        return await ctx.channel.send(embed=em)
Beispiel #6
0
    async def ping(self, ctx, *, role_name):
        """
        Usage: ??ping role_name

        To find out more about how the bot based roles work, run the command ?about_pings
        """
        if role_name[0] == '"' and role_name[-1] == '"':
            role_name = role_name[1:-1]
        role = get_role(ctx.guild.id, role_name)
        if role is None:
            return await ctx.channel.send(embed=discord.Embed(
                title="Fail", description="Cannot find that role.", color=red))
        if role['is_pingable']:
            public_message = ""
            for member in role['members']:
                user_db = get_user(member)
                # get_member is used instead of get_user as User doesn't
                user_discord = ctx.guild.get_member(member)
                if user_discord is not None:
                    # not have a status property, only Members
                    if user_discord.status != discord.Status.offline or (
                            user_db['ping_online_only'] != 1):
                        if user_db['ping_public'] == 1:
                            public_message += user_discord.mention + " "
                        else:
                            em = Embed(title="Ping!", colour=gold)
                            em.add_field(name="Message",
                                         value=str(ctx.message.content),
                                         inline=False)
                            em.add_field(name="Channel", value=ctx.channel)
                            em.add_field(name="Role", value=role_name)
                            em.add_field(name="Time",
                                         value=ctx.message.created_at)
                            em.add_field(name="Pinger", value=str(ctx.author))
                            em.add_field(
                                name="Click here to jump to message",
                                value="https://discordapp.com/channels/{}/{}/{}"
                                .format(ctx.guild.id, ctx.channel.id,
                                        ctx.message.id),
                                inline=False)
                            em.set_footer(text=strings['ping']['help'])
                            await user_discord.send(embed=em)
            if public_message == "":
                return await ctx.channel.send(embed=discord.Embed(
                    title="Sent!",
                    description=
                    "All users have been pinged privately with the message.",
                    color=green))
            else:
                return await ctx.channel.send(
                    public_message +
                    "\n\n **Message**: {} \n **Author:** {}".format(
                        str(ctx.message.content), str(ctx.author.mention)))
        else:
            return await ctx.channel.send("**FAIL** : Role not pingable")
        def get_channel_object_dict(channel):
            if type(channel) == dict:
                return channel  # already converted
            new_overwrites = []
            overwrites = channel.overwrites
            for overwrite in overwrites:
                allow, deny = overwrite[1].pair()
                if type(overwrite[0]) == discord.role.Role:
                    role = get_role(old_id=overwrite[0].id)
                    if role is None:
                        to_append = dict(
                            grantee=dict(old_id=overwrite[0].id, type="Role"))
                    else:
                        to_append = dict(grantee=dict(
                            old_id=role.get('old_id'),
                            new_id=role.get('new_id'),
                            old_name=role.get('old_role', dict()).get('name'),
                            type="Role"))
                else:  # user overwrite
                    to_append = dict(
                        grantee=dict(id=overwrite[0].id, type="User"))
                to_append['allow_permission'] = allow.value
                to_append['deny_permission'] = deny.value
                new_overwrites.append(to_append)
            to_return = dict(id=channel.id,
                             name=channel.name,
                             type=get_channel_type(channel),
                             overwrites=new_overwrites,
                             position=channel.position)
            if to_return['type'] != "Category":
                if channel.category is not None:
                    to_return['category'] = get_channel_object_dict(
                        channel.category)
                else:
                    to_return['category'] = None
                if to_return['type'] == "Text":
                    # do text
                    to_return['topic'] = channel.topic
                    to_return['slowmode_delay'] = channel.slowmode_delay
                    to_return['nsfw'] = channel.nsfw

                elif to_return['type'] == "Voice":
                    # do voice
                    if channel.bitrate > 96000:
                        # Higher bitrates require nitro boosts, which the destination server may not have. Assume not.
                        to_return['bitrate'] = 96000
                    else:
                        to_return['bitrate'] = channel.bitrate
                    to_return['user_limit'] = channel.user_limit
            return to_return
 async def delete(self, ctx, *, role_name):
     """Deletes a role - cannot be undone!"""
     if role_name[0]=='"' and role_name[-1] == '"':
         role_name=role_name[1:-1]
     role_check = get_role(ctx.guild.id, role_name)
     em = discord.Embed(
         title="Success", description="Deleted role {}".format(role_name), color=green)
     if role_check is None:
         em = discord.Embed(
             title="Error", description="{} is not in the DB".format(role_name), color=red)
     else:
         query = "DELETE FROM `gssp`.`roles` WHERE `role_name` = %s AND `guild_id` = %s"
         cursor.execute(query, (role_name, ctx.guild.id))
         cnx.commit()
     return await ctx.channel.send(embed=em)
 async def add(self, ctx, *, role_name):
     """Add a role. Note: by default, it isn't joinable"""
     if role_name[0]=='"' and role_name[-1] == '"':
         role_name=role_name[1:-1]
     role_check = get_role(ctx.guild.id, role_name)
     em = discord.Embed(
         title="Success", description="Created role {}".format(role_name), color=green)
     if role_check is not None:
         em = discord.Embed(
             title="Error", description="Role is already in the DB", color=red)
     else:
         query = "INSERT INTO `gssp`.`roles` (`role_name`, `guild_id`) VALUES (%s, %s);"
         cursor.execute(query, (role_name, ctx.guild.id))
         cnx.commit()
     return await ctx.channel.send(embed=em)
Beispiel #10
0
 async def info(self, ctx, *, role_name):
     if role_name[0] == '"' and role_name[-1] == '"':
         role_name = role_name[1:-1]
     role = get_role(ctx.guild.id, role_name)
     if role is None:
         em = Embed(title="{} does not exist".format(role_name), color=red)
     else:
         em = Embed(title="Information for {}".format(role['role_name']),
                    color=green)
         em.add_field(name="Joinable?",
                      value=str(bool(role['is_joinable'])),
                      inline=True)
         em.add_field(name="Pingable?",
                      value=str(bool(role['is_pingable'])),
                      inline=True)
     em.set_footer(text=strings['ping']['help'])
     await ctx.send(embed=em)
Beispiel #11
0
    async def output_leave_role(self, ctx, role_name):
        if role_name[0] == '"' and role_name[-1] == '"':
            role_name = role_name[1:-1]
        role = get_role(ctx.guild.id, role_name)
        if role is None:
            return await ctx.channel.send(
                "**FAIL** : This role does not exist - are you sure it's not a Discord based role?"
            )
        cur_members = role['members']

        if ctx.author.id not in cur_members:
            return await ctx.channel.send(
                "**FAIL** : You are not a member of this role!")

        cur_members.remove(ctx.author.id)
        updated_role = DbRole(role['role_id'],
                              role['role_name'],
                              role['is_pingable'],
                              members=cur_members)
        updated_role.save_members()
        return await ctx.channel.send(
            "**SUCCESS** : You have now left {}".format(role['role_name']))