diff options
| author | Teddy Wing | 2017-08-20 17:23:36 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-08-20 17:23:36 +0200 | 
| commit | 3124acd6ae0328a8607d0807e4923f0dd75fe49e (patch) | |
| tree | c2a8848292771bd4d4e4db5275f88e8b32a39f31 /src | |
| parent | 563252f324b315afb386dc4b0e7f54880b736255 (diff) | |
| download | sorbot-3124acd6ae0328a8607d0807e4923f0dd75fe49e.tar.bz2 | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/IRC.hs | 37 | 
1 files changed, 22 insertions, 15 deletions
| @@ -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 } | 
