Added more message logging
This commit is contained in:
parent
74be6dd162
commit
f1f80d2446
|
@ -51,9 +51,9 @@ listen = do
|
||||||
debug $ "< " ++ line
|
debug $ "< " ++ line
|
||||||
|
|
||||||
let message = msgFromLine botConfig now line
|
let message = msgFromLine botConfig now line
|
||||||
case message of
|
nStatus <- case message of
|
||||||
JoinMsg { .. } | userNick user == nick -> debug "Joined" >> return Joined
|
JoinMsg { .. } | userNick user == nick -> debug "Joined" >> return Joined
|
||||||
KickMsg { .. } | kicked == nick -> debug "Kicked" >> return Kicked
|
KickMsg { .. } | kickedNick == nick -> debug "Kicked" >> return Kicked
|
||||||
ModeMsg { user = Self, .. } -> sendCommand bot JoinCmd >> return status
|
ModeMsg { user = Self, .. } -> sendCommand bot JoinCmd >> return status
|
||||||
_ -> return status
|
_ -> return status
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ listen = do
|
||||||
case mCmd of
|
case mCmd of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just cmd -> sendCommand bot cmd
|
Just cmd -> sendCommand bot cmd
|
||||||
return status
|
|
||||||
|
return nStatus
|
||||||
|
|
||||||
put nStatus
|
put nStatus
|
||||||
when (nStatus /= Disconnected) listen
|
when (nStatus /= Disconnected) listen
|
||||||
|
|
|
@ -46,10 +46,37 @@ exitMessageLogger = do
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just logFileHandle -> liftIO $ hClose logFileHandle
|
Just logFileHandle -> liftIO $ hClose logFileHandle
|
||||||
|
|
||||||
messageLogger :: MonadMsgHandler m => Message -> m (Maybe Command)
|
withLogFile :: MonadMsgHandler m => (Handle -> IO ()) -> m (Maybe Command)
|
||||||
messageLogger ChannelMsg { .. } = do
|
withLogFile action = do
|
||||||
logFileHandle <- map (`fromDyn` error "No log file set") get
|
logFileHandle <- map (`fromDyn` error "No log file set") get
|
||||||
let time = formatTime defaultTimeLocale "%F %T" msgTime
|
liftIO $ action logFileHandle
|
||||||
liftIO $ TF.hprint logFileHandle "[{}] {}: {}\n" $ TF.buildParams (time, userNick user, msg)
|
|
||||||
return Nothing
|
return Nothing
|
||||||
|
|
||||||
|
fmtTime :: UTCTime -> String
|
||||||
|
fmtTime = formatTime defaultTimeLocale "%F %T"
|
||||||
|
|
||||||
|
messageLogger :: MonadMsgHandler m => Message -> m (Maybe Command)
|
||||||
|
messageLogger ChannelMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] {}: {}\n" $ TF.buildParams (fmtTime msgTime, userNick user, msg)
|
||||||
|
|
||||||
|
messageLogger KickMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] ** {} KICKED {} :{}\n" $
|
||||||
|
TF.buildParams (fmtTime msgTime, userNick user, kickedNick, msg)
|
||||||
|
|
||||||
|
messageLogger JoinMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] ** {} JOINED\n" $
|
||||||
|
TF.buildParams (fmtTime msgTime, userNick user)
|
||||||
|
|
||||||
|
messageLogger PartMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] ** {} PARTED :{}\n" $
|
||||||
|
TF.buildParams (fmtTime msgTime, userNick user, msg)
|
||||||
|
|
||||||
|
messageLogger QuitMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] ** {} QUIT :{}\n" $
|
||||||
|
TF.buildParams (fmtTime msgTime, userNick user, msg)
|
||||||
|
|
||||||
|
messageLogger NickMsg { .. } = withLogFile $ \logFileHandle ->
|
||||||
|
TF.hprint logFileHandle "[{}] ** {} CHANGED NICK TO {}\n" $
|
||||||
|
TF.buildParams (fmtTime msgTime, userNick user, nick)
|
||||||
|
|
||||||
messageLogger _ = return Nothing
|
messageLogger _ = return Nothing
|
||||||
|
|
|
@ -28,12 +28,12 @@ data Message =
|
||||||
| PrivMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
| PrivMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
||||||
| Ping { msgTime :: !UTCTime, msg :: !Text, msgLine :: !Text }
|
| Ping { msgTime :: !UTCTime, msg :: !Text, msgLine :: !Text }
|
||||||
| JoinMsg { msgTime :: !UTCTime, user :: !User, msgLine :: !Text }
|
| JoinMsg { msgTime :: !UTCTime, user :: !User, msgLine :: !Text }
|
||||||
|
| QuitMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
||||||
|
| PartMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
||||||
| ModeMsg { msgTime :: !UTCTime, user :: !User, target :: !Text, mode :: !Text
|
| ModeMsg { msgTime :: !UTCTime, user :: !User, target :: !Text, mode :: !Text
|
||||||
, modeArgs :: ![Text], msgLine :: !Text }
|
, modeArgs :: ![Text], msgLine :: !Text }
|
||||||
| NickMsg { msgTime :: !UTCTime, user :: !User, nick :: !Text, msgLine :: !Text }
|
| NickMsg { msgTime :: !UTCTime, user :: !User, nick :: !Text, msgLine :: !Text }
|
||||||
| QuitMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
| KickMsg { msgTime :: !UTCTime, user :: !User, kickedNick :: !Text, msg :: !Text
|
||||||
| PartMsg { msgTime :: !UTCTime, user :: !User, msg :: !Text, msgLine :: !Text }
|
|
||||||
| KickMsg { msgTime :: !UTCTime, user :: !User, kicked :: !Text, msg :: !Text
|
|
||||||
, msgLine :: !Text }
|
, msgLine :: !Text }
|
||||||
| OtherMsg { msgTime :: !UTCTime, source :: !Text, command :: !Text, target :: !Text
|
| OtherMsg { msgTime :: !UTCTime, source :: !Text, command :: !Text, target :: !Text
|
||||||
, msg :: !Text, msgLine :: !Text }
|
, msg :: !Text, msgLine :: !Text }
|
||||||
|
|
|
@ -7,3 +7,7 @@ msghandlers = ["greeter", "welcomer", "songsearch"]
|
||||||
songsearch {
|
songsearch {
|
||||||
tinysong_apikey = "xxxyyyzzz"
|
tinysong_apikey = "xxxyyyzzz"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
messagelogger {
|
||||||
|
logdir = "./logs/"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue