diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Lib.hs | 7 | ||||
| -rw-r--r-- | src/Plugin.hs | 12 | ||||
| -rw-r--r-- | src/Plugin/Base.hs | 4 | ||||
| -rw-r--r-- | src/Plugin/GitHubCommit.hs | 6 | 
4 files changed, 21 insertions, 8 deletions
| @@ -2,10 +2,15 @@ module Lib      ( someFunc      ) where +import Message  import Plugin  someFunc :: IO ()  someFunc = do -    let message = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" +    let message = Message +            { text    = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" +            , channel = "#a-channel" +            , nick    = "anon" +            }          Just plugin = matchPlugin message      putStrLn $ performPlugin plugin message diff --git a/src/Plugin.hs b/src/Plugin.hs index 84b4779..d6598ec 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -6,23 +6,25 @@ module Plugin  import Text.Regex.TDFA +import qualified Message as M  import Plugin.Base  import Plugin.GitHubCommit  -- | Get the first plugin that matches the given message text. -matchPlugin :: String -> Maybe Plugin +matchPlugin :: M.Message -> Maybe Plugin  matchPlugin message = firstPlugin $ matchPlugins message plugins    where      firstPlugin []     = Nothing      firstPlugin (p:ps) = Just p  -- | Filter the list of plugins to those that match the given message. -matchPlugins :: String -> [Plugin] -> [Plugin] -matchPlugins message plugins = [p | p <- plugins, message =~ matchRegex p] +matchPlugins :: M.Message -> [Plugin] -> [Plugin] +matchPlugins message plugins = +    [p | p <- plugins, M.text message =~ matchRegex p]  -- | Run the action belonging to the plugin, stored in its `perform` field. -performPlugin :: Plugin -> String -> String -performPlugin p message = perform p $ message =~ matchRegex p +performPlugin :: Plugin -> M.Message -> String +performPlugin p message = perform p $ message  -- | The list of plugins to load  plugins :: [Plugin] diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs index 329c21a..c85f53a 100644 --- a/src/Plugin/Base.hs +++ b/src/Plugin/Base.hs @@ -4,7 +4,9 @@ module Plugin.Base      , Plugin(..)      ) where -type PluginAction = String -> String +import Message + +type PluginAction = Message -> String  data Plugin = Plugin      { matchRegex :: String diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index 24c4831..8fa8d0a 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -2,6 +2,9 @@ module Plugin.GitHubCommit      ( gitHubCommit      ) where +import Text.Regex.TDFA + +import qualified Message as M  import Plugin.Base  gitHubCommit = Plugin @@ -10,4 +13,5 @@ gitHubCommit = Plugin      }  gitHubCommitAction :: PluginAction -gitHubCommitAction match = "https://github.com/" ++ match +gitHubCommitAction message = +    "https://github.com/" ++ M.text message =~ matchRegex gitHubCommit | 
