Beispiel #1
0
def setup(bot: Bot) -> None:
    conn.cursor().execute("""
            CREATE TABLE IF NOT EXISTS Roles (
                RoleID INTEGER PRIMARY KEY,
                GuildID INTEGER NOT NULL
            ); 
    """)
    bot.add_cog(Roles(bot))
Beispiel #2
0
def setup(bot: Bot) -> None:
    conn.cursor().execute("""
            CREATE TABLE IF NOT EXISTS Character (
                ID          INTEGER PRIMARY KEY     AUTOINCREMENT,
                PlayerID    INTEGER NOT NULL,
                Name        TEXT    NOT NULL,
                Description TEXT    DEFAULT 'No description'
            )
    """);
    bot.add_cog(Characters(bot))    
Beispiel #3
0
    async def set_role(self, ctx, roleName=None):
        if (roleName == None):
            await ctx.send("Please specify a role!")
            return

        member = ctx.message.author
        role = getRole(ctx, roleName)

        if (role == None):
            await ctx.send(f"No such role: `{roleName}`")
            return

        cur = conn.cursor()
        cur.execute("""
            SELECT * FROM Roles
            WHERE RoleID == ?;
        """, (role.id,))

        if (len(cur.fetchall()) == 0):
            await ctx.send(f"I cant do anything to {role}!")

        elif (role in member.roles):
            await member.remove_roles(role)
            await ctx.send(f"Removed the {role} role from {member}")

        else:
            await member.add_roles(role)
            await ctx.send(f"Gave the {role} role to {member}")
Beispiel #4
0
    async def common_role(self, ctx: Context, roleName=None):
        if (roleName):
            await ctx.send("Please specify a role!")
            return

        role = getRole(ctx, roleName)
        if (role == None):
            await ctx.send(f"No such role: `{roleName}`")
            return

        cur = conn.cursor()
        cur.execute("SELECT * FROM Roles WHERE RoleID == {role.id}'")

        if (len(cur.fetchall()) > 0):
            cur.execute(f"""
                DELETE FROM Roles
                WHERE RoleID == ?
            """, (role.id,))
            await ctx.send(f"Removed {role} from the common roles")
        else:
            cur.execute("""
                INSERT INTO Roles (RoleID, GuildID, Authority) VALUES 
                (?, ?)
            """, (role.id, ctx.guild.id))
            await ctx.send(f"Added {role} to the common roles")

        conn.commit()
Beispiel #5
0
    async def add_character(self, ctx, argc):
        if (len(argc) < 2):
            await ctx.send("Usage: character add [Character Name]")
            return

        name = " ".join(argc)
        cur = conn.cursor()
        cur.execute("""
            INSERT INTO Character (PlayerID, Name)
            VALUES (?, ?)
        """, (ctx.message.author.id, name,))

        await ctx.send(f"Added {name} to {ctx.message.author}'s characters!")
        conn.commit()
Beispiel #6
0
    async def del_character(self, ctx, argc):
        if (len(argc) < 2):
            await ctx.send("Usage: character remove [Character Name]")
            return

        name = " ".join(argc)
        cur = conn.cursor()
        cur.execute("""
            DELETE FROM Character
            WHERE PlayerID == ? AND Name == ?
        """, (ctx.message.author.id, name,))

        if (cur.fetchone() != None):
            await ctx.send(f"{name} has been deleted!")
        else:
            await ctx.send(f"You don't have a character named {name}!")
        conn.commit()
Beispiel #7
0
    async def get_character(self, ctx, argc):
        if (len(argc) == 0):
            await ctx.send("Please give me a character name!")
            return

        name = " ".join(argc)
        cur = conn.cursor()
        cur.execute(f"""
            SELECT Description FROM Character
            WHERE PlayerID == ? AND Name == ?
        """, (ctx.message.author.id, name))

        character = cur.fetchone()
        
        if (character == None):
            await ctx.send(f"No character named {name}!")
        else:
            await ctx.send(f">>> **{name}**\n{character[0]}")
Beispiel #8
0
    async def get_roles(self, ctx):
        #TODO Format output
        guild = ctx.guild
        cur = conn.cursor()

        cur.execute("""
            SELECT RoleID FROM Roles
            WHERE GuildID == ?;
        """, (guild.id,))

        roleIDs = cur.fetchall()

        if (len(roleIDs) == 0):
            await ctx.send(f"No available roles in {guild}")
        else:
            roleIDs = [r[0] for r in roleIDs]
            roles = [r for r in guild.roles if r.id in roleIDs]
            await ctx.send(roles)
Beispiel #9
0
    async def view_characters(self, ctx, member: Member):
        if (member == None):
            await ctx.send("I don't know who that is...")
            return

        cur = conn.cursor()
        cur.execute("""
            SELECT Name FROM Character
            WHERE PlayerID == ?
        """, (member.id,))

        chars = cur.fetchall()
        out = ""

        if (len(chars) > 0):
            out += f">>> {member}'s characters are:\n "
            for c in chars:
                out += c[0] + "\n"
            out.strip()
        else:
            out += f"{member} has no characters!"

        await ctx.send(out)