Add cleanup interval option Enhanced some options to be per-compiler Fix concurrent option not being used |
||
|---|---|---|
| docker | ||
| src | ||
| .eslintrc.json | ||
| .gitattributes | ||
| .gitignore | ||
| CHANGELOG.md | ||
| config.example.json | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
Comp_iler
Sandboxed code execution discord bot.
Invite the bot!
Usage
Code Blocks
>```lang
code
```
>options```lang
code
```
Inline Code
>`lang code`
>options`lang code`
Examples
>```cpp
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
```
>harmony```js
class Foo {
bar = 1;
}
console.log(new Foo().bar);
```
>`py print('hello world')`
>e`hs (+) <$> Just 1 <*> Just 2`
Supported Languages and Options
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.
bashBashcC (GCC)cljClojurecppC++ (G++)csC# (Mono)eevaluates a single expression instead of a module
elixirElixirfsF# (Mono)goGohsHaskell (GHC)eevaluates a single expression instead of a module
javaJava (OpenJDK)jsJavaScript (Node)harmonyenables harmony features (--harmonyon node)eprints the result of evaluating the code
juliaJuliaeprints the result of evaluating the code
lispRacketluaLuaocamlOCamlpasPascal (FPC)phpPHPplPerl5prologProlog (SWI-Prolog)pyPython (CPython)2runs Python 2 instead of Python 3
rbRubyrsRust
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
- Install Docker 18+
- Install Node 10+
- Run
npm i - Fill out
config.jsonas described in the configuration section below - Run
node .
Configuration
Bot
owner- The owner(s) of the bot.
Use an array for multiple owners.token- The bot token.prefix- The prefix for commands.codePrefix- The prefix for code evaluation.
Setup
languagesLanguages to use.
The language names here are different from the user-facing ones.
Check the filenames insrc/languages/for the language names.
Change tonullto enable all languages.prepareWhether to start containers on setup.
Setting to true will speed up the first eval, but that language might not be used.parallelWhether to build images in parallel.
Will also setup containers in parallel ifprepareis set.
Faster, but will take more resources.cleanupInterval in minutes to occasionally kill all containers.
Set to0to disable.
Compilers
For each of these options, you can use either the expected value to set it for all compilers or an object with compiler names to the expected values.
If using an object, you can set the default with the default key.
The compiler names are the folder names under docker/.
memoryMax memory usage of a container.cpuMax CPU usage of a container.timeoutTime limit for code in milliseconds.concurrentNumber of code evaluations than can run at a time per container.
The more that can run, the more resources a container would need.