Reformatting and hlinting.
parent
ab26dd9f6a
commit
044285bfb8
|
@ -61,7 +61,7 @@ sendCommandLoop commandChan bot@Bot { .. } = do
|
|||
forM_ exs $ \(ex :: SomeException) ->
|
||||
errorM ("Error while formatting command: " ++ show cmd ++ "\nError: " ++ show ex)
|
||||
|
||||
forM_ lines_ $ \line -> do
|
||||
forM_ lines_ $ \line ->
|
||||
handle (\(e :: SomeException) -> do
|
||||
errorM ("Error while writing to connection: " ++ show e)
|
||||
closeMessageChannel commandChan) $ do
|
||||
|
|
|
@ -68,7 +68,7 @@ connect botConfig@BotConfig { .. } = do
|
|||
let msgHandlerChannels = map snd msgHandlersChans
|
||||
let msgHandlers = map fst msgHandlersChans
|
||||
|
||||
return ConnectionResource { bot = (Bot botConfig' socket msgHandlers)
|
||||
return ConnectionResource { bot = Bot botConfig' socket msgHandlers
|
||||
, botStatus = mvBotStatus
|
||||
, inChannel = inChannel
|
||||
, mainMsgChannel = mainMsgChannel
|
||||
|
@ -81,8 +81,7 @@ connect botConfig@BotConfig { .. } = do
|
|||
threadDelay (5 * oneSec)
|
||||
connectToWithRetry)
|
||||
|
||||
mkMsgHandler name messageBus =
|
||||
case lookup name msgHandlerMakers of
|
||||
mkMsgHandler name messageBus = case lookup name msgHandlerMakers of
|
||||
Nothing -> return Nothing
|
||||
Just maker -> do
|
||||
messageChannel <- newMessageChannel messageBus
|
||||
|
@ -116,26 +115,26 @@ runBotIntenal :: BotConfig -> IO ()
|
|||
runBotIntenal botConfig' = withSocketsDo $ do
|
||||
status <- run
|
||||
case status of
|
||||
Disconnected -> debugM "Restarting .." >> runBotIntenal botConfigWithCore
|
||||
Errored -> debugM "Restarting .." >> runBotIntenal botConfigWithCore
|
||||
Disconnected -> debugM "Restarting .." >> runBotIntenal botConfigWithCoreHandlers
|
||||
Errored -> debugM "Restarting .." >> runBotIntenal botConfigWithCoreHandlers
|
||||
NickNotAvailable -> debugM "Trying new nick" >> runBotIntenal botConfigWithNewNick
|
||||
NickAvailable -> debugM "Trying original nick" >> runBotIntenal botConfigWithOrigNick
|
||||
Interrupted -> return ()
|
||||
_ -> error "Unsupported status"
|
||||
where
|
||||
botConfigWithCore = botConfig' {
|
||||
botConfigWithCoreHandlers = botConfig' {
|
||||
msgHandlerInfo =
|
||||
foldl' (flip (`insertMap` mempty)) mempty
|
||||
(hashNub $ mapKeys (msgHandlerInfo botConfig') ++ mapKeys coreMsgHandlerMakers)
|
||||
, msgHandlerMakers = coreMsgHandlerMakers <> msgHandlerMakers botConfig'
|
||||
}
|
||||
|
||||
botConfigWithNewNick = botConfigWithCore {
|
||||
botNick = Nick $ nickToText (botNick botConfigWithCore) ++ "_"
|
||||
botConfigWithNewNick = botConfigWithCoreHandlers {
|
||||
botNick = Nick $ nickToText (botNick botConfigWithCoreHandlers) ++ "_"
|
||||
}
|
||||
|
||||
botConfigWithOrigNick = botConfigWithCore {
|
||||
botNick = botOrigNick botConfigWithCore
|
||||
botConfigWithOrigNick = botConfigWithCoreHandlers {
|
||||
botNick = botOrigNick botConfigWithCoreHandlers
|
||||
}
|
||||
|
||||
handleErrors :: SomeException -> IO BotStatus
|
||||
|
@ -157,8 +156,7 @@ runBotIntenal botConfig' = withSocketsDo $ do
|
|||
forM_ resps $ sendMessage msgChannel
|
||||
runHandler botConfig (msgHandlerName, (handler, msgChannel))
|
||||
|
||||
run = bracket (connect botConfigWithCore) disconnect $
|
||||
\ConnectionResource { .. } ->
|
||||
run = bracket (connect botConfigWithCoreHandlers) disconnect $ \ConnectionResource { .. } ->
|
||||
handle handleErrors $ do
|
||||
let Bot { .. } = bot
|
||||
debugM $ "Running with config:\n" ++ show botConfig
|
||||
|
|
Loading…
Reference in New Issue