From 7bbfc556ec267a2f575a35d36fc0b99408c46930 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Thu, 24 Oct 2024 21:44:11 -0400 Subject: Split long lines --- fig-monitor-irc/src/Fig/Monitor/IRC.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fig-monitor-irc/src/Fig/Monitor/IRC.hs b/fig-monitor-irc/src/Fig/Monitor/IRC.hs index 0ceaeba..ae38b3a 100644 --- a/fig-monitor-irc/src/Fig/Monitor/IRC.hs +++ b/fig-monitor-irc/src/Fig/Monitor/IRC.hs @@ -26,6 +26,13 @@ data OutgoingMessage = OutgoingMessage , msg :: !Text } +splitLineIRCLength :: Text -> [Text] +splitLineIRCLength x + | Text.length x > 400 = + let (m, xs) = Text.splitAt 400 x + in m : splitLineIRCLength xs + | otherwise = [x] + ircBot :: Config -> (Text, Text) -> IO () ircBot cfg busAddr = do outgoing <- Chan.newChan @OutgoingMessage @@ -35,7 +42,8 @@ ircBot cfg busAddr = do o <- liftIO $ Chan.readChan outgoing log $ "Sending: " <> o.msg <> " (from " <> o.user <> ")" let lines = Text.splitOn "\n" o.msg - let msgs = lines <&> \msg -> IRC.Privmsg o.chan . Right . Text.take 400 $ mconcat + let linesshort = mconcat $ splitLineIRCLength <$> lines + let msgs = linesshort <&> \msg -> IRC.Privmsg o.chan . Right . Text.take 400 $ mconcat [ "<", o.user, "> " , Text.replace "\n" " " msg ] -- cgit v1.2.3