Giter VIP home page Giter VIP logo

discord-compiler-bot's Introduction

👩‍💻 Discord Compiler

A Discord bot which can compile code, display the output of the compiler, and run the program. This bot is great for prototyping ideas, or testing concepts on-the-fly with very little effort. It supports almost every programing language you could name (c++, c, java, python, ruby, javascript, go, php, lua, & more!).

🔗 Links

👩‍🏫 Usage

For a tutorial about how to use this bot, feel free to view our wiki!

🔰 Hosting it yourself?

There's only two steps required to get this bot up-and-running. Our release builds only support 64-bit, if you'd like to run this on a different architecture you will have to compile the project yourself, this is also true if you wish to host this bot on MacOS.

  1. Copy the repository's .env.example as a .env file & fill in required information
  2. Download our latest release build & place it in the same directory as the .env file. For windows download discord-compiler-bot.exe & for linux download discord-compiler-bot.
  3. Start the bot

⚖️ License

This project's license is the GNU AGPLv3 general purpose license. Review it here.

🖼️ Icons

Icons made by Freepik and pixelmeetup from www.flaticon.com

discord-compiler-bot's People

Contributors

asherkin avatar christopherwmm avatar durocodes avatar halalaluyafail3 avatar headline avatar impact123 avatar sighery avatar starkrights avatar thatghostyt avatar thomasbyr avatar tuti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-compiler-bot's Issues

Add support for raw.githubusercontent.com

I think adding github's raw links straight from regular repositories would make a lot of sense instead of just supporting gists. This would make it a lot easier for people with existing repositories of scripts to just paste the link in and see it working instead of having to copy the text over to pastebin.

Assembly for Javascript---infinite loop

The following code hasn't finished being compiled into assembly (via ;asm js), and it's been 45 minutes.

for (let i = 0; i<i+++--i; i+=i--+(++i)) {
  console.log(i);
}

Pid 0 in bash compile

When you compile in bash
"kill -19 0" the bot stop and if you delete te message it returns "Critical error: Unkown Messege"

Haskell Broken

Getting this for a simple hello program:

/usr/bin/ld.gold: error: cannot find -lnuma

rts/posix/OSMem.c:370:0: error:
     error: undefined reference to 'mbind'

rts/posix/OSMem.c:748:0: error:
     error: undefined reference to 'numa_num_configured_nodes'

rts/posix/OSMem.c:758:0: error:

Discord command:

;compile haskell
```haskell
main = print "hello"
```

Bot down

Compiler is offline, as shown in the picture.

image

Serenity dependency

project does not compile with current serenity version v0.11.1
could you provide a more specific version to use with the current state of the master branch?

Arbitary reqwest::Error

It happend literally yesterday when I wanted to run the .exe release file but instead I get:

INFO discord_compiler_bot > Registering owner(s): 559039176905850880 Error: reqwest::Error { kind: Decode, source: Error("missing field provider", line: 1, column: 1441) }

Now sorry if I don't have more information, because I literally copied and paste the .env example from the root tree and I ran the standalone exe and I get this. It is not my bots fault as I verified other discord code working on my bots. But this might be Discord's new privacy policy or something but it literally work the day before.

EOFError: EOF when reading a line

Hello, I'm having an issue that whenever I run code with an input(), "I get EOFError: EOF when reading a line", but a simple print() doesn't. I'm compiling python.
image
image

Migrate from Wandbox to Compiler Explorer

This is something that I've been tossing around in my head for a little bit but I'd like to formalize the migration publicly.

We will be migrating to use more of Compiler Explorer and less of Wandbox. I'll explain how it works now and then how it'll work in the future.

As of now all assembly requests are executed by Compiler Explorer and all execution requests are executed by Wandbox. This will be changing to default all execution requests to Compiler Explorer, if Compiler Explorer does not support the language then we will fallback to Wandbox. With this system, we will not lose support for any languages.

With this system, we will move a majority of our requests to a more reliable platform that I think can be better aligned with the spirit of this project. We have great communication and help with Compiler Explorer, so I'm drawn to make this change.

What's also on the table is downtime fallback. If Compiler Explorer were to drop our request, API error, or otherwise unable to fulfill a request we can rely on Wandbox to fulfil the request. This logic could be confusing, but for the large majority of our requests, no one cares what compiler or interpreter is used.

Output format: Get rid of the embed and use a code block

Honestly, and I have heard a decent number of people share this opinion, but the output from code execution would look a lot better if it just used a standard code block. The one thing the embed has going for it is that it provides more color contrast. If the output were made into an embed, there would also be more room for multi-page output. The RichEmbed compresses the code in a small text area, and it isn't great for code viewing.

I hope this FR can be considered.

How do you change certain stuff (help wanted)

Hey! I have this bot in my server and it's great! But what I wanted to know is how to remove the vote and botinfo command since I don't really need them and also how to customise what emotes the bot reacts with

Failure on invalid assembly compiler

Looks like we're missing a check here for when the compiler cannot be resolved, it was previously assumed that we can already resolve the compiler at this point, but the code path for assembly requests are different than compilation and has different guarentees.

