engineer-man / piston-bot

I Run Code bot on Discord
https://emkc.org/run
MIT License
239 stars 35 forks source link

Parse attachments as input code #36

Closed ParadauxIO closed 3 years ago

ParadauxIO commented 3 years ago

Messages on discord our limited to 2,000 characters -- It would be nice if you were to get the attachment from the CDN and compile/run that

For example:

realtux commented 3 years ago

i like this idea, let me look into this

brtwrst commented 3 years ago

We had that come up multiple times before. The reason it was not done until now is that it will no longer be "one look" to see the code and the result.

I thought the discord bot was meant to be used for "small" code snippets to demonstrate or explain something.

Making it run files is possible of course, but should a discord bot be the place to run "big" files in the first place?

realtux commented 3 years ago

it is. big in this case just means > 2000 characters, which is discord's message size limit. on programs with lots of indentation and whitespace, sometimes 2000 characters could be as little as 30-40 lines.

realtux commented 3 years ago

maybe this is an opportunity to upload to snippets as well, then post the link to the snippet + the output

brtwrst commented 3 years ago

For me discord is not the place to run programs with 30+ lines.

Wasn't there a Piston online IDE in the works or something?

brtwrst commented 3 years ago

Of course implementing this if we want to try it should be straight forward.

realtux commented 3 years ago

re: piston ide, there was but the guy disappeared. we'd have to take that project on ourselves if we wanted it. the function here is pretty close to the same as snippet upload, but with the additional step of sending it to piston.

brtwrst commented 3 years ago

I just saw the new file preview feature in discord, with that this suggestion could finally become a valid option.

brtwrst commented 3 years ago

So I played with it a bit. Taking attachments as input can work there are just a few things we have to specify.

Ideas?

brtwrst commented 3 years ago

image Putting the bots output into files comes with 1 big obstacle. You cannot edit the file in the output message so that would break the editing portion of the bot. We can either keep the the current system (output in a codeblock - truncate if necessary) or display long output as a file but disable editing for these.

Putting output in files might also have some unknown sideffects which are not apparent right now.

Ideas?

ParadauxIO commented 3 years ago

Thanks for all the work you've put into this to date!

I believe that as long as users know that they can't edit the file attachments after running them that's perfectly fine, sounds like something you could put into the embed footer as a reminder. Truncating the output or sticking it in https://paste.gg / something like that sounds like it'd work pretty well.

I know for one, all codeblocks that are submitted on our discord server get uploaded to paste.gg anyway for our IRC bridge so as not to spam it out.

brtwrst commented 3 years ago

Thinking some more - I decided that I probably don't want to break any existing functionality. Specifically - if someone runs the bot with a codeblock it should always be editable (like it is now). This means not using a file as the output.

I also find it hard to justify outputs > 2000 chars. Those mostly happen with endless loops that print suff.

So I will look into adding the functionality of providing text files (now that they are very readable inside discord) but I won't change the way the output gets returned just yet.

brtwrst commented 3 years ago

first version is up and running - have fun trying to break it