diff options
-rw-r--r-- | Hsbot/Message.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Hsbot/Message.hs b/Hsbot/Message.hs index a34659d..819018d 100644 --- a/Hsbot/Message.hs +++ b/Hsbot/Message.hs @@ -1,5 +1,6 @@ module Hsbot.Message ( answerMsg + , getChannel , getCommand , getDestination , getSender @@ -18,6 +19,7 @@ import Hsbot.Types readMsg :: Plugin (Env IO) Message readMsg = asks pluginChan >>= liftIO . readChan +-- TODO : remove the Plugin layer since it's useless, and use the envChan instead writeMsg :: Message -> Plugin (Env IO) () writeMsg msg = asks pluginMaster >>= liftIO . flip writeChan msg @@ -28,6 +30,11 @@ answerMsg (IRC.Message (Just (IRC.NickName nick _ _)) _ (channel:_)) msg | otherwise = writeMsg . OutgoingMsg $ IRC.Message Nothing "PRIVMSG" [nick, msg] answerMsg _ _ = return () +-- | Get the channel a message has been posted on +getChannel :: IRC.Message -> String +getChannel (IRC.Message _ _ (channel:_)) = channel +getChannel _ = "" + -- | Get the command in the IRC message if there is one getCommand :: IRC.Message -> Env IO [String] getCommand (IRC.Message _ _ (_:msg:[])) = getCommandFrom $ words msg @@ -41,6 +48,7 @@ getCommand (IRC.Message _ _ (_:msg:[])) = getCommandFrom $ words msg getCommandFrom _ = return [] getCommand _ = return [] +-- | Get the sender of a message getSender :: IRC.Message -> String getSender (IRC.Message (Just (IRC.NickName nick _ _)) _ _) = nick getSender _ = "" |