Learning from last time's long changelog, this one's left short and to the point.
Read the generated Haddock documentation (after this is merged) to read more if you want!
Commands
"Commands" are now a solid thing, instead of just a wrapper function like newCommand. It can be constructed using the command function from the Command module.
Commands use parsers and type magic to make it super duper intuitive to parse arguments, instead of the captures thing of the past
Functions can be composed to override default behaviour
Commands can be converted to your normal receivers, or can be used to dynamically generate help messages
Example
receivers =
[ runCommand setStatus,
, runCommand ...
, runHelp [setStatus, ...]
]
simple :: Command DiscordHandler
simple = command "ping" $ \msg -> respond msg "pong!"
setStatus :: Command DiscordHandler
setStatus
= prefix "~~!"
. requires (\msg -> pure $ Just "needs special privs!")
. requires (\msg -> isUserMod msg >> pure $ Just "another permission issue!")
. help "this command cannot be run because no one has the privs"
. command "status"
$ \msg newStatus newType (Remaining newName) -> do
-- newStatus is automatically parsed to UpdateStatusType,
-- newType is parsed to ActivitiyType,
-- and newName to T.Text
updateStatus newStatus newType newName
respond msg "Status updated :) Keep in mind it may take up to a minute for your client to refresh."
Aux
Commands can be declared with "command", but if the syntax is unorthodox, there are regexCommand and parsecCommand where you can specify your own parsers (for owo, dad joke, or whatever)
MonadDiscord
Optionally, functions operating in DiscordHandler can now be made polymorphic with MonadDiscord.
This is optional because some receivers rely on being inside DiscordHandler specifically (like setStatus), and those don't need to be abstracted (nor if there is no need to use/test anything from another context)
ReaderT Auth IO is also a MonadDiscord, so you can make REST requests from pure IO like this:
-- create a message from pure IO using an Auth token
main :: IO ()
main = runReaderT func (Auth "<token here>")
-- create a message from a discord handler
receiver :: DiscordHandler ()
receiver = func
-- polymorphic function
func :: (MonadDiscord m) => m ()
func = void $ createMessage (read "123123") "This is sent from polymorphic function"
The use of restCall $ R. should gradually be replaced with the replacements from this dataclass (like createMessage). It also handles all the Either RestCallErrorCode thing for you, so receivers are bound to be much much more simpler.
Learning from last time's long changelog, this one's left short and to the point.
Read the generated Haddock documentation (after this is merged) to read more if you want!
Commands
newCommand
. It can be constructed using thecommand
function from theCommand
module.captures
thing of the pastExample
Aux
regexCommand
andparsecCommand
where you can specify your own parsers (for owo, dad joke, or whatever)MonadDiscord
MonadDiscord
.ReaderT Auth IO
is also aMonadDiscord
, so you can make REST requests from pure IO like this:restCall $ R.
should gradually be replaced with the replacements from this dataclass (likecreateMessage
). It also handles all theEither RestCallErrorCode
thing for you, so receivers are bound to be much much more simpler.