summaryrefslogtreecommitdiff
path: root/fig-monitor-irc/src/Fig
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-10-24 21:44:11 -0400
committerLLLL Colonq <llll@colonq>2024-10-24 21:44:11 -0400
commit7bbfc556ec267a2f575a35d36fc0b99408c46930 (patch)
treee3a0aa679182c5d69ba0add77c1ccda0ba487be7 /fig-monitor-irc/src/Fig
parent76035a843777a7c5ca8d3d8e3d52b6b380c735f7 (diff)
Split long lines
Diffstat (limited to 'fig-monitor-irc/src/Fig')
-rw-r--r--fig-monitor-irc/src/Fig/Monitor/IRC.hs10
1 files changed, 9 insertions, 1 deletions
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
]