summaryrefslogtreecommitdiff
path: root/Hsbot/IRCPlugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-16 00:01:00 +0200
committerJulien Dessaux2010-05-16 00:01:00 +0200
commitc1662ba7b982a8502dc9f32031b7cb518df7f60e (patch)
treef00dbd9cb39bf0fbc20949105ea2b93d9e868070 /Hsbot/IRCPlugin.hs
parentAdded the quote module. (diff)
downloadhsbot-c1662ba7b982a8502dc9f32031b7cb518df7f60e.tar.gz
hsbot-c1662ba7b982a8502dc9f32031b7cb518df7f60e.tar.bz2
hsbot-c1662ba7b982a8502dc9f32031b7cb518df7f60e.zip
Rewrote nearly everything!v0.2.0
* Rewrote the whole architecture to achieve extreme modularity * Added the ability to build a multiprotocol bot * Added cabal integration * Added configuration handling the XMonad style * Added configuration in ~/.hsbot * Refactored many many named and functions * Refactored data structures * Cleaned a big bunch of stuff
Diffstat (limited to 'Hsbot/IRCPlugin.hs')
-rw-r--r--Hsbot/IRCPlugin.hs66
1 files changed, 0 insertions, 66 deletions
diff --git a/Hsbot/IRCPlugin.hs b/Hsbot/IRCPlugin.hs
deleted file mode 100644
index e0299fc..0000000
--- a/Hsbot/IRCPlugin.hs
+++ /dev/null
@@ -1,66 +0,0 @@
-module Hsbot.IRCPlugin
- ( IrcPlugin
- , PluginState(..)
- , answerMsg
- , readMsg
- , sendCommand
- , sendCommandWithRequest
- , sendRegisterCommand
- , sendUnregisterCommand
- , writeMsg
- ) where
-
-import Control.Concurrent.Chan
-import Control.Monad.State
-import Data.Maybe(fromMaybe)
-
-import Hsbot.Types
-
--- | The IrcPlugin monad
-type IrcPlugin a = StateT PluginState IO a
-
--- | An IRCPlugin state
-data PluginState = PluginState
- { instanceName :: String -- The plugin's name
- , instanceServerChan :: Chan BotMsg -- The server channel
- , instanceChan :: Chan BotMsg -- The plugin channel
- }
-
--- | 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
-
-answerMsg :: IrcMsg -> String -> IrcPlugin ()
-answerMsg request msg = do
- let chanOrigin = head $ parameters request
- sender = takeWhile (/= '!') $ fromMaybe "" (prefix request)
- 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 emptyIrcMsg
-
-sendCommandWithRequest :: String -> String -> String -> IrcMsg -> IrcPlugin ()
-sendCommandWithRequest cmd to params originalRequest = do
- serverChan <- gets instanceServerChan
- from <- gets instanceName
- liftIO . writeChan serverChan . InternalCmd $ IntCmd cmd from to params originalRequest
-
-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)
-