starcraft66 / minecraft-discord-bridge

A minecraft <-> discord bridge with no server-side requirements
Apache License 2.0
30 stars 9 forks source link

Commands #36

Open Stronkfish opened 5 years ago

Stronkfish commented 5 years ago

Idea: Add the ability to use commands such as joindate, this could be implemented by giving the bot a command (e.g. !command joindate) or making the command direct instead of posting "/joindate (username)" in public chat

starcraft66 commented 5 years ago

Thanks for opening this issue. This was brought up a long time ago and I never got to implementing it.

I think we could add a command called something like mc!command or mc!exec to allow users to execute commands via the bot. My biggest concern at the moment is how to deal with commands that return output back to the user. I don't think that command output should be returned into the main chat feed because it is only relevant to the user who executed the command. The problem is that there is no guaranteed way to find out exactly what received messages to send back to the user executing a command because technically speaking, there is nothing linking the chat output to the executed command. One way to do it would be to blindly assume that any chat messages received within a few seconds after executing the command that don't match any other regexes are the command's output.

starcraft66 commented 5 years ago

After having sleept on this for a while, I think that adding a plug-in system to the bridge would be the best way to handle this feature. Since this bridge aims to be compatible with any minecraft server, it is not reasonable for it to attempt to support parsing the output of commands not featured in the vanilla Mojang minecraft server implementation.

For example, a plug-in specifically tailored to the constantiam.net server could be loaded and register a callback associated to a regex pattern corresponding to the output of a command. Another way would be for the plugin to register an event handler for every incoming chat message and decide what to do with them. I still need to think about these approaches some more in order to handle matching command output sprawled over multiple lines (causing multiple seperate events to fire or several passes of the regex parse) that would need to be put back together before being sent to a user.