dreeves / omnibot

Discord/Slack bot to play a dictionary guessing game and other things
1 stars 0 forks source link

Make a dispatcher #165

Closed dreeves closed 1 year ago

dreeves commented 1 year ago

Currently app.js is pretty confusing, mixing together a lot of setup code with some business logic. I'd like to separate out the following business logic:

  1. Omnibot's decision about what channels to pay attention to
  2. The regexes Omnibot uses to decide what to reply to

I'd also like to abstract away the concept of slash commands.

There should be a single dispatcher function that receives every message and decides what to do with it. Currently that includes something like the following:

  1. If the channel is #games or #spellingbee or matches #lexi.* and the message is a single word consisting of only letters then feed the message to lexiguess
  2. If the message starts with "/bid" then feed it to bid.js
  3. If the message starts with "/roll" then feed it to roll.js
  4. If the message starts with "/omninom" then feed it to omninom.js
  5. If the message at-mentions omnibot then... TBD
  6. Otherwise, ignore it.

I'm thinking the business logic shouldn't even understand the concept of slash commands at all. From the business logic's point of view, messages just come in as strings, some of which may happen to start with a slash character, and the dispatcher passes those messages to the appropriate submodule, all based purely on regexes.

PS: And of course we want it to be easy to add new rules/regexes to that list. And maybe webhooks (#159) can also be in that list. Hitting the webhook is treated the same as any other incoming message for the bot.

dreeves commented 1 year ago

Also there's DM'ing the bot. I'd like to capture all of these things in a nice general, flexible architecture. Proposal: Every incoming message that Omnibot is allowed to see hits the dispatcher as a hash like so:

And rfun itself takes the following parameters:

The rfun function returns the message ID of the sent message. (Maybe Javascript promises is the right way to implement that?)

Here's a review of how the above captures what we previously did with voxmode:

dreeves commented 1 year ago

PS: Actually now I'm not sure why rfun would want to be passed in, rather than just being a separate library function that the business logic can call when it wants to send a message.

PPS: And separately from all that we need a place to store the slash command metadata (description, usage hint, name of argument, whether argument is required).

jakecoble commented 1 year ago

"the bot replies to privately, probably as a DM"

Should priv mean "reply as DM"?

dreeves commented 1 year ago

After discussing on Discord, tentatively the answer is yes. We've got:

sendmesg(plat, fief, chan, user, mesg, mrid, priv, phem)

Specifying priv=true and phem=true is an error, presumably, if there's no such thing as an ephemeral DM.