Esempio n. 1
0
File: utils.py Progetto: s4mim/Fetch
def get_timestamp(guild_id, screen_name):
    c.execute('select timestamp from database where guild_id = (?) and screen_name = (?)', (guild_id, screen_name))
    row = c.fetchone()
    if row is not None:
        return row[0]
    else:
        #Just for safety, should never be executed
        return 0
Esempio n. 2
0
File: utils.py Progetto: s4mim/Fetch
def remove_account(guild_id, screen_name):
    #Look if the user is in the database for the server
    c.execute('select * from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
    row = c.fetchone()
    if row is not None:
    #User exists, remove it
        c.execute('delete from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
        conn.commit()
Esempio n. 3
0
async def add_account(ctx, screen_name, channel_id = None):
    try:
        if channel_id == None:
            channel_id = ctx.message.channel.id

        guild_id = ctx.message.guild.id
        channel_id = int(channel_id)

        #Check if the channel exists before doing anything else
        if client.get_channel(channel_id) is None:
            await ctx.send('Channel does not exist.')
            return

        #Make sure the account has no @
        if screen_name.startswith('@'):
            await ctx.send('Type the account name without the @.')
            return

        user = api.get_user(screen_name)

        c.execute('select * from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
        row = c.fetchone()

        if row is None:
            #User was not found in the database for the server
            c.execute('insert into database values (?,?,0,?)', (guild_id, screen_name, channel_id))
            await ctx.send(f'User {user.screen_name} has been added to {ctx.message.guild.name}.\nChannel: `{channel_id}`')
        else:
            #User was found, check if channel_id is the same
            c.execute('select channel_id from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
            row = c.fetchone()
            if row[0] == channel_id:
                #Channel_id is the same, no need to change it
                await ctx.send('User and channel are already registered.')
            else:
                #Channel_id is different, update it
                c.execute('update database set channel_id = (?) where guild_id = (?) and screen_name = (?)', (channel_id, guild_id, screen_name))
                await ctx.send(f'Channel was updated for user {user.screen_name}')
        conn.commit()

    except Exception as e:
        logger.exception(e)
        print('GUILD : ' + ctx.message.guild.name + ' - ERROR : ' + str(e))
        error_str = 'Error!\n `Code : {}`'.format(str(e))
        await ctx.send(error_str)
Esempio n. 4
0
async def get_channel(ctx, screen_name):
    try:
        guild_id = ctx.message.guild.id

        c.execute('select channel_id from database where guild_id = (?) and screen_name = (?)', (guild_id, screen_name))
        row = c.fetchone()
        if row is not None:
            #Channel (and user) exist, post name and ID
            await ctx.send(f'Channel ID: `{row[0]}`\nChannel name: {client.get_channel(row[0])}')
        else:
            #Channel (and user) not found
            await ctx.send('Channel was not found for this user in the database.')
    except Exception as e:
        logger.exception(e)
        print('GUILD : ' + ctx.message.guild.name + ' - ERROR : ' + str(e))
        error_str = 'Error!\n `Code : {}`'.format(str(e))
        await ctx.send(error_str)
Esempio n. 5
0
async def remove_account(ctx, screen_name):
    try:
        guild_id = ctx.message.guild.id

        #Look if the user is in the database for the server
        c.execute('select * from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
        row = c.fetchone()
        if row is not None:
            #User exists, remove it
            c.execute('delete from database where screen_name = (?) and guild_id = (?)', (screen_name, guild_id))
            await ctx.send(f'User {screen_name} has been removed from the database for {ctx.message.guild.name}')
        else:
            #User is not in the database
            await ctx.send(f'User {screen_name} was not found in the database.')
        conn.commit()

    except Exception as e:
        logger.exception(e)
        print('GUILD : ' + ctx.message.guild.name + ' - ERROR : ' + str(e))
        error_str = 'Error!\n `Code : {}`'.format(str(e))
        await ctx.send(error_str)