summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2011-09-10 00:10:46 +0200
committerJulien Dessaux2011-09-10 00:10:46 +0200
commit96c12ca43692b028dde3756b3fabb6b19bdd414e (patch)
tree0be6ce87570bbe947b8a662bdc56c7632a2fcb88
parentMerge branch 'master' into quoteModule (diff)
downloadhsbot-96c12ca43692b028dde3756b3fabb6b19bdd414e.tar.gz
hsbot-96c12ca43692b028dde3756b3fabb6b19bdd414e.tar.bz2
hsbot-96c12ca43692b028dde3756b3fabb6b19bdd414e.zip
Added the getChannel helper.
Diffstat (limited to '')
-rw-r--r--Hsbot/Message.hs8
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 _ = ""