예제 #1
0
def _db_update_server_setting(guild_id: int, settings: dict) -> bool:
    where = util.db_get_where_string('guildid', guild_id, is_text_type=True)
    set_string = ', '.join(
        [f'{key} = {value}' for key, value in settings.items()])
    query = f'UPDATE serversettings SET {set_string} WHERE {where}'
    success = core.db_try_execute(query)
    return success
예제 #2
0
async def get_prefs(ctx: commands.Context, app: str = None, key: str = None):
    try:
        # Dump all user settings
        if not app:
            prefs = preferences.get_all(ctx.author)
            msg = 'Your Preferences:\n'
            for app, settings in prefs.items():
                if app != 'id':
                    msg += f'\n**__{app}__**'
                    for key, value in settings.items():
                        msg += f'\n{key} = {value}'

            return await ctx.send(msg)

        # Make sure the game exists
        if app != 'global' and not registry.get(app):
            return await ctx.send(f'I\'m not sure what app or game that is!')

        # Dump all settings for specified app
        if not key:
            prefs = preferences.get_all_for_app(ctx.author, app)
            msg = f"Your Preferences for **{app}**:\n"
            for key, value in prefs.items():
                msg += f'\n{key} = {value}'
            return await ctx.send(msg)

        msg = f'{key} = {preferences.get(ctx.author, app, key)}'
        await ctx.send(msg)

    except KeyError:
        await ctx.send('Whoops! It seems that a specified param does not exist in your settings... maybe you haven\'t customized that yet?\n*Or, my code threw a python KeyError for some odd reason...*')
예제 #3
0
def write_settings(exp_name, settings):
    fn = Path(f"{ROOT_PATH}/uuid_lookup.txt")
    wstr = f"exp_name: {exp_name}\n"
    for key, val in settings.items():
        if isinstance(val, float):
            val = "{:.3e}".format(val)
            wstr += f"{key}: {val}\n"
        elif isinstance(val, int):
            val = "{:d}".format(val)
            wstr += f"{key}: {val}\n"
        elif isinstance(val, str):
            wstr += f"{key}: {val}\n"
        else:
            raise TypeError("Uknown settings type {}".format(type(val)))
    with open(fn, 'a+') as f:
        f.write(wstr)
예제 #4
0
파일: database.py 프로젝트: Lnic/YaDc
async def set_settings(settings: Dict[str, Tuple[object, datetime]]) -> bool:
    __log_db_function_enter('set_settings', settings=settings)

    utc_now = util.get_utcnow()
    if settings:
        query_lines = []
        args = []
        success = True
        current_settings = await get_settings(settings.keys())
        for setting_name, (value, modified_at) in settings.items():
            query = ''
            column_name = None
            if isinstance(value, bool):
                column_name = 'settingboolean'
                value = util.db_convert_boolean(value)
            elif isinstance(value, int):
                column_name = 'settingint'
            elif isinstance(value, float):
                column_name = 'settingfloat'
            elif isinstance(value, datetime):
                column_name = 'settingtimestamptz'
                value = util.db_convert_timestamp(value)
            else:
                column_name = 'settingtext'
                value = util.db_convert_text(value)
            current_value, db_modify_date = current_settings[setting_name]
            modify_date = db_modify_date or utc_now

            setting_name = util.db_convert_text(setting_name)
            if current_value is None and db_modify_date is None:
                query = f'INSERT INTO settings ({column_name}, modifydate, settingname) VALUES ({value}, \'{modified_at}\', {setting_name});'
            elif current_value != value:
                query = f'UPDATE settings SET {column_name} = {value}, modifydate = \'{modified_at}\' WHERE settingname = {setting_name};'

            if query:
                query_lines.append(query)
                args.extend([value, modified_at, setting_name])
        success = not query_lines or await try_execute('\n'.join(query_lines))
        if success:
            __settings_cache.update(settings)
        return success
    else:
        return True
예제 #5
0
 def post(self):
     stage = self.get_argument("stage", None)
     if stage is None:
         return self.write({
             'status': "error",
             'message': "Please provide a stage"
         })
     settings = self.get_argument("settings", None)
     if settings is None:
         return self.write({
             'status': "error",
             'message': "Please provide a settings object"
         })
     settings = json.loads(settings)
     # print(settings)
     with db.getCur() as cur:
         for colname, val in settings.items():
             cur.execute(
                 "UPDATE Stages SET {} = ?"
                 " WHERE Id = ? AND Tournament = ?".format(colname),
                 (val, stage, self.tournamentid))  # TODO: fix SQL injection
         return self.write({'status': "success"})