Run a code in a langage, with Wandbox API. Arguments: - `verbose`: Without this mode, only the programme output will be sent, without any additional information. In case of an error, it will be used automatically. - `language`: If not specified, the command will try
(
self,
ctx: commands.Context,
verbose: bool | None = False,
language: WandboxLanguageConverter | None = None,
parameters: WandboxFlagsConverter | None = None,
*,
code: str | None = None,
)
| 374 | @commands.hybrid_command(aliases=["executecode"]) |
| 375 | @app_commands.allowed_installs(guilds=True, users=True) |
| 376 | async def runcode( |
| 377 | self, |
| 378 | ctx: commands.Context, |
| 379 | verbose: bool | None = False, |
| 380 | language: WandboxLanguageConverter | None = None, |
| 381 | parameters: WandboxFlagsConverter | None = None, |
| 382 | *, |
| 383 | code: str | None = None, |
| 384 | ) -> None: |
| 385 | """ |
| 386 | Run a code in a langage, with Wandbox API. |
| 387 | |
| 388 | Arguments: |
| 389 | - `verbose`: Without this mode, only the programme output will be sent, without any additional information. In case of an error, it will be used automatically. |
| 390 | - `language`: If not specified, the command will try to "guess" with the file extension or Discord Markdown syntax. |
| 391 | - `parameters`: Optional option to send with the request. `engine:1/cpython-3.10.2`, `input:<input>`, `compiler_options:option1|option2|option3` and `runtime_options:option1|option2|option3`. |
| 392 | - `code`: May be normal code, but also an attached file, or a link from [pastebin](https://pastebin.com), [Github gist](https://gist.github.com) or another "raw" website. |
| 393 | If you use a link, your command must end with this syntax: `link=<link>` (no space around `=`). You may also not provide it and upload an attachment instead. |
| 394 | """ |
| 395 | if parameters is None: |
| 396 | _parameters = {} |
| 397 | else: |
| 398 | _parameters = { |
| 399 | key: getattr(parameters, key) |
| 400 | for key in parameters.get_flags() |
| 401 | if getattr(parameters, key) |
| 402 | } |
| 403 | |
| 404 | raw_request = {} |
| 405 | |
| 406 | _parameters["code_language"], raw_request["code"] = await self.get_code_from_context( |
| 407 | ctx, |
| 408 | code=code, |
| 409 | provided_language=language, |
| 410 | ) |
| 411 | if _parameters["code_language"] is None: |
| 412 | raise commands.UserFeedbackCheckFailure( |
| 413 | _( |
| 414 | "The language of your code could not be found. Specify it with the `language` parameter.", |
| 415 | ), |
| 416 | ) |
| 417 | |
| 418 | code_language = _parameters["code_language"] |
| 419 | if "engine" in _parameters: |
| 420 | engine: str = _parameters["engine"].lower() |
| 421 | try: |
| 422 | engine_index = int(engine) |
| 423 | if engine_index >= 1: |
| 424 | i = 0 |
| 425 | for engine_template in self.wandbox_languages[code_language]: |
| 426 | nb_engines = len(self.wandbox_languages[code_language][engine_template]) |
| 427 | if engine_index > nb_engines + i: |
| 428 | i += nb_engines |
| 429 | else: |
| 430 | raw_request["engine"]: WandboxEngine = list( |
| 431 | self.wandbox_languages[code_language][engine_template].values(), |
| 432 | )[engine_index - i - 1] |
| 433 | break |
nothing calls this directly
no test coverage detected