From 40f8f12e6a749ebd5c87df5675bf4b7c2118ccef Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 17 Aug 2017 00:46:35 +0200 Subject: Message: Add a function to get the `text` field as a string Clean up some of the calls to get the `text` field by adding a function that abstracts the call to `Data.Text(unpack)`. --- src/Message.hs | 5 +++++ src/Plugin.hs | 2 +- src/Plugin/GitHubCommit.hs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Message.hs b/src/Message.hs index db582e9..a0cadc3 100644 --- a/src/Message.hs +++ b/src/Message.hs @@ -2,6 +2,8 @@ module Message ( Message(..) , Channel , Nick + + , textStr ) where import qualified Data.Text as T @@ -15,3 +17,6 @@ data Message = Message , channel :: Channel , nick :: Nick } + +textStr :: Message -> String +textStr = T.unpack . text diff --git a/src/Plugin.hs b/src/Plugin.hs index 26432d9..0ff1367 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -22,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, (T.unpack $ M.text message) =~ matchRegex p] + [p | p <- plugins, M.textStr message =~ matchRegex p] -- | Run the action belonging to the plugin, stored in its `perform` field. performPlugin :: Plugin -> PluginAction diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index ee694b4..187f016 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -36,7 +36,7 @@ gitHubCommitAction message = do \Try `git remote set origin REPO_URL`." respond ((RepoUrlRow r):_) = Right $ r `T.append` "/commits/" `T.append` T.pack ( - (T.unpack $ M.text message) =~ matchRegex gitHubCommit) + M.textStr message =~ matchRegex gitHubCommit) type Id = Int -- cgit v1.2.3