Reformatting and hlinting.

master
Abhinav Sarkar 2015-06-29 21:14:14 +05:30
parent ab26dd9f6a
commit 044285bfb8
2 changed files with 30 additions and 32 deletions

View File

@ -61,7 +61,7 @@ sendCommandLoop commandChan bot@Bot { .. } = do
forM_ exs $ \(ex :: SomeException) -> forM_ exs $ \(ex :: SomeException) ->
errorM ("Error while formatting command: " ++ show cmd ++ "\nError: " ++ show ex) errorM ("Error while formatting command: " ++ show cmd ++ "\nError: " ++ show ex)
forM_ lines_ $ \line -> do forM_ lines_ $ \line ->
handle (\(e :: SomeException) -> do handle (\(e :: SomeException) -> do
errorM ("Error while writing to connection: " ++ show e) errorM ("Error while writing to connection: " ++ show e)
closeMessageChannel commandChan) $ do closeMessageChannel commandChan) $ do

View File

@ -68,7 +68,7 @@ connect botConfig@BotConfig { .. } = do
let msgHandlerChannels = map snd msgHandlersChans let msgHandlerChannels = map snd msgHandlersChans
let msgHandlers = map fst msgHandlersChans let msgHandlers = map fst msgHandlersChans
return ConnectionResource { bot = (Bot botConfig' socket msgHandlers) return ConnectionResource { bot = Bot botConfig' socket msgHandlers
, botStatus = mvBotStatus , botStatus = mvBotStatus
, inChannel = inChannel , inChannel = inChannel
, mainMsgChannel = mainMsgChannel , mainMsgChannel = mainMsgChannel
@ -81,8 +81,7 @@ connect botConfig@BotConfig { .. } = do
threadDelay (5 * oneSec) threadDelay (5 * oneSec)
connectToWithRetry) connectToWithRetry)
mkMsgHandler name messageBus = mkMsgHandler name messageBus = case lookup name msgHandlerMakers of
case lookup name msgHandlerMakers of
Nothing -> return Nothing Nothing -> return Nothing
Just maker -> do Just maker -> do
messageChannel <- newMessageChannel messageBus messageChannel <- newMessageChannel messageBus
@ -116,26 +115,26 @@ runBotIntenal :: BotConfig -> IO ()
runBotIntenal botConfig' = withSocketsDo $ do runBotIntenal botConfig' = withSocketsDo $ do
status <- run status <- run
case status of case status of
Disconnected -> debugM "Restarting .." >> runBotIntenal botConfigWithCore Disconnected -> debugM "Restarting .." >> runBotIntenal botConfigWithCoreHandlers
Errored -> debugM "Restarting .." >> runBotIntenal botConfigWithCore Errored -> debugM "Restarting .." >> runBotIntenal botConfigWithCoreHandlers
NickNotAvailable -> debugM "Trying new nick" >> runBotIntenal botConfigWithNewNick NickNotAvailable -> debugM "Trying new nick" >> runBotIntenal botConfigWithNewNick
NickAvailable -> debugM "Trying original nick" >> runBotIntenal botConfigWithOrigNick NickAvailable -> debugM "Trying original nick" >> runBotIntenal botConfigWithOrigNick
Interrupted -> return () Interrupted -> return ()
_ -> error "Unsupported status" _ -> error "Unsupported status"
where where
botConfigWithCore = botConfig' { botConfigWithCoreHandlers = botConfig' {
msgHandlerInfo = msgHandlerInfo =
foldl' (flip (`insertMap` mempty)) mempty foldl' (flip (`insertMap` mempty)) mempty
(hashNub $ mapKeys (msgHandlerInfo botConfig') ++ mapKeys coreMsgHandlerMakers) (hashNub $ mapKeys (msgHandlerInfo botConfig') ++ mapKeys coreMsgHandlerMakers)
, msgHandlerMakers = coreMsgHandlerMakers <> msgHandlerMakers botConfig' , msgHandlerMakers = coreMsgHandlerMakers <> msgHandlerMakers botConfig'
} }
botConfigWithNewNick = botConfigWithCore { botConfigWithNewNick = botConfigWithCoreHandlers {
botNick = Nick $ nickToText (botNick botConfigWithCore) ++ "_" botNick = Nick $ nickToText (botNick botConfigWithCoreHandlers) ++ "_"
} }
botConfigWithOrigNick = botConfigWithCore { botConfigWithOrigNick = botConfigWithCoreHandlers {
botNick = botOrigNick botConfigWithCore botNick = botOrigNick botConfigWithCoreHandlers
} }
handleErrors :: SomeException -> IO BotStatus handleErrors :: SomeException -> IO BotStatus
@ -157,8 +156,7 @@ runBotIntenal botConfig' = withSocketsDo $ do
forM_ resps $ sendMessage msgChannel forM_ resps $ sendMessage msgChannel
runHandler botConfig (msgHandlerName, (handler, msgChannel)) runHandler botConfig (msgHandlerName, (handler, msgChannel))
run = bracket (connect botConfigWithCore) disconnect $ run = bracket (connect botConfigWithCoreHandlers) disconnect $ \ConnectionResource { .. } ->
\ConnectionResource { .. } ->
handle handleErrors $ do handle handleErrors $ do
let Bot { .. } = bot let Bot { .. } = bot
debugM $ "Running with config:\n" ++ show botConfig debugM $ "Running with config:\n" ++ show botConfig