diff --git a/Network/IRC/Handlers.hs b/Network/IRC/Handlers.hs index 1f4d0c3..b011a4a 100644 --- a/Network/IRC/Handlers.hs +++ b/Network/IRC/Handlers.hs @@ -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 diff --git a/Network/IRC/Handlers/Core.hs b/Network/IRC/Handlers/MessageLogger.hs similarity index 93% rename from Network/IRC/Handlers/Core.hs rename to Network/IRC/Handlers/MessageLogger.hs index 0f6b437..7bdbebe 100644 --- a/Network/IRC/Handlers/Core.hs +++ b/Network/IRC/Handlers/MessageLogger.hs @@ -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"