Nathan13888 / CodeRunnerBot

Smart Discord Bot that runs almost any code of any supported language. Powered by Go and engineer-man/piston. Runs on Docker and code execution network could be distributed.
GNU General Public License v3.0
5 stars 2 forks source link

use piston endpoint for languages rather than hardcoding them. #6

Closed vidhanio closed 2 years ago

vidhanio commented 2 years ago

Closes #4.

Unfortunately not possible (?) for the mappings as they require hardcoded values which I have retrieved from pygments.

If either @wozeparrot or @Nathan13888 figure out a way to do this, please lmk :)

vidhanio commented 2 years ago

Ok, nvm this is not ready to push. Weird nil pointer dereference error trying to retrieve languages from this wrapper...

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x1051e9b68]

goroutine 1 [running]:
github.com/milindmadhukar/go-piston.(*Client).GetLanguages(0x1400011dbf0)
        /Users/vidhanio/go/pkg/mod/github.com/milindmadhukar/go-piston@v0.0.0-20211122120254-64da61081d05/piston.go:58 +0x48
main.GetLanguages()
        /Users/vidhanio/Projects/CodeRunnerBot/exec.go:30 +0x5c
main.init()
        /Users/vidhanio/Projects/CodeRunnerBot/bot.go:156 +0x28
wozeparrot commented 2 years ago

I'll take a look at this as well

wozeparrot commented 2 years ago

Not really sure why they are required to be hard-coded.

vidhanio commented 2 years ago
The data looks like this. ```go var languageMappings = map[string][]string{ "awk": {"awk"}, "bash": {"bash", "sh", "zsh", "ksh", "shell"}, "befunge93": {"befunge"}, "brainfuck": {"brainfuck", "bf"}, "c": {"c"}, "c++": {"cpp", "c++", "h"}, "cjam": {}, "clojure": {"clojure", "clj", "clojurescript", "cljs"}, "cobol": {"cobol"}, "coffeescript": {"coffeescript", "coffee-script", "coffee"}, "cow": {}, "crystal": {"cr", "crystal"}, "csharp": {"csharp", "c#", "cs", "aspx-cs"}, "csharp.net": {}, "d": {"d"}, "dart": {"dart"}, "dash": {}, "dragon": {}, "elixir": {"elixir", "ex", "exs"}, "emacs": {"emacs-lisp", "elisp", "emacs"}, "erlang": {"erlang"}, "file": {}, "forte": {}, "fortran": {"fortran"}, "freebasic": {"basic"}, "fsharp.net": {}, "fsi": {"fsharp", "f#"}, "go": {"go", "golang"}, "golfscript": {}, "groovy": {"groovy"}, "haskell": {"haskell", "hs"}, "husk": {}, "iverilog": {"verilog", "v"}, "japt": {}, "java": {"java"}, "javascript": {"javascript", "js"}, "jelly": {}, "julia": {"julia", "jl"}, "kotlin": {"kotlin"}, "lisp": {"common-lisp", "cl", "lisp"}, "llvm_ir": {"llvm"}, "lolcode": {}, "lua": {"lua"}, "nasm": {"nasm"}, "nasm64": {}, "nim": {"nimrod", "nim"}, "ocaml": {"ocaml"}, "octave": {"octave"}, "osabie": {}, "paradoc": {}, "pascal": {"delphi", "pas", "pascal", "objectpascal"}, "perl": {"perl", "pl"}, "php": {"php", "php3", "php4", "php5"}, "ponylang": {"pony"}, "powershell": {"powershell", "pwsh", "posh", "ps1", "psm1"}, "prolog": {"prolog"}, "pure": {}, "pyth": {}, "python": {"python", "py", "sage", "python3", "py3"}, "python2": {"python2", "py2"}, "racket": {"racket", "rkt"}, "raku": {"perl6", "pl6", "raku"}, "retina": {}, "rockstar": {}, "rscript": {"rd"}, "ruby": {"ruby", "rb", "duby"}, "rust": {"rust", "rs"}, "scala": {"scala"}, "sqlite3": {"sql"}, "swift": {"swift"}, "typescript": {"typescript", "ts"}, "basic": {"basic"}, "basic.net": {}, "vlang": {}, "vyxal": {}, "yeethon": {}, "zig": {"zig"}, } ```

I dont think there is a more efficient way to put the correct aliases in for markdown mappings.

vidhanio commented 2 years ago

This wrapper really is not very good, we could try writing one ourselves.

wozeparrot commented 2 years ago

what does the wrapper return?

Nathan13888 commented 2 years ago

I agree, this wrapper is poorly written... You could just take PISTON_URL and append /runtimes and do a GET request then marshal it to a struct with json flag thingies.

vidhanio commented 2 years ago

Nvm, this wrapper rocks.

I used the aliases you get from the runtimes to generate the language mappings instead, and no more hardcoding required! 🚀

wozeparrot commented 2 years ago

Yup seemed like before you were just using the wrong api call.

vidhanio commented 2 years ago

I was using GetLanguages() correctly, but ig that method is kinda not working properly. GetRuntimes() works fine however, so this works for me.

wozeparrot commented 2 years ago

GetLanguages() just seems to return a list of languages that it supports, GetRuntimes() returns the full struct.

vidhanio commented 2 years ago

Yeah, I guess so.

Looks good @Nathan13888?

vidhanio commented 2 years ago

🚀🚀🚀🚀