Archived
1
0
Fork 0

Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat)

This commit is contained in:
Julien Dessaux 2009-08-13 00:07:08 +02:00
parent 65646eb07f
commit dfd0b3dcd7
4 changed files with 78 additions and 19 deletions

View file

@ -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 ()