aboutsummaryrefslogtreecommitdiffstats
path: root/src/IRC.hs
diff options
context:
space:
mode:
authorTeddy Wing2017-08-20 02:07:21 +0200
committerTeddy Wing2017-08-20 02:12:10 +0200
commit7ec97cd79face496f739265dcf1841f04ce1c519 (patch)
tree3d998229bd617f08d56addaf5cbf82962aef8ae7 /src/IRC.hs
parent473b9098763000f6b1e5c531f2bd6c8b2f8a40c1 (diff)
downloadsorbot-7ec97cd79face496f739265dcf1841f04ce1c519.tar.bz2
Reformat Help output
Instead of printing all help text on a single line as a result of joining the list of help text, print each plugin's help on a separate line. Also separate commands from descriptions with a dash instead of a tab as the tab character was getting rendered as an `I` in irssi instead of the actual whitespace I had been hoping for. The dash in inspired by Hubot. In order to print multiple lines of output, we needed to change the IRC PRIVMSG handler. This now splits the plugin result at newlines into a list and sends separate PRIVMSGs for each line of output. Before, text with newlines would only show the first line in the resulting IRC message. Assume plugin error messages will always be a single line.
Diffstat (limited to 'src/IRC.hs')
-rw-r--r--src/IRC.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/IRC.hs b/src/IRC.hs
index d086511..259772c 100644
--- a/src/IRC.hs
+++ b/src/IRC.hs
@@ -4,6 +4,7 @@ module IRC
( connectIRC
) where
+import Control.Monad (sequence_)
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString as B
import qualified Data.Text as T
@@ -40,7 +41,7 @@ handlePrivmsg = IRC.EventHandler
response <- liftIO $ privmsgFromPlugin message
case response of
Nothing -> return ()
- Just r -> r
+ Just r -> sequence_ r
dispatchEvent (IRC.Event
_ (IRC.Channel chan nick) (IRC.Privmsg _ (Right msg))) = do
let message = Message
@@ -51,18 +52,18 @@ handlePrivmsg = IRC.EventHandler
response <- liftIO $ privmsgFromPlugin message
case response of
Nothing -> return ()
- Just r -> r
+ Just r -> sequence_ r
-privmsgFromPlugin :: Message -> IO (Maybe (IRC.StatefulIRC s ()))
+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
- (channel message)
- (Right err)
- Right r -> Just $ IRC.send $ IRC.Privmsg
- (channel message)
- (Right r)
+ Left err -> Just $
+ [IRC.send $ IRC.Privmsg (channel message) (Right err)]
+ Right r -> Just $
+ map (\r ->
+ IRC.send $ IRC.Privmsg (channel message) (Right r) )
+ (T.lines r)