aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Plugin/Factorial.hs20
-rw-r--r--src/Plugin/GitRemoteSetOrigin.hs7
-rw-r--r--src/Plugin/Help.hs32
-rw-r--r--src/PluginList.hs3
4 files changed, 39 insertions, 23 deletions
diff --git a/src/Plugin/Factorial.hs b/src/Plugin/Factorial.hs
index 9284fe7..9d7a169 100644
--- a/src/Plugin/Factorial.hs
+++ b/src/Plugin/Factorial.hs
@@ -7,20 +7,24 @@ module Plugin.Factorial
import Text.Regex.TDFA ((=~))
import TextShow (showt)
+import Bot (Bot)
import qualified Message as M
import Plugin.Base
-factorial = defaultPlugin
- { matchRegex = "^([0-9]+)!$"
- , perform = factorialAction
- , command = "<integer>!"
- , description = "Calculate the factorial of <integer> for whole numbers \
- \up to 35000."
- }
+factorial :: Bot Plugin
+factorial = do
+ return defaultPlugin
+ { matchRegex = "^([0-9]+)!$"
+ , perform = factorialAction
+ , command = "<integer>!"
+ , description = "Calculate the factorial of <integer> for whole numbers \
+ \up to 35000."
+ }
factorialAction :: PluginAction
factorialAction message = do
- case M.textStr message =~ matchRegex factorial :: [[String]] of
+ plugin <- factorial
+ case M.textStr message =~ matchRegex plugin :: [[String]] of
[] -> return $ Left "I didn't understand"
(m:_) -> do
let number = last m
diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs
index 0fdb4ef..7d46e46 100644
--- a/src/Plugin/GitRemoteSetOrigin.hs
+++ b/src/Plugin/GitRemoteSetOrigin.hs
@@ -10,10 +10,12 @@ import qualified Data.Text as T
import Database.SQLite.Simple
import Text.Regex.TDFA ((=~))
+import Bot (Bot)
import qualified Message as M
import Plugin.Base
-gitRemoteSetOrigin = defaultPlugin
+gitRemoteSetOrigin :: Bot Plugin
+gitRemoteSetOrigin = return defaultPlugin
{ matchRegex = "^git remote set origin ([^ ]+)$"
, perform = gitRemoteSetOriginAction
, command = "git remote set origin <url>"
@@ -22,7 +24,8 @@ gitRemoteSetOrigin = defaultPlugin
gitRemoteSetOriginAction :: PluginAction
gitRemoteSetOriginAction message = do
- case M.textStr message =~ matchRegex gitRemoteSetOrigin :: [[String]] of
+ plugin <- gitRemoteSetOrigin
+ case M.textStr message =~ matchRegex plugin :: [[String]] of
[] -> return $ Left "blast"
(m:_) -> do
let url = last m
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]
diff --git a/src/PluginList.hs b/src/PluginList.hs
index bd2af35..070033a 100644
--- a/src/PluginList.hs
+++ b/src/PluginList.hs
@@ -2,6 +2,7 @@ module PluginList
( plugins
) where
+import Bot (Bot)
import Plugin.Base (Plugin)
import Plugin.Factorial (factorial)
import Plugin.GitHubCommit (gitHubCommit)
@@ -9,7 +10,7 @@ import Plugin.GitRemoteSetOrigin (gitRemoteSetOrigin)
-- | The list of plugins to load, minus the Help plugin, which would otherwise
-- cause a circular import.
-plugins :: [Plugin]
+plugins :: [Bot Plugin]
plugins =
[ factorial
, gitHubCommit