2019-03-12 10:09:46 +01:00
|
|
|
# Comp_iler
|
|
|
|
|
|
|
|
Sandboxed code execution discord bot.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
### Code Blocks
|
|
|
|
|
|
|
|
````
|
|
|
|
>```lang
|
|
|
|
code
|
|
|
|
```
|
|
|
|
|
2019-03-13 06:54:36 +01:00
|
|
|
>options```lang
|
2019-03-12 10:09:46 +01:00
|
|
|
code
|
|
|
|
```
|
|
|
|
````
|
|
|
|
|
|
|
|
### Inline Code
|
|
|
|
|
|
|
|
```
|
|
|
|
>`lang code`
|
|
|
|
|
2019-03-13 06:54:36 +01:00
|
|
|
>options`lang code`
|
2019-03-15 02:58:43 +01:00
|
|
|
```
|
2019-03-12 10:09:46 +01:00
|
|
|
|
|
|
|
### Examples
|
|
|
|
|
|
|
|
````
|
2019-03-15 02:58:43 +01:00
|
|
|
>```cpp
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::cout << "Hello World!" << std::endl;
|
|
|
|
}
|
2019-03-12 10:09:46 +01:00
|
|
|
```
|
|
|
|
|
2019-03-13 06:54:36 +01:00
|
|
|
>harmony```js
|
2019-03-12 10:09:46 +01:00
|
|
|
class Foo {
|
|
|
|
bar = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(new Foo().bar);
|
|
|
|
```
|
|
|
|
|
|
|
|
>`py print('hello world')`
|
|
|
|
|
2019-03-13 06:54:36 +01:00
|
|
|
>e`hs (+) <$> Just 1 <*> Just 2`
|
2019-03-15 02:58:43 +01:00
|
|
|
````
|
2019-03-13 06:54:36 +01:00
|
|
|
|
2019-03-15 02:58:43 +01:00
|
|
|
## Supported Languages and Options
|
2019-03-12 10:09:46 +01:00
|
|
|
|
2019-03-15 02:58:43 +01:00
|
|
|
One of the following language codes is set in `lang`.
|
|
|
|
Options are optionally set in `options`, which is a semicolon-delimited list of `flag` or `flag=value`.
|
2019-03-12 10:09:46 +01:00
|
|
|
|
2019-03-16 00:48:24 +01:00
|
|
|
- `bash` Bash (Bash 5.0.2)
|
2019-03-15 02:32:39 +01:00
|
|
|
- `c` C (GCC 8.2.0)
|
2019-03-15 05:06:59 +01:00
|
|
|
- `clj` Clojure (Clojure 1.10)
|
2019-03-15 02:32:39 +01:00
|
|
|
- `cpp` C++ (G++ 8.2.0)
|
|
|
|
- `cs` C# (Mono 5.18.0)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `e` evaluates a single expression instead of a module
|
2019-03-15 06:08:41 +01:00
|
|
|
- `elixir` Elixir (Elixir 1.8.1)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `fs` F# (FSharp 4.5)
|
|
|
|
- `go` Go (Go 1.12)
|
2019-03-16 04:01:22 +01:00
|
|
|
- `hs` Haskell (GHC 8.4.3)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `e` evaluates a single expression instead of a module
|
2019-03-15 05:06:59 +01:00
|
|
|
- `java` Java (OpenJDK 13)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `js` JavaScript (Node 11.11.0)
|
|
|
|
- `harmony` enables harmony features (`--harmony` on node)
|
|
|
|
- `e` prints the result of evaluating the code
|
2019-03-16 01:24:49 +01:00
|
|
|
- `julia` Julia (Julia 1.1.0)
|
|
|
|
- `e` prints the result of evaluating the code
|
2019-03-16 03:06:49 +01:00
|
|
|
- `lisp` Racket (Racket 7.2)
|
2019-03-16 01:47:24 +01:00
|
|
|
- `lua` Lua (Lua 5.3)
|
2019-03-16 02:43:40 +01:00
|
|
|
- `ocaml` OCaml (OCaml 4.0.6)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `pas` Pascal (FPC 3.0.4)
|
2019-03-16 00:48:24 +01:00
|
|
|
- `php` PHP (PHP 7.3.3)
|
|
|
|
- `pl` Perl (Perl 5.28.1)
|
2019-03-16 01:44:37 +01:00
|
|
|
- `prolog` Prolog (SWI-Prolog 8.1.2)
|
2019-03-15 02:58:43 +01:00
|
|
|
- `py` Python (CPython 3.7.2, CPython 2.7.16)
|
|
|
|
- `2` runs Python 2 instead of Python 3
|
2019-03-15 05:06:59 +01:00
|
|
|
- `rb` Ruby (Ruby 2.6.2)
|
|
|
|
- `rs` Rust (Rust 1.33.0)
|
2019-05-15 02:24:16 +02:00
|
|
|
|
|
|
|
## How it Works
|
|
|
|
|
|
|
|
Read the source code, specifically `src/struct/LanguageHandler.js`.
|
|
|
|
In summary, for every language there is a docker image which spins up a docker container.
|
|
|
|
The container is used for all evaluations of code, restarting if something goes wrong.
|
|
|
|
The container is locked down, so there is no networking, limited memory and CPU usage, and a time limit.
|
|
|
|
|
|
|
|
## Setup
|
|
|
|
|
2019-05-15 02:50:07 +02:00
|
|
|
0. Install Docker 18+
|
|
|
|
0. Install Node 10+
|
2019-05-15 02:24:16 +02:00
|
|
|
0. Run `npm i`
|
|
|
|
0. Fill out `config.json`
|
2019-05-15 02:50:07 +02:00
|
|
|
- `owner` - The owner(s) of the bot.
|
|
|
|
Use an array for multiple owners.
|
|
|
|
- `token` - The bot token.
|
|
|
|
- `languages` Languages to use.
|
|
|
|
The language names here are different from the user-facing ones.
|
|
|
|
Check the folders in ./docker/ for the language names.
|
|
|
|
Change to null to enable all languages.
|
|
|
|
- `memory` Max memory usage of a container.
|
|
|
|
- `cpu` Max CPU usage of a container.
|
|
|
|
- `timeout` Time limit for code in milliseconds.
|
|
|
|
- `prepare` Whether to run containers on setup.
|
|
|
|
Setting to true will speed up the first eval, but that language might not be used.
|
2019-05-15 02:24:16 +02:00
|
|
|
0. Run `node .`
|