From 3124acd6ae0328a8607d0807e4923f0dd75fe49e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Aug 2017 17:23:36 +0200 Subject: IRC: Only respond to messages if prefixed with "sorbot: " Prevent Sorbot from responding to general messages. Messages must be directed at Sorbot to invoke plugins and get a response. --- src/IRC.hs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/IRC.hs b/src/IRC.hs index 3fd980c..53f6969 100644 --- a/src/IRC.hs +++ b/src/IRC.hs @@ -57,21 +57,23 @@ handlePrivmsg = IRC.EventHandler privmsgFromPlugin :: Message -> IO (Maybe [IRC.StatefulIRC s ()]) privmsgFromPlugin message = do - case matchPlugin message of - Nothing -> return Nothing - Just plugin -> do - response <- liftIO $ performPlugin plugin message - return $ case response of - Left err -> Just $ - [IRC.send $ IRC.Privmsg - (toChannel plugin message) - (Right err)] - Right r -> Just $ - map (\r -> - IRC.send $ IRC.Privmsg - (toChannel plugin message) - (Right r) ) - (splitAtNewlines $ splitLongLines r) + case messageForBot message of + Nothing -> return Nothing + Just message -> case matchPlugin message of + Nothing -> return Nothing + Just plugin -> do + response <- liftIO $ performPlugin plugin message + return $ case response of + Left err -> Just $ + [IRC.send $ IRC.Privmsg + (toChannel plugin message) + (Right err)] + Right r -> Just $ + map (\r -> + IRC.send $ IRC.Privmsg + (toChannel plugin message) + (Right r) ) + (splitAtNewlines $ splitLongLines r) where -- IRC only permits 512 bytes per line. Use less to allow for protocol -- information that gets sent in addition to the message content. @@ -82,3 +84,8 @@ privmsgFromPlugin message = do toChannel plugin message = case queryOnly plugin of False -> channel message True -> nick message + +messageForBot :: Message -> Maybe Message +messageForBot m = case T.stripPrefix "sorbot: " (text m) of + Nothing -> Nothing + Just t -> Just m { text = t } -- cgit v1.2.3