summaryrefslogtreecommitdiff
path: root/Hsbot/Irc/PluginCommons.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-18 00:46:36 +0200
committerJulien Dessaux2010-05-18 00:46:36 +0200
commit5b8cffbf6809b378aab9c6e1f7601112d810b709 (patch)
treef48748168b7a56f4235c50f8f8bfa928d61ccdea /Hsbot/Irc/PluginCommons.hs
parentRemoved thread ids from plugins data structure. (diff)
downloadhsbot-5b8cffbf6809b378aab9c6e1f7601112d810b709.tar.gz
hsbot-5b8cffbf6809b378aab9c6e1f7601112d810b709.tar.bz2
hsbot-5b8cffbf6809b378aab9c6e1f7601112d810b709.zip
Cleaned the definition of irc plugins' data structure.
Diffstat (limited to 'Hsbot/Irc/PluginCommons.hs')
-rw-r--r--Hsbot/Irc/PluginCommons.hs66
1 files changed, 0 insertions, 66 deletions
diff --git a/Hsbot/Irc/PluginCommons.hs b/Hsbot/Irc/PluginCommons.hs
deleted file mode 100644
index 51f9473..0000000
--- a/Hsbot/Irc/PluginCommons.hs
+++ /dev/null
@@ -1,66 +0,0 @@
-module Hsbot.Irc.PluginCommons
- ( IrcPlugin
- , IrcPluginState (..)
- , answerMsg
- , readMsg
- , sendCommand
- , sendCommandWithRequest
- , sendRegisterCommand
- , sendUnregisterCommand
- , writeMsg
- ) where
-
-import Control.Concurrent
-import Control.Concurrent.Chan ()
-import Control.Monad.State
-import Data.Maybe (fromMaybe)
-
-import Hsbot.Irc.Message
-
--- | The IrcPlugin monad
-type IrcPlugin = StateT IrcPluginState IO
-
--- | A plugin state
-data IrcPluginState = IrcPluginState
- { ircPluginName :: String -- The plugin's name
- , ircPluginChan :: Chan IrcBotMsg -- The plugin chan
- , ircPluginMasterChan :: Chan IrcBotMsg -- The master's chan
- }
-
---- | Basic input output for IrcPlugins
-readMsg :: IrcPlugin (IrcBotMsg)
-readMsg = do
- chan <- gets ircPluginChan
- input <- liftIO $ readChan chan
- return input
-
-writeMsg :: IrcBotMsg -> IrcPlugin ()
-writeMsg (OutIrcMsg msg) = do
- chan <- gets ircPluginMasterChan
- liftIO $ writeChan chan (OutIrcMsg msg)
-writeMsg _ = return ()
-
-answerMsg :: IrcMsg -> String -> IrcPlugin ()
-answerMsg request msg = do
- let chanOrigin = head $ ircMsgParameters request
- sender = takeWhile (/= '!') $ fromMaybe "" (ircMsgPrefix request)
- case head chanOrigin of
- '#' -> writeMsg . OutIrcMsg $ IrcMsg Nothing "PRIVMSG" [chanOrigin, msg]
- _ -> writeMsg . OutIrcMsg $ IrcMsg Nothing "PRIVMSG" [sender, msg]
-
--- | Command management
-sendCommand :: String -> String -> String -> IrcPlugin ()
-sendCommand cmd to params = sendCommandWithRequest cmd to params emptyIrcMsg
-
-sendCommandWithRequest :: String -> String -> String -> IrcMsg -> IrcPlugin ()
-sendCommandWithRequest cmd to params originalRequest = do
- masterChan <- gets ircPluginMasterChan
- from <- gets ircPluginName
- liftIO . writeChan masterChan . IntIrcCmd $ IrcCmd cmd from to params originalRequest
-
-sendRegisterCommand :: String -> IrcPlugin ()
-sendRegisterCommand cmd = sendCommand "REGISTER" "CORE" cmd
-
-sendUnregisterCommand :: String -> IrcPlugin ()
-sendUnregisterCommand cmd = sendCommand "UNREGISTER" "CORE" cmd
-