aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-08-16 21:00:54 +0200
committerTeddy Wing2017-08-16 21:00:54 +0200
commit20b0d046c2a19ec567a1d61af07bfaec143d8b70 (patch)
tree76df0ca05b955fbaf9c7ec176e9b609f5eaa776e
parent1311706d7cca3cd67af5c974c763aba53b0011a9 (diff)
downloadsorbot-20b0d046c2a19ec567a1d61af07bfaec143d8b70.tar.bz2
IRC.hs: Handle `Nothing` branches
Handle our un-handled `Nothing` branches. Make `privmsgFromPlugin` return a `Maybe` so we can decide whether or not to send a message upstream. If we do get a `Nothing` from `privmsgFromPlugin`, just return unit and don't send any chat message, since no plugin matched and thus none could respond.
-rw-r--r--src/IRC.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/IRC.hs b/src/IRC.hs
index 253d51f..de50bbb 100644
--- a/src/IRC.hs
+++ b/src/IRC.hs
@@ -53,19 +53,20 @@ handlePrivmsg = IRC.EventHandler
-- msg -> IRC.send msg
-- response <- privmsgFromPlugin message
response <- liftIO $ privmsgFromPlugin message
- IRC.send response
+ case response of
+ Nothing -> return ()
+ Just r -> r
-privmsgFromPlugin :: Message -> IO (IRC.Message T.Text)
+privmsgFromPlugin :: Message -> IO (Maybe (IRC.StatefulIRC s ()))
privmsgFromPlugin message = do
case matchPlugin message of
- -- Nothing ->
+ Nothing -> return Nothing
Just plugin -> do
- -- let response = liftIO $ performPlugin plugin message in
response <- liftIO $ performPlugin plugin message
return $ case response of
- Left err -> IRC.Privmsg
+ Left err -> Just $ IRC.send $ IRC.Privmsg
(T.pack (channel message))
(Right (T.pack err))
- Right r -> IRC.Privmsg
+ Right r -> Just $ IRC.send $ IRC.Privmsg
(T.pack (channel message))
(Right (T.pack r))