aboutsummaryrefslogtreecommitdiffstats
path: root/src/IRC.hs
diff options
context:
space:
mode:
authorTeddy Wing2017-08-20 17:23:36 +0200
committerTeddy Wing2017-08-20 17:23:36 +0200
commit3124acd6ae0328a8607d0807e4923f0dd75fe49e (patch)
treec2a8848292771bd4d4e4db5275f88e8b32a39f31 /src/IRC.hs
parent563252f324b315afb386dc4b0e7f54880b736255 (diff)
downloadsorbot-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/IRC.hs')
-rw-r--r--src/IRC.hs37
1 files changed, 22 insertions, 15 deletions
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 }