Added the getChannel helper.
This commit is contained in:
		
					parent
					
						
							
								900c242551
							
						
					
				
			
			
				commit
				
					
						96c12ca436
					
				
			
		
					 1 changed files with 8 additions and 0 deletions
				
			
		| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
module Hsbot.Message
 | 
					module Hsbot.Message
 | 
				
			||||||
    ( answerMsg
 | 
					    ( answerMsg
 | 
				
			||||||
 | 
					    , getChannel
 | 
				
			||||||
    , getCommand
 | 
					    , getCommand
 | 
				
			||||||
    , getDestination
 | 
					    , getDestination
 | 
				
			||||||
    , getSender
 | 
					    , getSender
 | 
				
			||||||
| 
						 | 
					@ -18,6 +19,7 @@ import Hsbot.Types
 | 
				
			||||||
readMsg :: Plugin (Env IO) Message
 | 
					readMsg :: Plugin (Env IO) Message
 | 
				
			||||||
readMsg = asks pluginChan >>= liftIO . readChan
 | 
					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 :: Message -> Plugin (Env IO) ()
 | 
				
			||||||
writeMsg msg = asks pluginMaster >>= liftIO . flip writeChan msg
 | 
					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]
 | 
					    | otherwise = writeMsg . OutgoingMsg $ IRC.Message Nothing "PRIVMSG" [nick, msg]
 | 
				
			||||||
answerMsg _ _ = return ()
 | 
					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
 | 
					-- | Get the command in the IRC message if there is one
 | 
				
			||||||
getCommand :: IRC.Message -> Env IO [String]
 | 
					getCommand :: IRC.Message -> Env IO [String]
 | 
				
			||||||
getCommand (IRC.Message _ _ (_:msg:[])) = getCommandFrom $ words msg
 | 
					getCommand (IRC.Message _ _ (_:msg:[])) = getCommandFrom $ words msg
 | 
				
			||||||
| 
						 | 
					@ -41,6 +48,7 @@ getCommand (IRC.Message _ _ (_:msg:[])) = getCommandFrom $ words msg
 | 
				
			||||||
    getCommandFrom _ = return []
 | 
					    getCommandFrom _ = return []
 | 
				
			||||||
getCommand _ = return []
 | 
					getCommand _ = return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- | Get the sender of a message
 | 
				
			||||||
getSender :: IRC.Message -> String
 | 
					getSender :: IRC.Message -> String
 | 
				
			||||||
getSender (IRC.Message (Just (IRC.NickName nick _ _)) _ _) = nick
 | 
					getSender (IRC.Message (Just (IRC.NickName nick _ _)) _ _) = nick
 | 
				
			||||||
getSender _ = ""
 | 
					getSender _ = ""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue