def commands_submit(session): mode = flask.request.values.get("mode", "responses") assert mode in ("responses", "explanations") data = flask.json.loads(flask.request.values["data"]) # Server-side sanity checking for command, response_data in data.items(): if not isinstance(command, str): raise ValueError("Key is not a string") if command == "": raise ValueError("Command is blank") if not isinstance(response_data, dict): raise ValueError("Response data is not a dict") if set(response_data.keys()) != set(("response", "access")): raise ValueError("Incorrect keys for response_data") if not isinstance(response_data["response"], (tuple, list)): response_data["response"] = [response_data["response"]] for response in response_data["response"]: if not isinstance(response, str): raise ValueError("Value is not a string or list of strings") if response == "": raise ValueError("Response is blank") if len(response) > 450: raise ValueError("Response is too long") if len(response_data["response"]) == 1: response_data["response"] = response_data["response"][0] if response_data["access"] not in ("any", "sub", "mod"): raise ValueError("Invalid access level") if mode == "responses": botinteract.modify_commands(data) elif mode == "explanations": botinteract.modify_explanations(data) history.store(mode, session["user"], data) return flask.json.jsonify(success="OK", csrf_token=server.app.csrf_token())
def commands_submit(session): mode = flask.request.values.get('mode', 'responses') assert (mode in ('responses', 'explanations')) data = flask.json.loads(flask.request.values['data']) # Server-side sanity checking for command, response_data in data.items(): if not isinstance(command, str): raise ValueError("Key is not a string") if command == '': raise ValueError("Command is blank") if not isinstance(response_data, dict): raise ValueError("Response data is not a dict") if set(response_data.keys()) != set(('response', 'access')): raise ValueError("Incorrect keys for response_data") if not isinstance(response_data['response'], (tuple, list)): response_data['response'] = [response_data['response']] for response in response_data['response']: if not isinstance(response, str): raise ValueError("Value is not a string or list of strings") if response == '': raise ValueError("Response is blank") if len(response) > 450: raise ValueError("Response is too long") if len(response_data['response']) == 1: response_data['response'] = response_data['response'][0] if response_data['access'] not in ('any', 'sub', 'mod'): raise ValueError("Invalid access level") if mode == 'responses': botinteract.modify_commands(data) elif mode == 'explanations': botinteract.modify_explanations(data) history.store(mode, session['user'], data) return flask.json.jsonify(success='OK', csrf_token=server.app.csrf_token())
async def commands_submit(session): mode = flask.request.values.get('mode', 'responses') assert(mode in ('responses', 'explanations')) data = flask.json.loads(flask.request.values['data']) # Server-side sanity checking for command, response_data in data.items(): if not isinstance(command, str): raise ValueError("Key is not a string") if command == '': raise ValueError("Command is blank") if not isinstance(response_data, dict): raise ValueError("Response data is not a dict") if set(response_data.keys()) != set(('response', 'access')): raise ValueError("Incorrect keys for response_data") if not isinstance(response_data['response'], (tuple, list)): response_data['response'] = [response_data['response']] for response in response_data['response']: if not isinstance(response, str): raise ValueError("Value is not a string or list of strings") if response == '': raise ValueError("Response is blank") if len(response) > 450: raise ValueError("Response is too long") if len(response_data['response']) == 1: response_data['response'] = response_data['response'][0] if response_data['access'] not in ('any', 'sub', 'mod'): raise ValueError("Invalid access level") if mode == 'responses': await common.rpc.bot.static.modify_commands(data) elif mode == 'explanations': await common.rpc.bot.explain.modify_explanations(data) history.store(mode, session['user']['id'], data) return flask.json.jsonify(success='OK', csrf_token=server.app.csrf_token())
async def commands_submit(session): data = flask.json.loads(flask.request.values['data']) # Server-side sanity checking for command, response_data in data.items(): if not isinstance(command, str): raise ValueError("Key is not a string") if command == '': raise ValueError("Command is blank") if not isinstance(response_data, dict): raise ValueError("Response data is not a dict") if set(response_data.keys()) != set(('response', 'access')): raise ValueError("Incorrect keys for response_data") if not isinstance(response_data['response'], (tuple, list)): response_data['response'] = [response_data['response']] for response in response_data['response']: if not isinstance(response, str): raise ValueError("Value is not a string or list of strings") if response == '': raise ValueError("Response is blank") if not utils.check_length(response): raise ValueError("Response is too long") if len(response_data['response']) == 1: response_data['response'] = response_data['response'][0] if response_data['access'] not in ('any', 'sub', 'mod'): raise ValueError("Invalid access level") await common.rpc.bot.static.modify_commands(data) history.store('responses', session['user']['id'], data) return flask.json.jsonify(success='OK', csrf_token=server.app.csrf_token())
def spam_submit(session): data = flask.json.loads(flask.request.values['data']) # Validation checks error = verify_rules(data) if error: return flask.json.jsonify(error=error, csrf_token=server.app.csrf_token()) botinteract.modify_spam_rules(data) history.store("spam", session['user'], data) return flask.json.jsonify(success='OK', csrf_token=server.app.csrf_token())
async def spam_submit(session): link_spam = "link_spam" in flask.request.values data = flask.json.loads(flask.request.values['data']) # Validation checks error = verify_rules(data) if error: return flask.json.jsonify(error=error, csrf_token=server.app.csrf_token()) if link_spam: await common.rpc.bot.link_spam.modify_link_spam_rules(data) else: await common.rpc.bot.spam.modify_spam_rules(data) history.store("link_spam" if link_spam else "spam", session['user']['id'], data) return flask.json.jsonify(success='OK', csrf_token=server.app.csrf_token())