summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
Diffstat (limited to 'Hsbot')
-rw-r--r--Hsbot/Message.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/Hsbot/Message.hs b/Hsbot/Message.hs
index 825a649..dd15f75 100644
--- a/Hsbot/Message.hs
+++ b/Hsbot/Message.hs
@@ -1,10 +1,12 @@
module Hsbot.Message
( answerMsg
+ , getCommand
, readMsg
, writeMsg
) where
import Control.Concurrent
+import qualified Data.List as L
import Control.Monad.Reader
import qualified Network.IRC as IRC
@@ -24,3 +26,13 @@ answerMsg (IRC.Message (Just (IRC.NickName nick _ _)) _ (channel:_)) msg
| otherwise = writeMsg . OutgoingMsg $ IRC.Message Nothing "PRIVMSG" [nick, msg]
answerMsg _ _ = return ()
+-- | Get the command in the IRC message if there is one
+getCommand :: IRC.Message -> Env IO [String]
+getCommand (IRC.Message _ _ (_:msg:[])) = do
+ currentBotState <- asks envBotState >>= liftIO . readMVar
+ let cmd:stuff = if msg /= "" then words msg else ["",""]
+ if botNickname currentBotState `L.isPrefixOf` cmd
+ then return stuff
+ else return []
+getCommand _ = return []
+