summaryrefslogtreecommitdiff
path: root/Hsbot/Main.hs
diff options
context:
space:
mode:
authorJulien Dessaux2009-08-13 00:07:08 +0200
committerJulien Dessaux2009-08-13 00:07:08 +0200
commitdfd0b3dcd72a8efa84612a4ae925204f3e4526d8 (patch)
tree574665be7df16d203337ac807eddfd70a3ebcbf0 /Hsbot/Main.hs
parentAdded server states, in order to handle rebooting more cleanly (still missing... (diff)
downloadhsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.tar.gz
hsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.tar.bz2
hsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.zip
Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat)
Diffstat (limited to '')
-rw-r--r--Hsbot/Main.hs34
1 files changed, 18 insertions, 16 deletions
diff --git a/Hsbot/Main.hs b/Hsbot/Main.hs
index 8c4be63..4c006b5 100644
--- a/Hsbot/Main.hs
+++ b/Hsbot/Main.hs
@@ -41,28 +41,30 @@ imain' modul' reboot bot = do
monitor :: (Chan IrcLine) -> Bot -> IO Bot
monitor chan bot = do
loop bot
- where loop bot' = do
- input <- readChan chan
- case input of
- Reboot ->do
+ where
+ loop bot' = do
+ input <- readChan chan :: IO IrcLine
+ case input of
+ Reboot -> do
putStrLn "Got reboot message, rebooting"
return bot'
- Str str -> putStrLn ("received : " ++ str) >> loop bot'
+ _ -> loop bot'
-- | Thread entry point for socket listeners
listener :: (Chan IrcLine) -> (IrcServer, Handle) -> IO ()
listener chan (server, handle) = forever $ do
str <- hGetLine handle
- writeChan chan (Str str)
- if ping str then pong handle str
- else eval (parseIrcMsg str)
+ let msg = parseIrcMsg str
+ writeChan chan msg
+ eval msg
where
- eval str
- | (Cmd user channel (cmd, args)) <- str = do
- let cmd' = tail cmd
- unless (null cmd') (parseCmds user cmd' args channel)
- parseCmds user cmd args channel
- | cmd == "reboot" = writeChan chan Reboot
- | otherwise = do
- putStrLn $"Unknown command : " ++ cmd
+ eval :: IrcLine -> IO ()
+ eval (Privmsg (statement, stuff')) = sendPrivmsg (server, handle) stuff'
+ eval (Quit (ircServer, handle')) = return ()
+ eval (Join (ircServer, handle')) = return ()
+ eval (Part (ircServer, handle')) = return ()
+ eval (Ping (string)) = do pong handle string
+ eval stuff' = case stuff' of
+ Reboot -> return ()
+ Nil -> return ()