summaryrefslogtreecommitdiff
path: root/Hsbot/IRCPlugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-04-22 19:42:53 +0200
committerJulien Dessaux2010-04-22 19:42:53 +0200
commit727adadc28a40fe8843a0727168684d3c2b3e114 (patch)
tree03af9d78502488676c74d1f55762c5c6b6de2116 /Hsbot/IRCPlugin.hs
parentWrote the list plugin command. (diff)
downloadhsbot-727adadc28a40fe8843a0727168684d3c2b3e114.tar.gz
hsbot-727adadc28a40fe8843a0727168684d3c2b3e114.tar.bz2
hsbot-727adadc28a40fe8843a0727168684d3c2b3e114.zip
Added an utility function to correctly answer a message we receive (aka /msg)
Diffstat (limited to 'Hsbot/IRCPlugin.hs')
-rw-r--r--Hsbot/IRCPlugin.hs13
1 files changed, 12 insertions, 1 deletions
diff --git a/Hsbot/IRCPlugin.hs b/Hsbot/IRCPlugin.hs
index c32d24c..4707ce1 100644
--- a/Hsbot/IRCPlugin.hs
+++ b/Hsbot/IRCPlugin.hs
@@ -1,5 +1,6 @@
module Hsbot.IRCPlugin
- ( readMsg
+ ( answerMsg
+ , readMsg
, sendCommand
, sendCommandWithRequest
, sendRegisterCommand
@@ -9,6 +10,7 @@ module Hsbot.IRCPlugin
import Control.Concurrent.Chan
import Control.Monad.State
+import Data.Maybe(fromMaybe)
import Hsbot.Types
@@ -24,6 +26,15 @@ writeMsg botMsg = do
serverChan <- gets instanceServerChan
liftIO $ writeChan serverChan $ botMsg
+answerMsg :: Maybe IrcMsg -> String -> IrcPlugin ()
+answerMsg request msg = do
+ let incoming = fromMaybe (IrcMsg Nothing "ARGH" []) request
+ chanOrigin = head $ parameters (incoming)
+ sender = takeWhile (/= '!') $ fromMaybe "ARGH" (prefix incoming)
+ case head chanOrigin of
+ '#' -> writeMsg $ OutputMsg $ IrcMsg Nothing "PRIVMSG" [chanOrigin, msg]
+ _ -> writeMsg $ OutputMsg $ IrcMsg Nothing "PRIVMSG" [sender, msg]
+
-- | Commands management
sendCommand :: String -> String -> String -> IrcPlugin ()
sendCommand cmd to params = sendCommandWithRequest cmd to params Nothing