aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/IRC.hs42
-rw-r--r--src/Lib.hs2
-rw-r--r--src/Plugin/Base.hs3
-rw-r--r--src/Plugin/GitHubCommit.hs5
4 files changed, 45 insertions, 7 deletions
diff --git a/src/IRC.hs b/src/IRC.hs
index 127439d..bb153d2 100644
--- a/src/IRC.hs
+++ b/src/IRC.hs
@@ -4,11 +4,15 @@ module IRC
( connectIRC
) where
+import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString as B
import qualified Data.Text as T
import qualified Network.IRC.Client as IRC
+import Message
+import Plugin (matchPlugin, performPlugin)
+
connectIRC :: B.ByteString -> Int -> T.Text -> IO ()
connectIRC host port nick = do
conn <- IRC.connectWithTLS host port 1
@@ -26,8 +30,38 @@ handlePrivmsg = IRC.EventHandler
, IRC._eventFunc = \evt -> dispatchEvent evt
}
where
- dispatchEvent (IRC.Event _ (IRC.User nick) (IRC.Privmsg _ (Right msg))) =
- IRC.send $ IRC.Privmsg nick (Right "test")
+ dispatchEvent (IRC.Event _ (IRC.User nick) (IRC.Privmsg _ (Right msg))) = do
+ -- IRC.send $ IRC.Privmsg nick (Right "test")
+ let message = Message
+ { text = T.unpack msg
+ , channel = T.unpack nick
+ , nick = T.unpack nick
+ }
+ Just plugin = matchPlugin message
+ -- rsp =<< performPlugin plugin message
+ -- IRC.send case performPlugin plugin message of
+ -- Left err -> IRC.Privmsg nick (Right (T.pack err))
+ -- Right r -> IRC.Privmsg nick (Right (T.pack r))
+ response <- liftIO $ performPlugin plugin message
+ IRC.send $ case response of
+ Left err -> IRC.Privmsg nick (Right (T.pack err))
+ Right r -> IRC.Privmsg nick (Right (T.pack r))
dispatchEvent (IRC.Event
- _ (IRC.Channel chan nick) (IRC.Privmsg _ (Right msg))) =
- IRC.send $ IRC.Privmsg chan (Right "test")
+ _ (IRC.Channel chan nick) (IRC.Privmsg _ (Right msg))) = do
+ -- IRC.send $ IRC.Privmsg chan (Right "test")
+ let message = Message
+ { text = T.unpack msg
+ , channel = T.unpack chan
+ , nick = T.unpack nick
+ }
+ Just plugin = matchPlugin message
+ response <- liftIO $ performPlugin plugin message
+ IRC.send $ case response of
+ Left err -> IRC.Privmsg chan (Right (T.pack err))
+ Right r -> IRC.Privmsg chan (Right (T.pack r))
+
+ -- let Just plugin = matchPlugin message
+ -- response <- performPlugin plugin message
+ -- putStrLn $ case response of
+ -- Left e -> e
+ -- Right r -> r
diff --git a/src/Lib.hs b/src/Lib.hs
index f72729e..b23bf78 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -20,7 +20,7 @@ someFunc = do
-- }
-- Just plugin = matchPlugin message
-- dbConn <- open "db/sorbot_development.sqlite3"
- -- response <- performPlugin plugin message dbConn
+ -- response <- performPlugin plugin message
-- putStrLn $ case response of
-- Left e -> e
-- Right r -> r
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs
index fe3a0f8..4e63fdd 100644
--- a/src/Plugin/Base.hs
+++ b/src/Plugin/Base.hs
@@ -9,7 +9,8 @@ import Database.SQLite.Simple
import Message
-- TODO: Replace Connection with a type class
-type PluginAction = Message -> Connection -> IO (Either String String)
+-- type PluginAction = Message -> Connection -> IO (Either String String)
+type PluginAction = Message -> IO (Either String String)
data Plugin = Plugin
{ matchRegex :: String
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 492fd30..9773690 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -17,13 +17,16 @@ gitHubCommit = Plugin
}
gitHubCommitAction :: PluginAction
-gitHubCommitAction message dbConn = do
+gitHubCommitAction message = do
+ dbConn <- open "db/sorbot_development.sqlite3"
rs <- query dbConn "SELECT repo_url \
\ FROM plugin_github_commit_channel_repo_urls \
\ WHERE channel = ? \
\ LIMIT 1"
(Only (M.channel message))
:: IO [RepoUrlRow]
+ close dbConn
+
return $ respond rs
where
respond [] =