From dfd0b3dcd72a8efa84612a4ae925204f3e4526d8 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 13 Aug 2009 00:07:08 +0200 Subject: Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat) --- Hsbot/Main.hs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'Hsbot/Main.hs') 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 () -- cgit v1.2.3