From ea190de02cea99347ae125d86cc22bf8cd926c88 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 14 Sep 2017 03:44:38 +0200 Subject: Add `Bot` to rest of plugins Add our `Bot` monad to the rest of the plugins: * Factorial * GitRemoteSetOrigin * Help The only problem is with the Help plugin. Still trying to figure out how to set up my list comprehension so that it works with the `Bot`-wrapped `Plugin` list. --- src/Plugin/Help.hs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/Plugin/Help.hs') diff --git a/src/Plugin/Help.hs b/src/Plugin/Help.hs index 63143b1..b29d1b9 100644 --- a/src/Plugin/Help.hs +++ b/src/Plugin/Help.hs @@ -4,28 +4,36 @@ module Plugin.Help ( help ) where +import Control.Monad (sequence) import qualified Data.Text as T +import Bot (Bot) import qualified PluginList as PL (plugins) import Plugin.Base -help = defaultPlugin - { matchRegex = "^help$" - , perform = helpAction - , command = "help" - , description = "Show a list of available bot commands." - , queryOnly = True - } +help :: Bot Plugin +help = do + return defaultPlugin + { matchRegex = "^help$" + , perform = helpAction + , command = "help" + , description = "Show a list of available bot commands." + , queryOnly = True + } helpAction :: PluginAction helpAction _ = do return $ Right $ T.intercalate "\n" - [T.justifyRight longestCommandLen ' ' (command p) - `T.append` " – " - `T.append` description p - | p <- plugins] + -- [T.justifyRight longestCommandLen ' ' (command p) + -- `T.append` " – " + -- `T.append` description p + -- | p <- plugins'] where longestCommandLen = foldr (max) 0 (map (T.length . command) plugins) -plugins :: [Plugin] + helpText plugin = T.justifyRight longestCommandLen ' ' (command plugin) + `T.append` " – " + `T.append` description plugin + +plugins :: [Bot Plugin] plugins = PL.plugins ++ [help] -- cgit v1.2.3