Aug 29, 2017 04:53 PM
(This post was last modified: Sep 3, 2017 10:30 PM by Barret.)
Discord bot that can compile and execute your code snippet live in the channel.
Tutorial
This tutorial is based on Debian but should be simple enough for other distro's as well, i assume you read the thread and seen the requirements.
We need NodeJS, Php, Mono and a unix box in order for this to work, notice that you need to be the admin (root) of the unix box you have.
Preparations
Download the base files from: https://github.com/TheBarret/Compiler.NET and place these in a folder where your bot is going to operate.
Via your discord account you can add a new application which is going to be your bot, if you never done this before i recommend
that you follow these instructions: https://github.com/reactiflux/discord-ir...ng-a-token
This token you finally get after you created it, is the token that is going to be in auth.json from my project files.
So go ahead and edit that config and place your bot's token in there.
Install mono-complete and build-essentials if you haven't already
Install NodeJS 6.* or NodeJS 8.*
Install the Discord.JS and Random-id.js
This must be executed INSIDE the directory where you placed the compiler bot files
After doing this, we have created the environment to execute and operate your compiler bot.
Confirm the following commands to check everything is in place:
![[Image: tQcg9wA.png]](https://i.imgur.com/tQcg9wA.png)
Adjustments
The bot.js file contains config settings that you might want to check out, the functions.php has functions that include keyword filterering.
Most keywords have been setup by me, but if you want to change that make sure you use php regex formats, example:
Lets say you want to block System.Text you would add:
Adding admins (people you trust...)
The bot.js holds also your admins whitelist, it accepts only discord user id's (not the small one, the large number format).
If you done all that we are ready to startup and test it out but whatever you do, DON'T EVER EXECUTE AS ROOT
The bot has a feature that blocks compiles being executed as root, but still, bad practise to run services as root.
So create or change into another (lower) account and type node bot.js in the bot folder we created earlier
![[Image: UxYfIZm.png]](https://i.imgur.com/UxYfIZm.png)
Things to consider and facts
Commands
Features
Requirements
Diagram of system flow
![[Image: iPEwmxI.png]](https://i.imgur.com/iPEwmxI.png)
![[Image: xt1KprV.png?1]](https://i.imgur.com/xt1KprV.png?1)
![[Image: Q322Iin.png?1]](https://i.imgur.com/Q322Iin.png?1)
VB.NET
![[Image: 200uRPu.png?1]](https://i.imgur.com/200uRPu.png?1)
![[Image: QmP1g7w.png?1]](https://i.imgur.com/QmP1g7w.png?1)
C#.NET
![[Image: MbRvjo5.png?1]](https://i.imgur.com/MbRvjo5.png?1)
![[Image: 3AWyDzm.png?1]](https://i.imgur.com/3AWyDzm.png?1)
![[Image: tgGcP08.png?1]](https://i.imgur.com/tgGcP08.png?1)
Some loop testing
![[Image: IQ2a7Xt.png?1]](https://i.imgur.com/IQ2a7Xt.png?1)
Unix Debug Terminal
![[Image: S0ZfNc8.png]](https://i.imgur.com/S0ZfNc8.png)
People involved with testing in this project
Panthera (advice, tester), Cawk (advice tester), forceberg (tester), Wops (tester), Naywyn (tester), NewMecha (model), Rhez (tester), Electroalek (php regex)
(if i forgot your name, please forgive me and pm me)
Tutorial
This tutorial is based on Debian but should be simple enough for other distro's as well, i assume you read the thread and seen the requirements.
We need NodeJS, Php, Mono and a unix box in order for this to work, notice that you need to be the admin (root) of the unix box you have.
Preparations
Download the base files from: https://github.com/TheBarret/Compiler.NET and place these in a folder where your bot is going to operate.
Via your discord account you can add a new application which is going to be your bot, if you never done this before i recommend
that you follow these instructions: https://github.com/reactiflux/discord-ir...ng-a-token
This token you finally get after you created it, is the token that is going to be in auth.json from my project files.
So go ahead and edit that config and place your bot's token in there.
Install mono-complete and build-essentials if you haven't already
Code
sudo apt-get install build-essential
sudo apt-get install mono-completeInstall NodeJS 6.* or NodeJS 8.*
Code
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejsCode
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejsInstall the Discord.JS and Random-id.js
This must be executed INSIDE the directory where you placed the compiler bot files
Code
npm install --save discord.js
npm install --save random-idAfter doing this, we have created the environment to execute and operate your compiler bot.
Confirm the following commands to check everything is in place:
![[Image: tQcg9wA.png]](https://i.imgur.com/tQcg9wA.png)
Adjustments
The bot.js file contains config settings that you might want to check out, the functions.php has functions that include keyword filterering.
Most keywords have been setup by me, but if you want to change that make sure you use php regex formats, example:
Lets say you want to block System.Text you would add:
Code
\bSystem\b\.\bText\bAdding admins (people you trust...)
The bot.js holds also your admins whitelist, it accepts only discord user id's (not the small one, the large number format).
Code
var admins = ['1111111111111111','222222222222222','3333333333333'];If you done all that we are ready to startup and test it out but whatever you do, DON'T EVER EXECUTE AS ROOT
The bot has a feature that blocks compiles being executed as root, but still, bad practise to run services as root.
So create or change into another (lower) account and type node bot.js in the bot folder we created earlier
![[Image: UxYfIZm.png]](https://i.imgur.com/UxYfIZm.png)
Things to consider and facts
- Room for improvement, feel free to adjust the scripts if you see fit.
- The bot uses two pre-set c#/vb solution files that contain pre-coded wrapper classes.
- Compilations are usually finished within 3~6 seconds, depending on system hardware and speed.
- The bot keeps session id's that correspond with log files in the log folder that hold more detailed info of a session.
- Each user using the bot gets a separated log folder that holds all requests and builds.
- The bot uses Framework 4.5, change this by changing the settings when you open the project files in the VS.
- Mono might have a lot already built in, a small portion has yet to be ported.
- Why CAS is not been utilized? Sadly Mono does not yet support these namespaces.
Commands
- !showid Shows user's discord id (everyone)
- !uptime Shows system uptime (everyone)
- !mem Shows system memory table (everyone)
- !version Shows current version along with system's OS info (everyone)
- !mono Shows current mono version (everyone)
- !chmode Enables or Disables lock for free compiles for non-admins users (only admin, enabled by default)
- !vbnet ..code.. Compiles and executes vb.net code (only admins or if lock is disabled)
- !csharp ..code.. Compiles and executes c#.net code (only admins or if lock is disabled)
Features
- C# Compile and Run
- VB Compile and Run
- Supports Framework 4.5
- Whitelist members only
- Safety: filter (intercept potential unsafe code)
- Safety: Max execution time
- Safety: Max output responds
- Safety: Will not compile if process is root
Requirements
- Unix server
- Mono (runtime and sdk)
- Java environment (Node.js, Discord.js)
- Php environment (version 5.*)
- And...decent knowledgement of all items named above
Diagram of system flow
![[Image: iPEwmxI.png]](https://i.imgur.com/iPEwmxI.png)
![[Image: xt1KprV.png?1]](https://i.imgur.com/xt1KprV.png?1)
![[Image: Q322Iin.png?1]](https://i.imgur.com/Q322Iin.png?1)
VB.NET
![[Image: 200uRPu.png?1]](https://i.imgur.com/200uRPu.png?1)
![[Image: QmP1g7w.png?1]](https://i.imgur.com/QmP1g7w.png?1)
C#.NET
![[Image: MbRvjo5.png?1]](https://i.imgur.com/MbRvjo5.png?1)
![[Image: 3AWyDzm.png?1]](https://i.imgur.com/3AWyDzm.png?1)
![[Image: tgGcP08.png?1]](https://i.imgur.com/tgGcP08.png?1)
Some loop testing
![[Image: IQ2a7Xt.png?1]](https://i.imgur.com/IQ2a7Xt.png?1)
Unix Debug Terminal
![[Image: S0ZfNc8.png]](https://i.imgur.com/S0ZfNc8.png)
People involved with testing in this project
Panthera (advice, tester), Cawk (advice tester), forceberg (tester), Wops (tester), Naywyn (tester), NewMecha (model), Rhez (tester), Electroalek (php regex)
(if i forgot your name, please forgive me and pm me)




![[Image: narwinsig.gif]](https://image.ibb.co/jf6HBa/narwinsig.gif)
![[Image: PVoDiqS.png]](https://i.imgur.com/PVoDiqS.png)