We just need to return a CommandError here for invalid target

let compiler = self.gbolt.resolve(&parse_result.target).unwrap();

Dec 16 00:13:27 gabriel discord-compiler-bot[30098]: thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', src/managers/compilation.rs:99:65
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]: stack backtrace:
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:    0: rust_begin_unwind
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:    1: core::panicking::panic_fmt
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:    2: core::panicking::panic
Dec 16 00:13:27 gabriel discord-compiler-bot[30098]:              at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5

Feature Request: Support for reacting with default emojis

Currently custom emojis are required to self-host the bot, as default (unicode based) emojis don't have a 64 bit snowflake-ID. This could be implemented as defaults to fall back to when no emoji is specified in .env

The react roles for the ;languages command work with the default emojis, so hopefully this won't be too hard.

Incorrect server count in presense string

There's something flawed with how we increment the server count which causes the presence to display an incorrect (sometimes grossly incorrect) value. I haven't investigated much into why this is happening, but something is awry.

On top of this - some shards display server counts that are different than other shards.

Our proper server count is 2,396 servers. This is the display value.

Process OOM shutdowns

Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - process out of memory
 1: node::Abort() [/usr/bin/node]
 2: 0x11e7fec [/usr/bin/node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [/usr/bin/node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/bin/node]
 5: 0xad2f0b [/usr/bin/node]
 6: v8::internal::MarkCompactCollector::Evacuate() [/usr/bin/node]
 7: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/bin/node]
 8: v8::internal::Heap::MarkCompact() [/usr/bin/node]
 9: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/bin/node]
10: 0xe79a68 [/usr/bin/node]
11: v8::internal::Heap::HandleGCRequest() [/usr/bin/node]
12: v8::internal::StackGuard::HandleInterrupts() [/usr/bin/node]
13: v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/bin/node]
14: 0x1ccc456042fd
error: Forever detected script was killed by signal: SIGABRT
error: Script restart attempt #8

Support for Julia Language

Hello!

I'm a big fan of this bot because of what it can do on discord servers! It can compile almost any language I can think of. Yeah, the almost is bugging you out isn't it? Same for me!

It would be really great if Julia compilers are added too! That's a language that uses math a lot and can sometimes help us do math programmatically. Which calls for Julia's compilers' need.

I hope this issue is considered as soon as possible!

;cpp command fails to ignore brackets within comments

The following (valid) code fails to compile
image
This is because the function get_statement_end in src/cppeval/eval.rs keeps track of the number of open brackets to ensure the code is valid, but it fails to ignore brackets that are commented out.

fn get_statement_end(&self) -> usize {
let mut balance = 0;
let mut stop_idx = 0;
let mut ignore = false;
let mut last = '\0';
for (index, char) in self.input.chars().enumerate() {
// prevent } in print statements from messing up our balance, we keep track of the
// last character parsed in order to detect escaped quotes that way we know which
// quotes indicate the start of a string and which ones do not.
if (char == '\'' || char == '"') && last != '\\' {
ignore = !ignore;
}
if ignore && last != '\\' {
last = char;
continue;
}
// balance our braces
if char == '{' {
balance += 1;
}
if char == '}' {
balance -= 1;
}
if balance == 0 {
stop_idx = index;
break;
}
last = char;
}
stop_idx
}

Allow users to edit requests

We need a feature that lets users edit requests after their original execution that way users don't have to go back and submit an entirely new request for small mistakes.

Enhance C/C++ preprocessor output

It'd be great to take advantage of CE's preprocessor tool when -E is used during C/C++ compilation. The preprocessor tool automatically filters out headers, junk line directives which clutter even the most simple of preprocessor results, and can also automatically format the output. Demo: https://godbolt.org/z/bxoj4fzq7.

The API for this is undocumented but a simple request for the preprocessor tool looks like:

{
  source: '...',
  options: [  ],
  backendOptions: {
    producePp: { 'filter-headers': true, 'clang-format': true },
    produceGccDump: {},
    produceCfg: false,
    produceDevice: false
  },
  filters: {
    binary: false,
    execute: false,
    demangle: true,
    intel: true,
    commentOnly: true,
    directives: true,
    labels: true,
    optOutput: false,
    libraryCode: true,
    trim: false
  },
  bypassCache: false,
  tools: [],
  executionParameters: { args: [], stdin: undefined },
  libraries: []
}

Maybe this could be done for both ;compile and ;asm.

Menu system creates page emotes when only one page exists

Easy fix for someone looking to get contributions.

The following snippet shouldn't execute when max page count is <2

that.collector = result.createReactionCollector((reaction, user) => {
if (that.targetid == user.id
&& (reaction.emoji.name === that.left
|| reaction.emoji.name == that.stop
|| reaction.emoji.name == that.right)) {
that.collectionuser = user;
return true;
}
return false;
}
).once("collect", reaction => {
const chosen = reaction.emoji.name;
if (chosen == that.left) {
if (that.page > 0)
that.displayPage(--that.page)
else
that.displayPage(that.page)
}
else if (chosen == that.right) {
if (that.page + 1 > that.getMaxPage())
that.displayPage(that.page)
else
that.displayPage(++that.page);
}
else if (chosen == that.stop) {
result.clearReactions().then((r) => that.collector.stop());
that.timeout.stop();
return;
}
that.timeout.restart();
reaction.remove(that.collectionuser).catch();
});

