summaryrefslogtreecommitdiff
path: root/HsbotIrcBot/Hsbot/Irc/Server.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-07-03 21:26:00 +0200
committerJulien Dessaux2010-07-03 22:40:17 +0200
commit11c2c16835b3e8368be77ccc5b7ddf949021eccd (patch)
tree7733132ee370335156219ff6eb4f0ef2dbd1c8ff /HsbotIrcBot/Hsbot/Irc/Server.hs
parentWrote most of the resume code for the core and the irc plugin. (diff)
downloadhsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.gz
hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.bz2
hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.zip
Moved files around as a preliminary for architectural changes.
Diffstat (limited to 'HsbotIrcBot/Hsbot/Irc/Server.hs')
-rw-r--r--HsbotIrcBot/Hsbot/Irc/Server.hs35
1 files changed, 35 insertions, 0 deletions
diff --git a/HsbotIrcBot/Hsbot/Irc/Server.hs b/HsbotIrcBot/Hsbot/Irc/Server.hs
new file mode 100644
index 0000000..3c20e6d
--- /dev/null
+++ b/HsbotIrcBot/Hsbot/Irc/Server.hs
@@ -0,0 +1,35 @@
+module Hsbot.Irc.Server
+ ( initServerConnection
+ , sendIrcMsg
+ ) where
+
+import Control.Concurrent.Chan
+import Control.Monad.State
+
+import Hsbot.Irc.Config
+import Hsbot.Irc.Message
+import Hsbot.Irc.Types
+
+-- | Setup a newly connected server by sending nick and join stuff
+initServerConnection :: IrcConfig -> IrcServer ()
+initServerConnection config = do
+ sendIrcMsg $ IrcMsg Nothing "NICK" [(ircConfigNickname config)]
+ sendIrcMsg $ IrcMsg Nothing "USER" [(ircConfigNickname config), "0", "*", (ircConfigRealname config)]
+ when (not . null $ ircConfigPassword config) $ do
+ sendIrcMsg $ IrcMsg Nothing "PRIVMSG" ["nickserv", "identify", (ircConfigPassword config)]
+ mapM_ joinChan (ircConfigChannels config)
+
+-- | Joins a chan
+joinChan :: String -> IrcServer ()
+joinChan channel = do
+ ircServer <- get
+ let oldChannels = ircServerChannels ircServer
+ sendIrcMsg $ IrcMsg Nothing "JOIN" [channel]
+ put $ ircServer { ircServerChannels = channel : oldChannels }
+
+-- | Sends an IrcMsg
+sendIrcMsg :: IrcMsg -> IrcServer ()
+sendIrcMsg ircMsg = do
+ chan <- gets ircServerChan
+ liftIO $ writeChan chan (OutIrcMsg ircMsg)
+