From f4028e21f8a138961927b8e794b349f209b00dc7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 17 Aug 2017 00:35:24 +0200 Subject: Change `Plugin` and `Message` from `String` to `Data.Text` Use the `Data.Text` type instead of `String` in most of the places we use it in `Plugin` and `Message`. This allows us to more easily pass data between the IRC package. No more kludgy `pack`s and `unpack`s in our IRC message handler. The one thing we couldn't convert was our regex. From what I understand (https://stackoverflow.com/questions/14922579/haskell-regular-expressions-and-data-text#14922626), the regex library I'm using doesn't support `Data.Text`, so use `String`s for that instead. --- src/Plugin.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Plugin.hs') diff --git a/src/Plugin.hs b/src/Plugin.hs index 73df169..26432d9 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -4,6 +4,8 @@ module Plugin , plugins ) where +import qualified Data.Text as T + import Text.Regex.TDFA import qualified Message as M @@ -20,7 +22,7 @@ matchPlugin message = firstPlugin $ 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.text message =~ matchRegex p] + [p | p <- plugins, (T.unpack $ M.text message) =~ matchRegex p] -- | Run the action belonging to the plugin, stored in its `perform` field. performPlugin :: Plugin -> PluginAction -- cgit v1.2.3