Example #1
0
def add_all_roles(turtle_id, roles, conn, cur):
    try:
        conn
    except NameError:
                                    conn = tc.get_conn()

    for role in roles:
        sqlStr = "INSERT INTO turtle.turtle_roles(role_id, turtle_id) VALUES (" + str(role.id) + ", " + str(turtle_id) + ");"
        cur.execute(sqlStr)
        conn.commit()
Example #2
0
def check_if_turtle_exists(turtle_id):
    try:
        conn
    except NameError:
        conn = tc.get_conn()
    cur = conn.cursor()
    cur.execute("SELECT * FROM turtle.turtles WHERE discord_id = " + str(turtle_id) + ";")
    result = cur.fetchall()
    
    try:
        print(result[0][0])
        return True
    except IndexError:
        return False
Example #3
0
def get_api_key(discord_id):
    try:
        sqlStr = "SELECT api_key FROM turtle.api_keys WHERE discord_id = " + str(
            discord_id)
        try:
            conn
        except NameError:
            conn = tc.get_conn()
        cur = conn.cursor()
        cur.execute(sqlStr)
        result = cur.fetchall()
        try:
            return result[0][0]
        except:
            return None
    except:
        return None
Example #4
0
 async def get_roster(self, ctx):
     #TODO:  MAKE THIS WORK WHEN THE ROSTER ISN'T BLANK
     for guild in self.bot.guilds:
         if guild.name == 'Siege Turtles':
                print('starting ST')
                for member in guild.members:                       
                     roles = member.roles
                     is_seaguard = False
                     for role in roles:
                         if role.id == 189573500535701504:
                             is_seaguard = True
                     if is_seaguard:
                         print('found seaguard: ' + member.name)
                         turtle = []
                         turtle.append(member.id)
                         turtle.append(member.name)
                         nickname = member.nick
                         if nickname is None:
                             nickname = 'No nickname'
                         turtle.append(nickname)
                         turtle.append(member.discriminator)
                         turtle.append(member.roles)
                         print('checking if exists: ' + member.name)
                         if check_if_turtle_exists(turtle[0]):
                             print('found ' + member.name)#code goes here to update existing turtle
                         else:
                             print('now creating ' + str(turtle[1]))
                             sqlStr = "INSERT INTO turtle.turtles (discord_id, name, nickname, discriminator) VALUES (" + \
                                         str(turtle[0]) + ", '" + turtle[1] + "', '" + turtle[2] + "', '" + turtle[3] + "')"
                             try:
                                 conn
                             except NameError:
                                 conn = tc.get_conn()
                             cur = conn.cursor()
                             cur.execute(sqlStr)
                             conn.commit()
                             print('now adding roles for ' + str(turtle[1]))
                             add_all_roles(turtle[0], turtle[4], conn, cur)
                             print('completed ' + str(turtle[1]))
                             await ctx.send('Finished creating record and roles for: ' + turtle[1])
Example #5
0
    async def clear_api_key(self, ctx):
        await ctx.message.delete()
        out = 'Please confirm that you would like to delete your key (if you change your mind at a later date, you will have to re-set it). ```\nClick ✅ to confirm, ❌ to cancel```'
        try:
            message = await ctx.author.send(out)
            await message.add_reaction('✅')
            await message.add_reaction('❌')
        except discord.Forbidden:
            return await ctx.send(
                'I do not have permission to DM you. Please enable this in the future.'
            )

        def r_check(r, user):
            return user == ctx.author and r.count > 1

        try:
            ans, user = await self.bot.wait_for('reaction_add',
                                                check=r_check,
                                                timeout=300.0)
        except asyncio.TimeoutError:
            await ctx.author.send(
                'Sorry. You took to long to select your choice. If you would like to retry, re-enter the command in a text channel and the bot will re-message you.'
            )
        else:
            if str(ans.emoji) == '✅':
                sqlStr = "DELETE FROM turtle.api_keys WHERE discord_id = " + str(
                    ctx.author.id)
                try:
                    conn
                except NameError:
                    conn = tc.get_conn()
                cur = conn.cursor()
                cur.execute(sqlStr)
                conn.commit()
                await ctx.author.send('Your GW2 API key has been deleted.')
            if str(ans.emoji) == '❌':
                await ctx.author.send(
                    'Your GW2 API key has been preserved...for now.')
        await message.delete()
Example #6
0
    async def set_api_key(self, ctx):
        await ctx.message.delete()
        out = 'Enter the `GW2 API key` that you wish to link with your discord account into the message below then send.\n```md\n# Notes: Your API key will be saved to an online database and linked to your discord account. You only need to update your API code if you would like to change permissions. \nOnly bot administers will have access to the database [Rev, Renay]. \n# You may choose to limit your permissions for your provided API key, but this may block some bot functionality.\nTo get a GW2 API Key, go here: https://account.arena.net/applications.```'
        try:
            message = await ctx.author.send(out)
        except discord.Forbidden:
            return await ctx.send(
                'I do not have permission to DM you. Please enable this in the future.'
            )

        def m_check(m):
            return m.author == ctx.author and m.channel == message.channel

        try:
            ans = await self.bot.wait_for('message',
                                          check=m_check,
                                          timeout=300.0)
        except asyncio.TimeoutError:
            await ctx.author.send(
                'Sorry. You took to long to enter your key. If you would like to retry, re-enter the command in a text channel and the bot will re-message you.'
            )
        else:
            api_key = ans.content
            discord_id = ctx.author.id
            if check_valid_api_key(api_key):
                try:
                    try:
                        conn
                    except NameError:
                        conn = tc.get_conn()
                    cur = conn.cursor()
                    #get the id of any existing key for this person
                    sqlStr = "SELECT id FROM turtle.api_keys WHERE discord_id = " + str(
                        discord_id)
                    cur.execute(sqlStr)
                    result = cur.fetchall()
                    try:
                        to_be_deleted = result[0][0]
                        if to_be_deleted is None:
                            to_be_deleted = -1
                    except:
                        to_be_deleted = -1
                    sqlStr = "INSERT INTO turtle.api_keys (discord_id, api_key) VALUES (" + str(
                        discord_id) + ", '" + api_key + "');"
                    cur.execute(sqlStr)
                    conn.commit()
                    #now that we've successfully inserted, delete the previous key
                    if to_be_deleted != -1:
                        sqlStr = "DELETE FROM turtle.api_keys WHERE id = " + str(
                            to_be_deleted)
                        print(sqlStr)
                        cur.execute(sqlStr)
                        conn.commit()
                    await ctx.author.send(
                        'You entered the following GW2 API key: `{0}` ```\nThis key has been linked to your discord username. If you would like to update it in the future, just re-run this command from any text channel.```'
                        .format(ans.content))
                except:
                    await ctx.author.send(
                        'Something went wrong.  Tell Rev, he wrote this part')
            else:
                await ctx.author.send(
                    'That API key looks like it is the wrong length, or something.  Ask Rev to take a look'
                )

        await message.delete()