diff options
| author | Teddy Wing | 2017-08-20 15:04:50 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-08-20 15:15:15 +0200 | 
| commit | 3f39ebaa923ee5ce05a379313cbb046f093aa66a (patch) | |
| tree | afc8e1761547dea1f1331b91b86ae213ff07fdfd /src | |
| parent | 6009f91efd3dfd57122d2cf98d7255ec99ba8475 (diff) | |
| download | sorbot-3f39ebaa923ee5ce05a379313cbb046f093aa66a.tar.bz2 | |
IRC: Send private messages when plugin is `queryOnly`
If the plugin is defined as `queryOnly`, the response shouldn't be sent
on the channel to everyone, it should instead be sent directly to the
user in a private query message.
Enable this functionality for the Help plugin so that help output only
gets sent to the user requesting help. This ensures other channel
participants don't get an annoyingly long section of output that they
didn't ask for.
Diffstat (limited to 'src')
| -rw-r--r-- | src/IRC.hs | 13 | ||||
| -rw-r--r-- | src/Plugin/Help.hs | 1 | 
2 files changed, 12 insertions, 2 deletions
| @@ -13,6 +13,7 @@ import qualified Network.IRC.Client as IRC  import Message  import Plugin (matchPlugin, performPlugin) +import Plugin.Base (queryOnly)  connectIRC :: B.ByteString -> Int -> T.Text -> IO ()  connectIRC host port nick = do @@ -62,10 +63,14 @@ privmsgFromPlugin message = do              response <- liftIO $ performPlugin plugin message              return $ case response of                  Left err -> Just $ -                    [IRC.send $ IRC.Privmsg (channel message) (Right err)] +                    [IRC.send $ IRC.Privmsg +                        (toChannel plugin message) +                        (Right err)]                  Right r  -> Just $                      map (\r -> -                            IRC.send $ IRC.Privmsg (channel message) (Right 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 @@ -73,3 +78,7 @@ privmsgFromPlugin message = do      splitLongLines txt = T.chunksOf 400 txt      splitAtNewlines lst = foldr (\s acc -> (T.lines s) ++ acc) [] lst + +    toChannel plugin message = case queryOnly plugin of +        False -> channel message +        True  -> nick message diff --git a/src/Plugin/Help.hs b/src/Plugin/Help.hs index 258a80a..63143b1 100644 --- a/src/Plugin/Help.hs +++ b/src/Plugin/Help.hs @@ -14,6 +14,7 @@ help = defaultPlugin      , perform     = helpAction      , command     = "help"      , description = "Show a list of available bot commands." +    , queryOnly   = True      }  helpAction :: PluginAction | 
