summaryrefslogtreecommitdiff
path: root/Hsbot/IRCPlugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 21:05:37 +0100
committerJulien Dessaux2010-02-04 21:05:37 +0100
commitfd8d5faf5f4ab085b01316e15403779ca30cf3f9 (patch)
tree83dfae790dcb184d651567f06929fc69338733a9 /Hsbot/IRCPlugin.hs
parentFixed some types' functions. (diff)
downloadhsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.tar.gz
hsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.tar.bz2
hsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.zip
Began a complete rewrite of command and plugin management.
Wrote a command routing statement, added an IrcPlugin monad.
Diffstat (limited to 'Hsbot/IRCPlugin.hs')
-rw-r--r--Hsbot/IRCPlugin.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/Hsbot/IRCPlugin.hs b/Hsbot/IRCPlugin.hs
new file mode 100644
index 0000000..8c5eb86
--- /dev/null
+++ b/Hsbot/IRCPlugin.hs
@@ -0,0 +1,39 @@
+module Hsbot.IRCPlugin
+ ( readMsg
+ , sendRegisterCommand
+ , sendUnregisterCommand
+ , writeMsg
+ ) where
+
+import Control.Concurrent.Chan
+import Control.Monad.State
+
+import Hsbot.Types
+
+-- | Basic input output for IrcPlugins
+readMsg :: IrcPlugin (BotMsg)
+readMsg = do
+ chan <- gets instanceChan
+ input <- liftIO $ readChan chan
+ return input
+
+writeMsg :: BotMsg -> IrcPlugin ()
+writeMsg botMsg = do
+ serverChan <- gets instanceServerChan
+ liftIO $ writeChan serverChan $ botMsg
+
+-- | Commands management
+sendCommand :: String -> String -> String -> IrcPlugin ()
+sendCommand cmd to params = do
+ serverChan <- gets instanceServerChan
+ from <- gets instanceName
+ liftIO $ writeChan serverChan $ InternalCmd $ IntCmd cmd from to params
+
+sendRegisterCommand :: String -> IrcPlugin ()
+sendRegisterCommand cmd = sendCommand "REGISTER" "CORE" cmd
+
+sendUnregisterCommand :: String -> IrcPlugin ()
+sendUnregisterCommand cmd = sendCommand "UNREGISTER" "CORE" cmd
+
+-- | a isAdmin helper : I need an admin plugin (to track admins' status around chans)
+