diff options
author | Julien Dessaux | 2009-08-07 00:10:45 +0200 |
---|---|---|
committer | Julien Dessaux | 2009-08-07 00:10:45 +0200 |
commit | 2f270f8bdf0e5f226e9e54881ec71a2bde465b71 (patch) | |
tree | 7e127a649f508554ee36d036f5fae34028cd8dfa | |
parent | Added IRC connection and initialisation stuff. (diff) | |
download | hsbot-2f270f8bdf0e5f226e9e54881ec71a2bde465b71.tar.gz hsbot-2f270f8bdf0e5f226e9e54881ec71a2bde465b71.tar.bz2 hsbot-2f270f8bdf0e5f226e9e54881ec71a2bde465b71.zip |
Refactored some minor stuff
-rw-r--r-- | Config.hs | 1 | ||||
-rw-r--r-- | Hsbot/Core.hs | 1 | ||||
-rw-r--r-- | Hsbot/IRC.hs | 11 | ||||
-rw-r--r-- | Hsbot/Main.hs | 4 | ||||
-rw-r--r-- | Main.hs | 6 |
5 files changed, 14 insertions, 9 deletions
@@ -7,6 +7,7 @@ import Hsbot.Core -- | Imported plugins goes there -- | User server +kro :: IrcServer kro = IrcServer { address = "kro.corp" , port = 6667 diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs index 4daeef9..5e4853f 100644 --- a/Hsbot/Core.hs +++ b/Hsbot/Core.hs @@ -37,5 +37,6 @@ newbot :: Bot newbot = Bot (M.empty) -- | Send a string over handle +sendstr :: Handle -> String -> IO () sendstr handle str = hPrintf handle "%s\r\n" str diff --git a/Hsbot/IRC.hs b/Hsbot/IRC.hs index ead044c..d397456 100644 --- a/Hsbot/IRC.hs +++ b/Hsbot/IRC.hs @@ -25,14 +25,15 @@ data IrcInput = Cmd User Channel (Command, Maybe String) -- a regular command deriving (Eq,Show) -- | Data that can go over the remote channel -data IrcOutput = Str String -- a regular string +data IrcOutput = Str String -- a regular string | Quit (IrcServer, Handle) -- a quit message from a server | Join (IrcServer, Channel) -- joined a channel | Part (IrcServer, Channel) -- parted the channel - | Reboot -- reboot message sent - | Nil -- signifies thread death, only happens after reboot + | Reboot -- reboot message sent + | Nil -- signifies thread death, only happens after reboot deriving (Eq,Show) +-- | Parses an IrcInput parseIrcMsg :: String -> IrcInput parseIrcMsg _ = Err "Parsing not yet implemented" @@ -48,9 +49,9 @@ connectServer server = do -- | Setup a newly connected server by sending nick and join stuff initServer :: (IrcServer, Handle) -> IO () 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)) - when (not . null $ (password server)) $ do + when (not . null $ password server) $ do sendstr handle (IRC.encode $ IRC.privmsg "nickserv" ("identify" ++ (password server))) mapM_ (sendstr handle . IRC.encode . IRC.joinChan) (channels server) return () diff --git a/Hsbot/Main.hs b/Hsbot/Main.hs index 5ff138b..23b3991 100644 --- a/Hsbot/Main.hs +++ b/Hsbot/Main.hs @@ -1,5 +1,5 @@ module Hsbot.Main - (imain + ( imain ) where import System.IO @@ -18,7 +18,9 @@ imain modul' reboot = imain' modul' reboot newbot -- | Bot's main entry point imain' :: Module -> Reboot -> Bot -> IO () imain' modul' reboot bot = do + putStrLn "Connecting servers..." servers' <- mapM connectServer (ircServers C.config) + putStrLn "Joining channels..." mapM_ initServer servers' return () @@ -25,16 +25,16 @@ main = do -- | Dynamic rebooting function reboot :: Module -> a -> IO () -reboot modul' st = do +reboot modul' state = do mkstat <- makeAll "Hsbot.hs" [] --ghcargs case mkstat of MakeSuccess _ _ -> do unloadAll modul' ldstat <- load_ "Hsbot/Main.o" [".","Hsbot","Hsbot/Plugins"] "imain'" case ldstat of - LoadSuccess v imain' -> do + LoadSuccess modul'' imain' -> do putStrLn "REBOOT: Successful recompilation & reloading, rebooting..." - imain' v reboot st + imain' modul'' reboot state LoadFailure e -> fatality e MakeFailure e -> fatality e where |