aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IRC.hs20
-rw-r--r--src/Message.hs8
-rw-r--r--src/Plugin.hs4
-rw-r--r--src/Plugin/Base.hs4
-rw-r--r--src/Plugin/GitHubCommit.hs7
5 files changed, 26 insertions, 17 deletions
diff --git a/src/IRC.hs b/src/IRC.hs
index b941982..70bbc7d 100644
--- a/src/IRC.hs
+++ b/src/IRC.hs
@@ -32,9 +32,9 @@ handlePrivmsg = IRC.EventHandler
where
dispatchEvent (IRC.Event _ (IRC.User nick) (IRC.Privmsg _ (Right msg))) = do
let message = Message
- { text = T.unpack msg
- , channel = T.unpack nick
- , nick = T.unpack nick
+ { text = msg
+ , channel = nick
+ , nick = nick
}
response <- liftIO $ privmsgFromPlugin message
case response of
@@ -43,9 +43,9 @@ handlePrivmsg = IRC.EventHandler
dispatchEvent (IRC.Event
_ (IRC.Channel chan nick) (IRC.Privmsg _ (Right msg))) = do
let message = Message
- { text = T.unpack msg
- , channel = T.unpack chan
- , nick = T.unpack nick
+ { text = msg
+ , channel = chan
+ , nick = nick
}
response <- liftIO $ privmsgFromPlugin message
case response of
@@ -60,8 +60,8 @@ privmsgFromPlugin message = do
response <- liftIO $ performPlugin plugin message
return $ case response of
Left err -> Just $ IRC.send $ IRC.Privmsg
- (T.pack (channel message))
- (Right (T.pack err))
+ (channel message)
+ (Right err)
Right r -> Just $ IRC.send $ IRC.Privmsg
- (T.pack (channel message))
- (Right (T.pack r))
+ (channel message)
+ (Right r)
diff --git a/src/Message.hs b/src/Message.hs
index 6a95638..db582e9 100644
--- a/src/Message.hs
+++ b/src/Message.hs
@@ -4,12 +4,14 @@ module Message
, Nick
) where
-type Channel = String
+import qualified Data.Text as T
-type Nick = String
+type Channel = T.Text
+
+type Nick = T.Text
data Message = Message
- { text :: String
+ { text :: T.Text
, channel :: Channel
, nick :: Nick
}
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
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs
index 6ba4ca5..62900c7 100644
--- a/src/Plugin/Base.hs
+++ b/src/Plugin/Base.hs
@@ -4,11 +4,13 @@ module Plugin.Base
, Plugin(..)
) where
+import qualified Data.Text as T
+
import Database.SQLite.Simple
import Message
-type PluginAction = Message -> IO (Either String String)
+type PluginAction = Message -> IO (Either T.Text T.Text)
data Plugin = Plugin
{ matchRegex :: String
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 9773690..ee694b4 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -4,6 +4,8 @@ module Plugin.GitHubCommit
( gitHubCommit
) where
+import qualified Data.Text as T
+
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow
import Text.Regex.TDFA
@@ -33,11 +35,12 @@ gitHubCommitAction message = do
Left "I couldn't find a repo URL for this channel. \
\Try `git remote set origin REPO_URL`."
respond ((RepoUrlRow r):_) =
- Right $ r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit
+ Right $ r `T.append` "/commits/" `T.append` T.pack (
+ (T.unpack $ M.text message) =~ matchRegex gitHubCommit)
type Id = Int
-type RepoUrl = String
+type RepoUrl = T.Text
-- | A type to match the database table for this plugin.
data RepoUrlRow = RepoUrlRow RepoUrl