yellowtides / owenbot-hs

A utility bot written in Haskell for the Edinburgh Informatics Class of ‘24’s main messaging platform (Discord server).
https://yellowtid.es/owenbot-hs/
BSD 3-Clause "New" or "Revised" License
8 stars 7 forks source link

Message edits are incapable of triggering commands #18

Open yellowtides opened 3 years ago

yellowtides commented 3 years ago

Current functionality

https://github.com/yellowtides/owenbot-hs/blob/ebbe9937a360b61edfc64185f0d037b36f16eeca/src/EventHandler.hs#L58-L59

As can be seen in the above highlighted lines of code, commands can currently only get triggered by creating a new message.

Reasoning

Message edits are not capable of triggering commands. It would be a nice addition if they would also get processed on message edits, as our : prefix makes Discord emoji autocompletion typos quite common.

(e.g. :fortune → 🥠 | :fortune:)

Potential solution

Pattern match on the MessageUpdate Message Event data constructor in order to also detect message edits. Further modularise the message creation event handler into its own function, which should be triggered on both event sub-types.

E.g.

handleEvent event = case event of
     MessageCreate m -> 
          consultReceiversOnHumanMessage m
     MessageUpdate m -> 
          consultReceiversOnHumanMessage m
     -- // SOME LINES REDACTED  FOR VISIBILITY //
     where
          consultReceiversOnHumanMessage m = unless (isFromBot m) $ consultMessageReceivers m
          consultMessageReceivers m = forM_ messageReceivers ($ m) <|> pure ()
social-anthrax commented 3 years ago

Could be useful, however, most bots do not implement this even if it is supported by the module. This is to stop the bot from going back through messages and replying multiple times due to the user fixing a spelling mistake. It's normally safer to just let the user send another command.

jacobjwalters commented 3 years ago

Some bots (e.g. MathBot) do track edits, but these often take large inputs (such as entire TeX expressions or the likes). Since the majority of owen's commands are only two words long, I don't think it's (currently) a high priority at all.

yellowtides commented 3 years ago

Fully agreed @9nine9nine9, as this would also require a messageID -> [replyID] mapping that Owen could use in order to clean up replies after every message edit. I will change this to low priority.