Пример #1
0
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()
Пример #2
0
def remove_guilds():
    guilds = []
    guilds.clear()
    for guild in client.guilds:
        guilds.append(guild.id)
    guilds_db = get_guilds()
    trimmed_guilds = set(guilds) ^ set(guilds_db)
    for guild in trimmed_guilds:
        c.execute('delete from database where guild_id = (?)', (guild,))
        conn.commit()
Пример #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)
Пример #4
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)
Пример #5
0
def update_timestamp(guild_id, screen_name, timestamp):
    c.execute('update database set timestamp = (?) where guild_id = (?) and screen_name = (?)', (timestamp, guild_id, screen_name))
    conn.commit()