summaryrefslogtreecommitdiff
path: root/Hsbot/Plugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-29 16:59:41 +0200
committerJulien Dessaux2010-05-29 17:05:56 +0200
commit57bec4921b02e745f412e954ea4a4ec6b3c31b3b (patch)
tree3cca9e3630772cd9594442ff3ff2101a80599a4d /Hsbot/Plugin.hs
parentImplemented the clean killing of plugins' threads. (diff)
downloadhsbot-57bec4921b02e745f412e954ea4a4ec6b3c31b3b.tar.gz
hsbot-57bec4921b02e745f412e954ea4a4ec6b3c31b3b.tar.bz2
hsbot-57bec4921b02e745f412e954ea4a4ec6b3c31b3b.zip
Rationalized the way bot configs are handled.
Diffstat (limited to 'Hsbot/Plugin.hs')
-rw-r--r--Hsbot/Plugin.hs24
1 files changed, 13 insertions, 11 deletions
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 ()