diff options
author | Julien Dessaux | 2010-06-10 23:30:09 +0200 |
---|---|---|
committer | Julien Dessaux | 2010-06-20 17:49:39 +0200 |
commit | d97177ce3b392f80e36a93ca41ca1426b0220733 (patch) | |
tree | cfa8c4336cfebcad33236e9f0e88dacf832b5722 /Hsbot/Plugin.hs | |
parent | Fixed the plugin termination. (diff) | |
download | hsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.tar.gz hsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.tar.bz2 hsbot-d97177ce3b392f80e36a93ca41ca1426b0220733.zip |
Wrote most of the resume code for the core and the irc plugin.
Diffstat (limited to 'Hsbot/Plugin.hs')
-rw-r--r-- | Hsbot/Plugin.hs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Hsbot/Plugin.hs b/Hsbot/Plugin.hs index 3feffa8..1493c73 100644 --- a/Hsbot/Plugin.hs +++ b/Hsbot/Plugin.hs @@ -11,6 +11,7 @@ import Control.Concurrent.MVar import Control.Exception import Control.Monad.State import qualified Data.Map as M +import Data.Maybe (fromMaybe) import Prelude hiding (catch) import Hsbot.Config @@ -28,17 +29,20 @@ spawnPlugins = do spawnPlugin :: BotConfig -> Bot () spawnPlugin (IrcBotConfig ircConfig) = do bot <- get - let chan = botChan bot + let mvar = botResumeData bot + name = ircConfigName ircConfig + resumeData <- liftIO $ takeMVar mvar + let pluginResumeData = fromMaybe M.empty $ M.lookup name resumeData + chan = botChan bot pchan <- liftIO (newChan :: IO (Chan BotMsg)) - mvar <- liftIO newEmptyMVar - threadId <- liftIO . forkIO $ finally (startIrcbot ircConfig chan pchan) (putMVar mvar ()) - let plugin = PluginState { pluginName = ircConfigName ircConfig + pluginMVar <- liftIO newEmptyMVar + threadId <- liftIO . forkIO $ finally (startIrcbot ircConfig chan pchan (Just $ show pluginResumeData)) (putMVar pluginMVar ()) + let plugin = PluginState { pluginName = name , pluginChan = pchan , pluginHandles = M.empty } plugins = botPlugins bot - put $ bot { botPlugins = M.insert (pluginName plugin) (plugin, mvar, threadId) plugins } - resumeData <- gets botResumeData - liftIO $ modifyMVar_ resumeData (\oldData -> return $ M.insert (ircConfigName ircConfig) M.empty oldData) + put $ bot { botPlugins = M.insert (pluginName plugin) (plugin, pluginMVar, threadId) plugins } + liftIO . putMVar mvar $ M.insert name pluginResumeData resumeData -- | Unloads a plugin unloadPlugin :: String -> Bot () |