From 57bec4921b02e745f412e954ea4a4ec6b3c31b3b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 29 May 2010 16:59:41 +0200 Subject: Rationalized the way bot configs are handled. --- Hsbot/Plugin.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Hsbot/Plugin.hs') diff --git a/Hsbot/Plugin.hs b/Hsbot/Plugin.hs index 10c59af..e545e8d 100644 --- a/Hsbot/Plugin.hs +++ b/Hsbot/Plugin.hs @@ -1,7 +1,7 @@ module Hsbot.Plugin ( killPlugin - , spawnIrcPlugins - , spawnIrcPlugin + , spawnPlugins + , spawnPlugin , unloadPlugin ) where @@ -17,24 +17,26 @@ import Hsbot.Irc.Config import Hsbot.Irc.Core import Hsbot.Types --- | spawns IrcPlugins -spawnIrcPlugins :: Bot () -spawnIrcPlugins = do +-- | spawns plugins +spawnPlugins :: Bot () +spawnPlugins = do config <- gets botConfig - mapM_ (spawnIrcPlugin) (ircConfigs config) + mapM_ (spawnPlugin) config --- | spawns a single irc plugin -spawnIrcPlugin :: IrcConfig -> Bot () -spawnIrcPlugin config = do +-- | spawns a single plugin +spawnPlugin :: BotConfig -> Bot () +spawnPlugin (IrcBotConfig ircConfig) = do bot <- get let chan = botChan bot pchan <- liftIO (newChan :: IO (Chan BotMsg)) - threadId <- liftIO $ forkIO (startIrcbot config chan pchan) - let plugin = PluginState { pluginName = ircConfigName config + threadId <- liftIO $ forkIO (startIrcbot ircConfig chan pchan) + let plugin = PluginState { pluginName = ircConfigName ircConfig , pluginChan = pchan , pluginHandles = M.empty } plugins = botPlugins bot put $ bot { botPlugins = M.insert (pluginName plugin) (plugin, threadId) plugins } + resumeData <- gets botResumeData + liftIO $ modifyMVar_ resumeData (\oldData -> return $ M.insert (ircConfigName ircConfig) M.empty oldData) -- | Unloads a plugin unloadPlugin :: String -> Bot () -- cgit v1.2.3