nv-vn/glgbot

Switch to passing limited version of the Bot module to commands

Closed this issue · 1 comments

nv-vn commented

Currently, commands work with the Command.action type to give the command handler a set of actions to run from a predefined set of possibilities. It might be beneficial to switch to a system where a small module containing the actual functions here is passed to the command as a first-class module.

nv-vn commented

Considering the extra amount of effort that's been put into the current system (which emphasizes side-effect free code), I think changing this is probably unnecessary. Also, if one needs to implement this I think the generic solution:

module ProxyBot = Api.Mk (struct
  let token = my_token
  let commands = []
end)

module MainBot = Api.Mk (struct
  let token = my_token
  let commands = actual_commands
end)

where actual_commands are accessing the proxy bot. Of course, commands aren't shared to the proxy, but it's likely that I'll be making commands a ref in the near future anyways (this could serve the double purpose of allowing you to declare the commands outside the module and then manually adding them in yourself, which would work as an alternative solution to this problem).
Another alternative may be to generalize the functor interface to have a token -> 'a version of each function in another module and then just automatically apply the args for you inside the functor, but this will complicate things by adding duplicate code and requiring the user to hand the command list to pop_update each time, plus it would make it confusing which interface to use and what a TELEGRAM_BOT actually does.
However, given that the action interface, as it exists right now, has nearly full coverage of the API, it's unlikely that we'll need a more powerful alternative.

If you feel otherwise, please comment on here and give input. For now, I'm keeping this as WONTFIX.