compiler-discord/README.md

128 lines
2.9 KiB
Markdown
Raw Normal View History

2019-03-12 10:09:46 +01:00
# Comp_iler
2019-05-17 02:29:24 +02:00
Sandboxed code execution discord bot.
[Invite the bot!](https://discordapp.com/oauth2/authorize?client_id=555066722969714728&scope=bot)
2019-03-12 10:09:46 +01:00
## Usage
### Code Blocks
````
>```lang
code
```
2019-05-15 03:05:12 +02:00
````
2019-03-12 10:09:46 +01:00
2019-05-15 03:05:12 +02:00
````
2019-03-13 06:54:36 +01:00
>options```lang
2019-03-12 10:09:46 +01:00
code
```
````
### Inline Code
```
>`lang code`
2019-05-15 03:05:12 +02:00
```
2019-03-12 10:09:46 +01:00
2019-05-15 03:05:12 +02:00
```
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-05-15 03:05:12 +02:00
````
2019-03-12 10:09:46 +01:00
2019-05-15 03:05:12 +02: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);
```
2019-05-15 03:05:12 +02:00
````
2019-03-12 10:09:46 +01:00
2019-05-15 03:05:12 +02:00
```
2019-03-12 10:09:46 +01:00
>`py print('hello world')`
2019-05-15 03:05:12 +02:00
```
2019-03-12 10:09:46 +01:00
2019-05-15 03:05:12 +02:00
```
2019-03-13 06:54:36 +01:00
>e`hs (+) <$> Just 1 <*> Just 2`
2019-05-15 03:05:12 +02: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
- `bash` Bash
- `c` C (GCC)
- `clj` Clojure
- `cpp` C++ (G++)
- `cs` C# (Mono)
2019-03-15 02:58:43 +01:00
- `e` evaluates a single expression instead of a module
- `elixir` Elixir
2019-05-15 03:05:12 +02:00
- `fs` F# (Mono)
- `go` Go
- `hs` Haskell (GHC)
2019-03-15 02:58:43 +01:00
- `e` evaluates a single expression instead of a module
- `java` Java (OpenJDK)
- `js` JavaScript (Node)
2019-03-15 02:58:43 +01:00
- `harmony` enables harmony features (`--harmony` on node)
- `e` prints the result of evaluating the code
- `julia` Julia
2019-03-16 01:24:49 +01:00
- `e` prints the result of evaluating the code
- `lisp` Racket
- `lua` Lua
- `ocaml` OCaml
- `pas` Pascal (FPC)
- `php` PHP
- `pl` Perl5
- `prolog` Prolog (SWI-Prolog)
- `py` Python (CPython)
2019-03-15 02:58:43 +01:00
- `2` runs Python 2 instead of Python 3
- `rb` Ruby
- `rs` Rust
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.
2019-05-17 03:02:44 +02:00
- `prefix` - The prefix for commands.
- `codePrefix` - The prefix for code evaluation.
2019-05-15 02:50:07 +02:00
- `languages` Languages to use.
The language names here are different from the user-facing ones.
2019-05-17 04:57:59 +02:00
Check the filenames in `src/languages/` for the language names.
2019-05-17 02:29:24 +02:00
Change to `null` to enable all languages.
2019-05-15 02:50:07 +02:00
- `memory` Max memory usage of a container.
- `cpu` Max CPU usage of a container.
- `timeout` Time limit for code in milliseconds.
2019-05-17 07:55:24 +02:00
- `prepare` Whether to start containers on setup.
2019-05-15 02:50:07 +02:00
Setting to true will speed up the first eval, but that language might not be used.
- `parallel` Whether to build images and container in parallel.
Faster, but will take more resources.
2019-05-17 07:55:24 +02:00
- `concurrent` Number of code evaluations per language than can run at a time.
2019-05-15 02:24:16 +02:00
0. Run `node .`