aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Bot.hs2
-rw-r--r--src/Plugin.hs46
2 files changed, 45 insertions, 3 deletions
diff --git a/src/Bot.hs b/src/Bot.hs
index fe1b0a1..8b78497 100644
--- a/src/Bot.hs
+++ b/src/Bot.hs
@@ -17,3 +17,5 @@ newtype Bot a = Bot
{ runBot :: ReaderT Options IO a
-- } deriving (Monad, Functor, Applicative, BotConfig, MonadIO)
} deriving (Monad, Functor, Applicative, MonadReader Options, MonadIO)
+
+-- instance MonadPlus Bot
diff --git a/src/Plugin.hs b/src/Plugin.hs
index a79e815..04a8054 100644
--- a/src/Plugin.hs
+++ b/src/Plugin.hs
@@ -4,6 +4,7 @@ module Plugin
, plugins
) where
+import Control.Monad (mzero)
import qualified Data.Text as T
import Text.Regex.TDFA
@@ -16,15 +17,54 @@ import Plugin.Help (help)
-- | Get the first plugin that matches the given message text.
matchPlugin :: M.Message -> Maybe (Bot Plugin)
-matchPlugin message = firstPlugin $ matchPlugins message plugins
+matchPlugin message = do
+ -- plugins' <- return $ sequence plugins
+ -- firstPlugin $ matchPlugins message plugins'
+ return $ firstPlugin $ matchBotPlugins message
where
- firstPlugin [] = Nothing
- firstPlugin (p:ps) = Just p
+ firstPlugin :: Bot [Plugin] -> Bot Plugin
+ -- firstPlugin [] = Nothing
+ -- firstPlugin (p:ps) = Just p
+ firstPlugin plugins = do
+ plugins' <- plugins
+ case plugins' of
+ -- [] -> mzero
+ [] -> fail "Empty plugin list"
+ (p:ps) -> return p
+
+ -- matchBotPlugins :: M.Message -> [Bot Plugin]
+ -- matchBotPlugins message = do
+ -- -- plugins' <- sequence plugins
+ -- -- return $ matchPlugins message plugins'
+ -- return $ matchPlugins message plugins
+ matchBotPlugins :: M.Message -> Bot [Plugin]
+ matchBotPlugins message = do
+ plugins' <- sequence plugins
+ return $ matchPlugins message plugins'
-- | Filter the list of plugins to those that match the given message.
matchPlugins :: M.Message -> [Plugin] -> [Plugin]
matchPlugins message plugins =
[p | p <- plugins, M.textStr message =~ matchRegex p]
+ -- where
+ -- matches :: M.Message -> Bot Plugin -> Bool
+ -- matches message pluginM = do
+ -- p <- pluginM
+ -- M.textStr message =~ matchRegex p
+-- ---
+-- matchPlugins :: M.Message -> [Bot Plugin] -> [Bot Plugin]
+-- matchPlugins message plugins =
+-- [p | p <- plugins, matches message p]
+-- where
+-- matches :: M.Message -> Bot Plugin -> Bool
+-- matches message pluginM = do
+-- p <- pluginM
+-- M.textStr message =~ matchRegex p
+-- ---
+-- matchPlugins :: M.Message -> [Bot Plugin] -> [Bot Plugin]
+-- matchPlugins message plugins = do
+-- _ <- return $ sequence plugins
+-- [return p | p <- plugins', M.textStr message =~ matchRegex p]
-- | Run the action belonging to the plugin, stored in its `perform` field.
performPlugin :: Plugin -> PluginAction