diff options
| author | 2019-09-16 12:02:03 +0100 | |
|---|---|---|
| committer | 2019-09-16 12:02:35 +0100 | |
| commit | d6960865d6295b1c97869a79662add391fac10cd (patch) | |
| tree | 985421abc7cdf6cb43a63e2b51f33d0695c2844e /modules/rust.py | |
| parent | return content warning from ap_utils.format_note and show it (diff) | |
| signature | ||
eval_rust.py -> rust.py
Diffstat (limited to 'modules/rust.py')
| -rw-r--r-- | modules/rust.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/rust.py b/modules/rust.py new file mode 100644 index 00000000..f432e1c0 --- /dev/null +++ b/modules/rust.py @@ -0,0 +1,42 @@ +#--depends-on commands + +import json, socket +from src import ModuleManager, utils + +EVAL_URL = "https://play.rust-lang.org/execute" +FN_TEMPLATE = """ +fn main() { + println!("{:?}", { + %s + }); +} +""" +API_ARGS = { + "channel": "nightly", + "crateType": "bin", + "mode": "debug", + "tests": False, + "execute": True, + "target": "ast", + "backtrace": False +} + +class Module(ModuleManager.BaseModule): + @utils.hook("received.command.rust", min_args=1) + def eval(self, event): + """ + :help: Evaluate a rust statement + :usage: <statement> + """ + args = API_ARGS.copy() + args["code"] = FN_TEMPLATE % event["args"] + try: + page = utils.http.request(EVAL_URL, post_data=args, + method="POST", json=True, content_type="application/json") + except socket.timeout: + raise utils.EventError("%s: eval timed out" % + event["user"].nickname) + + err_or_out = "stdout" if page.data["success"] else "stderr" + event[err_or_out].write("%s: %s" % (event["user"].nickname, + page.data[err_or_out].strip("\n"))) |
