mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
🐛 fix(functionscalls.py): add timeout parameter to evaluate_math function to limit execution time and prevent potential abuse or infinite loops
This commit is contained in:
@@ -316,13 +316,14 @@ async def send_ascii_art_image(
|
|||||||
|
|
||||||
|
|
||||||
async def evaluate_math(
|
async def evaluate_math(
|
||||||
message_in_channel_in_wich_to_send: discord.Message, arguments: dict
|
message_in_channel_in_wich_to_send: discord.Message, arguments: dict, timeout=10
|
||||||
):
|
):
|
||||||
evaluable = arguments.get("string", "")
|
evaluable = arguments.get("string", "")
|
||||||
if evaluable == "":
|
if evaluable == "":
|
||||||
raise FuntionCallError("No string provided")
|
raise FuntionCallError("No string provided")
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
result = simple_eval(evaluable)
|
result = await asyncio.wait_for(loop.run_in_executor(None, simple_eval, evaluable), timeout=timeout)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result = f"Error: {e}"
|
result = f"Error: {e}"
|
||||||
return f"Result to math eval of {evaluable}: ```\n{str(result)}```"
|
return f"Result to math eval of {evaluable}: ```\n{str(result)}```"
|
||||||
|
|||||||
Reference in New Issue
Block a user