I'm making a bot that will output different information depending on the user input (a string). I'm wondering if there is a better way to parse the input and redirect to different outcomes:
def query(msg: str):
if re.compile(r"moci(o|ó)?n(es)? de (procedimiento)s?", re.IGNORECASE).search(msg):
return open("mociones/mocion_procedimiento.txt", "r").read()
elif re.compile(r"moci(o|ó)?n(es)? de (ó|o)?rden(es)?", re.IGNORECASE).search(msg):
return open("mociones/mocion_orden.txt", "r").read()
elif re.compile(r"moci(o|ó)?n(es)? de duda(s)?", re.IGNORECASE).search(msg):
return open("mociones/mocion_duda.txt", "r").read()
elif re.compile(r"moci(o|ó)?n(es)? de privilegio(s)?", re.IGNORECASE).search(msg):
return open("mociones/mocion_privilegio.txt", "r").read()
...
elif re.compile(r"defender (el|los)? anteproyectos?", re.IGNORECASE).search(msg):
return open("debate_particular/index.txt", "r").read()
elif re.compile(r"anteproyectos?", re.IGNORECASE).search(msg):
return open("anteproyecto/index.txt", "r").read()
else:
return "_*ERROR*_\n\nNo search results were found for \n`{query}`".format(query=msg)