diff options
author | Teddy Wing | 2017-07-30 19:36:28 +0200 |
---|---|---|
committer | Teddy Wing | 2017-07-30 19:36:28 +0200 |
commit | e4b00259ec4c1338f766561aba3b7a3a3159d216 (patch) | |
tree | 8ea8a29c3de9268d114041fc636354b1b8820ea7 | |
parent | 487f8f805647d3f3fbb86aac6838f0c0e37a6bde (diff) | |
download | sorbot-e4b00259ec4c1338f766561aba3b7a3a3159d216.tar.bz2 |
Move `Plugin` and `PluginAction` to a new module
Move our base plugin types to a new module to enable us to use them in
both the plugin matching code (which we'll leave in "Plugin.hs") and in
specialised plugin modules.
This enables us to import and provide a list of plugins in `plugins` in
"Plugin.hs" and use these types in that file and in the plugin files
without any circular/recursive module dependencies.
-rw-r--r-- | sorbot.cabal | 1 | ||||
-rw-r--r-- | src/Plugin.hs | 13 | ||||
-rw-r--r-- | src/Plugin/Base.hs | 17 |
3 files changed, 20 insertions, 11 deletions
diff --git a/sorbot.cabal b/sorbot.cabal index 49c21fa..a581bea 100644 --- a/sorbot.cabal +++ b/sorbot.cabal @@ -17,6 +17,7 @@ library hs-source-dirs: src exposed-modules: Lib , Plugin + , Plugin.Base build-depends: base >= 4.7 && < 5 , regex-tdfa default-language: Haskell2010 diff --git a/src/Plugin.hs b/src/Plugin.hs index 6522e0b..41b0296 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -1,21 +1,12 @@ module Plugin - ( Plugin - , matchPlugin + ( matchPlugin , performPlugin , plugins ) where import Text.Regex.TDFA -type PluginAction = String -> String - -data Plugin = Plugin - { matchRegex :: String - , perform :: PluginAction - } - -instance Show Plugin where - show (Plugin r p) = "matchRegex = " ++ r +import Plugin.Base matchPlugin :: String -> Maybe Plugin matchPlugin message = firstPlugin $ matchPlugins message plugins diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs new file mode 100644 index 0000000..c73ef6a --- /dev/null +++ b/src/Plugin/Base.hs @@ -0,0 +1,17 @@ +module Plugin.Base + ( PluginAction + + , Plugin(..) + , matchRegex + , perform + ) where + +type PluginAction = String -> String + +data Plugin = Plugin + { matchRegex :: String + , perform :: PluginAction + } + +instance Show Plugin where + show (Plugin r p) = "matchRegex = " ++ r |