Moved message logger to its own module
This commit is contained in:
parent
d80bba0948
commit
ff4030d7eb
|
@ -2,7 +2,7 @@
|
|||
|
||||
module Network.IRC.Handlers (coreMsgHandlerNames, getMsgHandler) where
|
||||
|
||||
import qualified Network.IRC.Handlers.Core as C
|
||||
import qualified Network.IRC.Handlers.MessageLogger as L
|
||||
import qualified Network.IRC.Handlers.SongSearch as SS
|
||||
|
||||
import ClassyPrelude
|
||||
|
@ -20,9 +20,13 @@ coreMsgHandlerNames = ["pingpong", "messagelogger"]
|
|||
getMsgHandler :: MsgHandlerName -> Maybe MsgHandler
|
||||
getMsgHandler "greeter" = Just $ newMsgHandler { msgHandlerRun = greeter }
|
||||
getMsgHandler "welcomer" = Just $ newMsgHandler { msgHandlerRun = welcomer }
|
||||
getMsgHandler "pingpong" = Just $ newMsgHandler { msgHandlerRun = pingPong }
|
||||
getMsgHandler name = listToMaybe $ mapMaybe (\f -> f name)
|
||||
[C.getMsgHandler, SS.getMsgHandler]
|
||||
[L.getMsgHandler, SS.getMsgHandler]
|
||||
|
||||
pingPong :: MonadMsgHandler m => Message -> m (Maybe Command)
|
||||
pingPong Ping { .. } = return . Just $ Pong msg
|
||||
pingPong _ = return Nothing
|
||||
|
||||
greeter :: MonadMsgHandler m => Message -> m (Maybe Command)
|
||||
greeter ChannelMsg { .. } = case find (== clean msg) greetings of
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{-# LANGUAGE RecordWildCards, NoImplicitPrelude, OverloadedStrings, FlexibleContexts, ScopedTypeVariables #-}
|
||||
|
||||
module Network.IRC.Handlers.Core (getMsgHandler) where
|
||||
module Network.IRC.Handlers.MessageLogger (getMsgHandler) where
|
||||
|
||||
import qualified Data.Configurator as C
|
||||
import qualified Data.Text.Format as TF
|
||||
|
@ -18,16 +18,11 @@ import System.IO (openFile, IOMode(..), hSetBuffering, BufferMode(..))
|
|||
import Network.IRC.Types
|
||||
|
||||
getMsgHandler :: MsgHandlerName -> Maybe MsgHandler
|
||||
getMsgHandler "pingpong" = Just $ newMsgHandler { msgHandlerRun = pingPong }
|
||||
getMsgHandler "messagelogger" = Just $ newMsgHandler { msgHandlerInit = initMessageLogger
|
||||
, msgHandlerRun = messageLogger
|
||||
, msgHandlerExit = exitMessageLogger }
|
||||
getMsgHandler _ = Nothing
|
||||
|
||||
pingPong :: MonadMsgHandler m => Message -> m (Maybe Command)
|
||||
pingPong Ping { .. } = return . Just $ Pong msg
|
||||
pingPong _ = return Nothing
|
||||
|
||||
getLogFilePath :: BotConfig -> IO FilePath
|
||||
getLogFilePath BotConfig { .. } = do
|
||||
logFileDir <- C.require config "messagelogger.logdir"
|
Loading…
Reference in New Issue