aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2017-08-13 19:03:02 +0200
committerTeddy Wing2017-08-13 19:03:02 +0200
commit5f157d66a001224fd623b63e92505aa058599942 (patch)
treeaaaf07fdb489e868209321e80be2ab45b6b58a64 /src
parent9209ccaadc40c294c85a8191a02330abea133bd6 (diff)
downloadsorbot-5f157d66a001224fd623b63e92505aa058599942.tar.bz2
Lib.hs: Move IRC-related code to a new "IRC" module
Now that we have something sort of working on the IRC side of things, we can move it out into its own module to keep `Lib` clear and tidy.
Diffstat (limited to 'src')
-rw-r--r--src/IRC.hs33
-rw-r--r--src/Lib.hs28
2 files changed, 34 insertions, 27 deletions
diff --git a/src/IRC.hs b/src/IRC.hs
new file mode 100644
index 0000000..127439d
--- /dev/null
+++ b/src/IRC.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module IRC
+ ( connectIRC
+ ) where
+
+import qualified Data.ByteString as B
+import qualified Data.Text as T
+
+import qualified Network.IRC.Client as IRC
+
+connectIRC :: B.ByteString -> Int -> T.Text -> IO ()
+connectIRC host port nick = do
+ conn <- IRC.connectWithTLS host port 1
+ let cfg = IRC.defaultIRCConf nick
+ let cfg' = cfg {
+ IRC._eventHandlers = handlePrivmsg : IRC._eventHandlers cfg
+ , IRC._channels = ["#test-chan-13513"]
+ }
+ IRC.start conn cfg'
+
+handlePrivmsg :: IRC.EventHandler s
+handlePrivmsg = IRC.EventHandler
+ { IRC._description = ""
+ , IRC._matchType = IRC.EPrivmsg
+ , 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.Channel chan nick) (IRC.Privmsg _ (Right msg))) =
+ IRC.send $ IRC.Privmsg chan (Right "test")
diff --git a/src/Lib.hs b/src/Lib.hs
index 53afeb5..f72729e 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -4,12 +4,9 @@ module Lib
( someFunc
) where
-import qualified Data.ByteString as B
-import qualified Data.Text as T
-
import Database.SQLite.Simple
-import qualified Network.IRC.Client as IRC
+import IRC (connectIRC)
import Message
import Plugin
@@ -28,26 +25,3 @@ someFunc = do
-- Left e -> e
-- Right r -> r
-- close dbConn
-
-connectIRC :: B.ByteString -> Int -> T.Text -> IO ()
-connectIRC host port nick = do
- conn <- IRC.connectWithTLS host port 1
- let cfg = IRC.defaultIRCConf nick
- let cfg' = cfg {
- IRC._eventHandlers = handlePrivmsg : IRC._eventHandlers cfg
- , IRC._channels = ["#test-chan-13513"]
- }
- IRC.start conn cfg'
-
-handlePrivmsg :: IRC.EventHandler s
-handlePrivmsg = IRC.EventHandler
- { IRC._description = ""
- , IRC._matchType = IRC.EPrivmsg
- , 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.Channel chan nick) (IRC.Privmsg _ (Right msg))) =
- IRC.send $ IRC.Privmsg chan (Right "test")