From 9307d2f5a1531f4a89264207be482cc23382908c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Aug 2017 17:28:18 +0200 Subject: IRC: Only require "sorbot: " prefix in channels When talking with the bot in a private one-to-one query, there's no reason to use the "sorbot: " prefix because you're not talking to anyone else. In that case, just behave like we did before and allow users to send commands with no prefix. --- src/IRC.hs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/IRC.hs b/src/IRC.hs index 53f6969..d67f28e 100644 --- a/src/IRC.hs +++ b/src/IRC.hs @@ -50,30 +50,31 @@ handlePrivmsg = IRC.EventHandler , channel = chan , nick = nick } - response <- liftIO $ privmsgFromPlugin message - case response of - Nothing -> return () - Just r -> sequence_ r + case messageForBot message of + Nothing -> return () + Just message -> do + response <- liftIO $ privmsgFromPlugin message + case response of + Nothing -> return () + Just r -> sequence_ r privmsgFromPlugin :: Message -> IO (Maybe [IRC.StatefulIRC s ()]) privmsgFromPlugin message = do - 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) + 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. -- cgit v1.2.3