infinity-0.1.1: Infinity.hs
module Main where
import Control.Monad.Reader
import Control.Concurrent
import System.Environment
import Network.Socket
import System.Exit
import System.IO
import Network
import qualified Config as C
import Plugins
import Utils
import API
import IRC
main = do
a <- getArgs
putStrLn "Loading configuration..."
conf <- getConfig
unless (null a) $ do
case (head a) of
"-conf" -> do
print conf
exitWith ExitSuccess
"-h" -> do
putStrLn "usage: ./infinity [-h|-conf]"
putStrLn " -h This info"
putStrLn " -conf Display configuration (Config.hs)"
exitWith ExitSuccess
_ -> do
putStrLn "invalid command line option, try '-h'"
exitWith (ExitFailure 1)
putStrLn "infinity initializing..."
putStrLn "Global infinity configuration:" >> print conf
putStrLn "Compiling & loading infinity plugins..."
p <- (compilePlugins >>= loadPlugins)
putStrLn "Finished plugin compilation & loading\n\n"
-- spawn off our threads for every server
chan <- newChan
forM_ (C.servers conf) $ \s -> do
h <- connectTo (C.address s) (PortNumber . fromIntegral $ C.portnum s)
hSetBuffering h NoBuffering
let ps = PluginState h chan (C.address s) (C.administrators s) (C.channels s) $ map (\(_,plug) -> plug) p
st = Bot h chan (C.commandPrefixes conf) s ps p
forkIO $ runReaderT infInit st
-- now collect all data from threads
reports <- getChanContents chan
mapM_ (putStrLn) reports