Closed dreeves closed 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:
plat
= a string like "discord" or "slack" saying what platform we're on, which we generally expect the business logic to not care aboutchan
= the channel that the message was sent in, eg, "botspam" or "games" or "DM" (and maybe this is actually 2 parameters, for channel name and channel ID, but we have no use case for caring about the channel ID so far)user
= the username of whoever is sending this messagemesg
= the actual string that the user typed, eg, "/bid my bid is $12"msid
= the message ID that the platform assigned to the user's message, which will be null if it's not an actual message in the channel, as it won't be if the user sent it by invoking a slash command, for examplepriv
= whether the message was sent to Omnibot privately which is the case if it was DM'd, is sent as a webhook, or sent by invoking a slash commandrfun
= a reply function that the business logic uses to send its replyAnd rfun
itself takes the following parameters:
plat
= the platform, typically whatever plat
was specified in the incoming message but maybe we'll make some sort of Slack/Discord bridge, who knows.chan
= the channel to send touser
= the username of who we're sending this tomesg
= the text of the message to sendpriv
= whether we're sending this privately to the recipient, eg, replying to a slash command in whisper modemrid
= message ID to make this a reply toThe 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:
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).
"the bot replies to privately, probably as a DM"
Should priv
mean "reply as DM"?
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.
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:
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:
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.