Archived
1
0
Fork 0

Refactored some minor stuff

This commit is contained in:
Julien Dessaux 2009-08-07 00:10:45 +02:00
parent b9c8e4d404
commit 2f270f8bdf
5 changed files with 14 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import Hsbot.Core
-- | Imported plugins goes there -- | Imported plugins goes there
-- | User server -- | User server
kro :: IrcServer
kro = IrcServer kro = IrcServer
{ address = "kro.corp" { address = "kro.corp"
, port = 6667 , port = 6667

View file

@ -37,5 +37,6 @@ newbot :: Bot
newbot = Bot (M.empty) newbot = Bot (M.empty)
-- | Send a string over handle -- | Send a string over handle
sendstr :: Handle -> String -> IO ()
sendstr handle str = hPrintf handle "%s\r\n" str sendstr handle str = hPrintf handle "%s\r\n" str

View file

@ -33,6 +33,7 @@ data IrcOutput = Str String -- a regular string
| Nil -- signifies thread death, only happens after reboot | Nil -- signifies thread death, only happens after reboot
deriving (Eq,Show) deriving (Eq,Show)
-- | Parses an IrcInput
parseIrcMsg :: String -> IrcInput parseIrcMsg :: String -> IrcInput
parseIrcMsg _ = Err "Parsing not yet implemented" parseIrcMsg _ = Err "Parsing not yet implemented"
@ -48,9 +49,9 @@ connectServer server = do
-- | Setup a newly connected server by sending nick and join stuff -- | Setup a newly connected server by sending nick and join stuff
initServer :: (IrcServer, Handle) -> IO () initServer :: (IrcServer, Handle) -> IO ()
initServer (server, handle) = do initServer (server, handle) = do
sendstr handle (IRC.encode $ IRC.nick (nickname server)) sendstr handle (IRC.encode . IRC.nick $ nickname server)
sendstr handle (IRC.encode $ IRC.user (nickname server) "0" "*" (realname server)) sendstr handle (IRC.encode $ IRC.user (nickname server) "0" "*" (realname server))
when (not . null $ (password server)) $ do when (not . null $ password server) $ do
sendstr handle (IRC.encode $ IRC.privmsg "nickserv" ("identify" ++ (password server))) sendstr handle (IRC.encode $ IRC.privmsg "nickserv" ("identify" ++ (password server)))
mapM_ (sendstr handle . IRC.encode . IRC.joinChan) (channels server) mapM_ (sendstr handle . IRC.encode . IRC.joinChan) (channels server)
return () return ()

View file

@ -1,5 +1,5 @@
module Hsbot.Main module Hsbot.Main
(imain ( imain
) where ) where
import System.IO import System.IO
@ -18,7 +18,9 @@ imain modul' reboot = imain' modul' reboot newbot
-- | Bot's main entry point -- | Bot's main entry point
imain' :: Module -> Reboot -> Bot -> IO () imain' :: Module -> Reboot -> Bot -> IO ()
imain' modul' reboot bot = do imain' modul' reboot bot = do
putStrLn "Connecting servers..."
servers' <- mapM connectServer (ircServers C.config) servers' <- mapM connectServer (ircServers C.config)
putStrLn "Joining channels..."
mapM_ initServer servers' mapM_ initServer servers'
return () return ()

View file

@ -25,16 +25,16 @@ main = do
-- | Dynamic rebooting function -- | Dynamic rebooting function
reboot :: Module -> a -> IO () reboot :: Module -> a -> IO ()
reboot modul' st = do reboot modul' state = do
mkstat <- makeAll "Hsbot.hs" [] --ghcargs mkstat <- makeAll "Hsbot.hs" [] --ghcargs
case mkstat of case mkstat of
MakeSuccess _ _ -> do MakeSuccess _ _ -> do
unloadAll modul' unloadAll modul'
ldstat <- load_ "Hsbot/Main.o" [".","Hsbot","Hsbot/Plugins"] "imain'" ldstat <- load_ "Hsbot/Main.o" [".","Hsbot","Hsbot/Plugins"] "imain'"
case ldstat of case ldstat of
LoadSuccess v imain' -> do LoadSuccess modul'' imain' -> do
putStrLn "REBOOT: Successful recompilation & reloading, rebooting..." putStrLn "REBOOT: Successful recompilation & reloading, rebooting..."
imain' v reboot st imain' modul'' reboot state
LoadFailure e -> fatality e LoadFailure e -> fatality e
MakeFailure e -> fatality e MakeFailure e -> fatality e
where where