From c006be894348c1302f99698d18d0e4d76bac160b Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 14 Oct 2022 09:52:18 +0200 Subject: Proper target for irc responses --- src/IRC.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/IRC.hs b/src/IRC.hs index 5a24909..ac88a78 100644 --- a/src/IRC.hs +++ b/src/IRC.hs @@ -56,10 +56,15 @@ noticeHandler = EventHandler privmsgHandler :: (Text -> Bool) -> (Text -> IO [Text]) -> EventHandler s privmsgHandler commandDetect msgFun = EventHandler (\ev -> case ev ^. message of - Privmsg target (Right text) - | commandDetect text -> Just (target, text) + Privmsg _ (Right text) + | commandDetect text -> Just (ev ^. source, text) _ -> Nothing) - (\_ (target, text) -> do + (\_ (src, text) -> do msgs <- liftIO $ msgFun text - forM_ msgs $ \msg -> - send $ Privmsg target (Right msg)) + let mtarget = case src of + User name -> Just name + Channel ch _ -> Just ch + Server _ -> Nothing + forM_ mtarget $ \target -> + forM_ msgs $ \msg -> + send $ Privmsg target (Right msg)) -- cgit v1.2.3-70-g09d2