diff options
author | Teddy Wing | 2017-08-20 00:14:46 +0200 |
---|---|---|
committer | Teddy Wing | 2017-08-20 00:14:46 +0200 |
commit | 2d94eb37d15032636acb08af43e3c5906bedcc45 (patch) | |
tree | c9fc9bff5dbfc27c548cd2b5f84cd676771fdda1 /src/Plugin/Base.hs | |
parent | 1884f2e54097bdce9a4a011065a89044c86a8ebf (diff) | |
download | sorbot-2d94eb37d15032636acb08af43e3c5906bedcc45.tar.bz2 |
Add Help plugin
A new plugin that displays a help listing for every plugin in the bot.
Currently the formatting is off in the chat output, but it does work.
This introduces two new record fields on `Plugin`: `command` and
`description`. The command is the text used to invoke the plugin and the
description is a long form explanation of what the plugin does.
Needed to update the `Show` for `Plugin` to match these extra fields.
Didn't change any of the output for now because I'm not really using the
`show` function, so I don't need to see the new fields for now. Also
change the `p` argument to an `_` because we're not using it.
All existing plugins now have the new fields filled. The Help plugin
will go through the list of all plugins and get their help fields for
output.
In order to be able to use the plugin list in both `Plugin.hs` and in
the Help plugin module, I needed to move the list into a new module to
avoid a circular dependency. Previously the `Plugin` module defined the
list, but we can't import `Plugin` from `Help` because `Plugin` needs to
import `Help` in order to build the full list of plugins. The
semi-hackish solution I came up with was to create a new module for the
plugin list that both these modules can use, but leave out the `Help`
plugin from the plugin list there. Then, `Plugin` and `Help` override
the list, appending the `Help` plugin to the list. I want the Help
plugin to appear last, which is why I'm appending. Wasn't comfortable
concatenating the list because of the performance smell, but it's going
to be a small enough list anyway that it shouldn't be a problem.
One thing I don't really like is the fact that we have to return an
`IO a` from `helpAction` even though it doesn't interact with `IO` at
all. Not sure if there's a way to use `IO` when we need it and not when
we don't. Not a huge deal though.
Diffstat (limited to 'src/Plugin/Base.hs')
-rw-r--r-- | src/Plugin/Base.hs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs index 62900c7..ac67e71 100644 --- a/src/Plugin/Base.hs +++ b/src/Plugin/Base.hs @@ -13,9 +13,11 @@ import Message type PluginAction = Message -> IO (Either T.Text T.Text) data Plugin = Plugin - { matchRegex :: String - , perform :: PluginAction + { matchRegex :: String + , perform :: PluginAction + , command :: T.Text + , description :: T.Text } instance Show Plugin where - show (Plugin r p) = "matchRegex = " ++ r + show (Plugin r _ _ _) = "matchRegex = " ++ r |