summaryrefslogtreecommitdiff
path: root/Hsbot/IRC.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:36:58 +0100
committerJulien Dessaux2010-02-04 20:36:58 +0100
commit884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5 (patch)
treec5941649d7fe1ac23d5ee673c240efb8508b3db2 /Hsbot/IRC.hs
parentRewrote the whole architecture. (diff)
downloadhsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.gz
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.tar.bz2
hsbot-884c6c9f2e3a03d6666c8dd6c6d6b6513db88ad5.zip
Reorganized code and types, changed slightly the architecture.
Diffstat (limited to '')
-rw-r--r--Hsbot/IRC.hs47
1 files changed, 17 insertions, 30 deletions
diff --git a/Hsbot/IRC.hs b/Hsbot/IRC.hs
index d3a3114..3fe2181 100644
--- a/Hsbot/IRC.hs
+++ b/Hsbot/IRC.hs
@@ -5,50 +5,38 @@ module Hsbot.IRC
import Control.Concurrent.Chan
import Control.Monad.State
-import System.IO
-import Hsbot.Core
import Hsbot.IRCParser
+import Hsbot.Plugin
+import Hsbot.Types
+import Hsbot.Utils
-- | Setup a newly connected server by sending nick and join stuff
initServer :: IrcBot ()
initServer = do
server <- gets serverConfig
- writeMsg $ IrcMsg Nothing "NICK" [(nickname server)]
- writeMsg $ IrcMsg Nothing "USER" [(nickname server), "0", "*", (realname server)]
+ sendstr $ serializeIrcMsg $ IrcMsg Nothing "NICK" [(nickname server)]
+ sendstr $ serializeIrcMsg $ IrcMsg Nothing "USER" [(nickname server), "0", "*", (realname server)]
when (not . null $ password server) $ do
- writeMsg $ IrcMsg Nothing "PRIVMSG" ["nickserv", "identify", (password server)]
- joinChans
- return ()
+ sendstr $ serializeIrcMsg $ IrcMsg Nothing "PRIVMSG" ["nickserv", "identify", (password server)]
+ mapM_ joinChan (channels server)
-- | Run a server
runServer :: IrcBot ()
runServer = do
- handle <- gets botHandle
+ chan <- gets botChannel
plugins <- gets botPlugins
- str <- liftIO $ hGetLine handle
- traceM $ inColor ("<-- " ++ str) [33]
- let msg = parseIrcMsg str
+ let input = readChan chan
+ msg <- liftIO input
case msg of
- Right msg' -> do
- mapM_ (sendPlugin msg') plugins
- return ()
- _ -> do
- return ()
- traceM $ show msg
+ InputMsg inputMsg ->
+ mapM_ (sendToPlugin $ InputMsg inputMsg) plugins
+ OutputMsg outputMsg ->
+ sendstr (serializeIrcMsg outputMsg)
+ InternalCmd internalCmd ->
+ traceM "TODO"
runServer
-sendPlugin :: IrcMsg -> Plugin -> IrcBot ()
-sendPlugin msg plugin = do
- let chan = pluginChannel plugin
- liftIO $ writeChan chan msg
-
--- | Join chans
-joinChans :: IrcBot ()
-joinChans = do
- server <- gets serverConfig
- mapM_ joinChan (channels server)
-
-- | Joins a chan
joinChan :: String -> IrcBot ()
joinChan name = do
@@ -57,7 +45,6 @@ joinChan name = do
newChannel = Channel name
(nickname $ serverConfig bot)
(administrators $ serverConfig bot)
- traceM $ " Joining " ++ name
- writeMsg $ IrcMsg Nothing "JOIN" [name]
+ sendstr $ serializeIrcMsg $ IrcMsg Nothing "JOIN" [name]
put $ bot { chans = newChannel : oldChannels }