diff options
author | Julien Dessaux | 2011-05-06 19:15:40 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-05-06 19:15:40 +0200 |
commit | a8c0c8578718098e7a0482678ab727533ee09862 (patch) | |
tree | c9a1d07d47e6089ba1fadacf595fd9dd8039a03e /Hsbot/Plugin | |
parent | Added a shitload of ducks to recognize and kill! (diff) | |
download | hsbot-a8c0c8578718098e7a0482678ab727533ee09862.tar.gz hsbot-a8c0c8578718098e7a0482678ab727533ee09862.tar.bz2 hsbot-a8c0c8578718098e7a0482678ab727533ee09862.zip |
Made the Plugin monad a Reader instead of a State since it can't change.
Diffstat (limited to '')
-rw-r--r-- | Hsbot/Plugin.hs | 13 | ||||
-rw-r--r-- | Hsbot/Plugin/Duck.hs | 2 | ||||
-rw-r--r-- | Hsbot/Plugin/Ping.hs | 2 |
3 files changed, 7 insertions, 10 deletions
diff --git a/Hsbot/Plugin.hs b/Hsbot/Plugin.hs index ebcff8d..6d1eacf 100644 --- a/Hsbot/Plugin.hs +++ b/Hsbot/Plugin.hs @@ -23,19 +23,16 @@ loadPlugin pId = do let name = pluginName pId loop = pluginEp pId oldPlugins = botPlugins bot - pState = PluginState { pluginId = pId - , pluginChan = chan - , pluginMaster = master } + pEnv = PluginEnv { pluginId = pId + , pluginChan = chan + , pluginMaster = master } case M.lookup name oldPlugins of Just _ -> liftIO . warningM "Hsbot.Core.LoadPlugin" $ "Not loading already loaded plugin : " ++ name Nothing -> do liftIO . infoM "Hsbot.Core.LoadPlugin" $ "Loading plugin : " ++ name env <- lift ask - finalStateMVar <- liftIO newEmptyMVar - threadId <- liftIO . forkIO $ runReaderT (execStateT loop pState >>= storeFinalState finalStateMVar) env - let newPlugins = M.insert name (pState, finalStateMVar, threadId) oldPlugins + threadId <- liftIO . forkIO $ runReaderT (runReaderT loop pEnv) env + let newPlugins = M.insert name (pEnv, threadId) oldPlugins put $ bot { botPlugins = newPlugins , botHooks = chan : botHooks bot } - storeFinalState :: MVar PluginState -> PluginState -> Env IO () - storeFinalState finalStateMVar finalState = liftIO $ putMVar finalStateMVar finalState diff --git a/Hsbot/Plugin/Duck.hs b/Hsbot/Plugin/Duck.hs index 11f7637..7e8c521 100644 --- a/Hsbot/Plugin/Duck.hs +++ b/Hsbot/Plugin/Duck.hs @@ -6,7 +6,7 @@ module Hsbot.Plugin.Duck import Control.Concurrent.Chan () import qualified Data.List as L -import Control.Monad.State +import Control.Monad.Reader import qualified Network.IRC as IRC import Prelude hiding (catch) diff --git a/Hsbot/Plugin/Ping.hs b/Hsbot/Plugin/Ping.hs index 179bcb3..54ba396 100644 --- a/Hsbot/Plugin/Ping.hs +++ b/Hsbot/Plugin/Ping.hs @@ -4,7 +4,7 @@ module Hsbot.Plugin.Ping ) where import Control.Concurrent.Chan () -import Control.Monad.State +import Control.Monad.Reader import qualified Network.IRC as IRC import Prelude hiding (catch) |