diff options
author | Julien Dessaux | 2011-05-10 23:21:28 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-05-10 23:21:28 +0200 |
commit | aba484db543d8d8b83affe9f224cd555ed0c2f7b (patch) | |
tree | 43b71e16539d4b82bec842dd421b2a0698a4cc74 | |
parent | Added the ability to directly answer /msg. (diff) | |
download | hsbot-aba484db543d8d8b83affe9f224cd555ed0c2f7b.tar.gz hsbot-aba484db543d8d8b83affe9f224cd555ed0c2f7b.tar.bz2 hsbot-aba484db543d8d8b83affe9f224cd555ed0c2f7b.zip |
Implemented bot commands parsing.
-rw-r--r-- | Hsbot/Message.hs | 12 | ||||
-rw-r--r-- | hsbot.cabal | 2 |
2 files changed, 13 insertions, 1 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 [] + diff --git a/hsbot.cabal b/hsbot.cabal index b2a9119..f92af2d 100644 --- a/hsbot.cabal +++ b/hsbot.cabal @@ -1,5 +1,5 @@ Name: hsbot -Version: 0.4.11 +Version: 0.4.12 Cabal-version: >=1.2 Synopsis: A multipurposes IRC bot Description: |