aboutsummaryrefslogtreecommitdiffstats
path: root/src/IRC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/IRC.hs')
-rw-r--r--src/IRC.hs42
1 files changed, 38 insertions, 4 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