Exemplo n.º 1
0
async def test(ctx, action, *, params):
    print(f'+ called command test(ctx, {action}, {params}) by {ctx.author}')
    if action == 'utcnow':
        utcnow = util.get_utcnow()
        txt = util.get_formatted_datetime(utcnow)
        await ctx.send(txt)
    elif action == 'init':
        core.init_db()
        await ctx.send('Initialized the database from scratch')
        await util.try_delete_original_message(ctx)
    elif (action == 'select' or action == 'selectall') and params:
        query = f'SELECT {params}'
        result, error = core.db_fetchall(query)
        if error:
            await ctx.send(error)
        elif result:
            await ctx.send(result)
        else:
            await ctx.send('The query didn\'t return any results.')
    elif action == 'query' and params:
        query = f'{params}'
        success, error = core.db_try_execute(query)
        if not success:
            await ctx.send(error)
        else:
            await ctx.send(
                f'The query \'{params}\' has been executed successfully.')
Exemplo n.º 2
0
def _db_get_server_settings(guild_id: int = None,
                            setting_names: list = None,
                            additional_wheres: list = []) -> list:
    wheres = []
    if guild_id is not None:
        wheres.append(
            util.db_get_where_string('guildid', guild_id, is_text_type=True))

    if setting_names:
        setting_string = ', '.join(setting_names)
    else:
        setting_string = '*'

    if additional_wheres:
        wheres.extend(additional_wheres)

    where = util.db_get_where_and_string(wheres)
    if where:
        query = f'SELECT {setting_string} FROM serversettings WHERE {where}'
    else:
        query = f'SELECT {setting_string} FROM serversettings'
    rows = core.db_fetchall(query)
    if rows:
        return rows
    else:
        return []
Exemplo n.º 3
0
def db_get_devices() -> List[Device]:
    query = f'SELECT * FROM devices;'
    rows = core.db_fetchall(query)
    if rows:
        result = [Device(*row) for row in rows]
    else:
        result = []
    return result
Exemplo n.º 4
0
def select_daily_channel(guild_id=None, can_post=None):
    query = 'SELECT * FROM daily'
    if guild_id:
        query += ' WHERE guildid = \'{}\''.format(guild_id)
        if can_post != None:
            query += ' AND canpost = {}'.format(convert_can_post(can_post))
    if can_post != None:
        query += ' WHERE canpost = {}'.format(convert_can_post(can_post))
    result = core.db_fetchall(query)
    return result
Exemplo n.º 5
0
def _db_get_device(device_key: str) -> Device:
    where = util.db_get_where_string('key', device_key, is_text_type=True)
    query = f'SELECT * FROM devices WHERE {where}'
    rows = core.db_fetchall(query)
    if rows:
        row = rows[0]
        result = Device(*row)
    else:
        result: Device = None
    return result