Want another language or compiler added? Read me!

Hi!

For our compilation requests we rely on the service Godbolt or Wandbox to process user requests.

What this means is that our project cannot add new languages or compilers, but any new additions Godbolt or Wandbox make we will inherit. Please search out for these projects and direct the feature requests to them. If the request is approved and completed then the bot will be able to support the new language within 24 hours.

Thanks!

Improve API Failure Error Message

As indicated by the failed tests, the latest commit leaves the bot in an unusable state:

Wandbox request failure 
 FetchError: invalid json response body
at https://wandbox.org/api/compile.json

reason: Unexpected token < in JSON at position 0 
Please try again later

Feature request: persistent option to make output less verbose

This is the embed currently generated by default:
2021-06-13_12-43-48

This can take over a half of available screen height (and on mobile devices, possibly not fit on the screen at all), which can break the flow of discussion. Meanwhile a lot of information provided are either not useful at the moment or (subjectively) not needed in general:

  • return status code (it's 0 in a vast majority of uses)
  • headers
  • reactions like :checkmark2:
  • possibly even the "Requested by" part (especially if the code block is directly above the embed)

Meanwhile, the build_small_compilation_embed function added in #98 shows it in a nice compact fashion:
2021-06-13_12-43-58

It would be nice to be able to somehow enable this compact embed for all compile output messages, either for a single message message, or in the scope of entire channel/server.

Parser fails to terminate on line break

Here's an example of the input that breaks the parser

;asm python38
wynik = 0
i = 0


while i < 3 :
    x = int(input("podaj liczbe parzystą: "))
    if ( x % 2 == 0):
        wynik += x
        i += 1
    else:
        print("podaj liczbe parzystą.")
    continue

print ("wynik dodawania to: ", wynik)

What's happening is that the parser is constantly looking for the beginning of a code block, which it never reaches due to the malformed input. The parser in turn is also looking for < inputs to indicate a url code request. When it hits the while loop, everything after the < is loaded in as a url. The bot then fails with "Invalid hostname or protocol" linked below
http://i.michaelwflaherty.com/u/ymoOvq3Rwg.png

Replace alternate quote chars with compiler-accepted counterparts

Please consider replacing the following respectively because people on phones cannot use " and ' also iirc those quotes used in phones aren't used in any of the languages for a particular use although you could add an ability that escaped ones aren't replaced

for example: will be replaced but \“ won't be.

-> "
-> "
-> '
-> '

Support for external libraries for languages

Hello!

This bot works great! But it would be much better if the bot supported external libraries (say numpy for Python, etc.) either as arguments:

;compile python -libs=['numpy', 'matplotlib', 'cv2', 'dyepy']
```py
import numpy as np
import matplotlib.pyplot as plt
import cv2
import dyepy

# Code
```

or any other method that lets us use a particular module(s) (any module that is publicly available to others).

I hope this issue is considered as soon as possible.

command line arguments on file attachment

Hello,

Suppose we send a single file (a file, not a code block) main.c
and we reply to our message with

;compile c
argv1 argv2

The bot considers argv1 and argv2 as files and not as command line arguments.
(the same behavior occurs when we reference a code in pastebin with <)

That would not occur if we typed in, in a single message

;compile c
argv1 argv2
```c
#include <stdio.h>

int main(int argc, char *argv[]) {
   ...
}
```

Am I missing something?

Compiler parsing malformed on two spaces

It seems that the parsing logic fails with the following case:

;compile c++  -Wall
```cpp
int main() {

}
```

with two spaces preceeding -Wall the output from the bot is always a compiler error in the form of

/usr/bin/ld: cannot find : No such file or directory
collect2: error: ld returned 1 exit status

rs not trimmed properly

In the following command, the rs does not get trimmed properly (assume it's intended properly, I can't figure out how GitHub markdown works):

;compile rust
```rs
fn absoluteValue(num: i64) -> i64 {
return if num > 0 {
num
} else {
-num
}
}

fn main() {
println!("{}", abs(-2));
println!("{}", abs(2));
}
```

Leading to the following bizarre error message:

error: expected one of `!` or `::`, found `fn`
 --> prog.rs:2:1
  |
1 | rs
  |   - expected one of `!` or `::` here
2 | fn absoluteValue(num: i64) -> i64 {
  | ^^ unexpected token

error: aborting due to previous error

Meaning it thinks line 1 is rs and line 2 is the function signature.

The correct error message is this:

error[E0425]: cannot find function `abs` in this scope
  --> prog.rs:11:19
   |
11 |    println!("{}", abs(-2));
   |                   ^^^ not found in this scope

error[E0425]: cannot find function `abs` in this scope
  --> prog.rs:12:19
   |
12 |    println!("{}", abs(2));
   |                   ^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

This issue is not present if rust is used or if the error made is fixed (renaming absoluteValue to abs).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.