summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2010-10-02 00:28:48 +0200
committerJulien Dessaux2010-10-02 00:28:48 +0200
commita6ba40c2522f3b51183279be58d9f0d9c8090b21 (patch)
treea541c221ab0e54218d1cd8e601f606d67300e802
parentAdded the help command for the quote module. (diff)
downloadhsbot-a6ba40c2522f3b51183279be58d9f0d9c8090b21.tar.gz
hsbot-a6ba40c2522f3b51183279be58d9f0d9c8090b21.tar.bz2
hsbot-a6ba40c2522f3b51183279be58d9f0d9c8090b21.zip
Fixed the plugin loading process.
-rw-r--r--HsbotIrcBot/Hsbot/Irc/Plugin.hs37
1 files changed, 19 insertions, 18 deletions
diff --git a/HsbotIrcBot/Hsbot/Irc/Plugin.hs b/HsbotIrcBot/Hsbot/Irc/Plugin.hs
index 40facbe..359f12b 100644
--- a/HsbotIrcBot/Hsbot/Irc/Plugin.hs
+++ b/HsbotIrcBot/Hsbot/Irc/Plugin.hs
@@ -40,24 +40,25 @@ loadIrcPlugin :: String -> IrcBot ()
loadIrcPlugin pluginName = do
ircbot <- get
let masterChan = ircBotChan ircbot
- pluginChan <- liftIO (newChan :: IO (Chan IrcBotMsg))
- let entryPoint = case pluginName of
- "Core" -> ircBotPluginCore
- "Ping" -> ircBotPluginPing
- "Quote" -> ircBotPluginQuote
- _ -> ircBotPluginDummy
- let oldPlugins = ircBotPlugins ircbot
- -- We check for unicity
- case M.lookup pluginName oldPlugins of
- Just _ -> return ()
- Nothing -> do
- mvar <- liftIO newEmptyMVar
- threadId <- liftIO . forkIO $ finally (entryPoint pluginChan masterChan) (putMVar mvar ())
- let plugin = IrcPluginState { ircPluginName = pluginName
- , ircPluginChan = pluginChan
- , ircPluginMasterChan = masterChan }
- newPlugins = M.insert pluginName (plugin, mvar, threadId) oldPlugins
- put $ ircbot { ircBotPlugins = newPlugins }
+ (entryPoint, loadIt) = case pluginName of
+ "Core" -> (ircBotPluginCore, True)
+ "Ping" -> (ircBotPluginPing, True)
+ "Quote" -> (ircBotPluginQuote, True)
+ _ -> (ircBotPluginDummy, False)
+ when loadIt $ do
+ pluginChan <- liftIO (newChan :: IO (Chan IrcBotMsg))
+ let oldPlugins = ircBotPlugins ircbot
+ -- We check for unicity
+ case M.lookup pluginName oldPlugins of
+ Just _ -> return ()
+ Nothing -> do
+ mvar <- liftIO newEmptyMVar
+ threadId <- liftIO . forkIO $ finally (entryPoint pluginChan masterChan) (putMVar mvar ())
+ let plugin = IrcPluginState { ircPluginName = pluginName
+ , ircPluginChan = pluginChan
+ , ircPluginMasterChan = masterChan }
+ newPlugins = M.insert pluginName (plugin, mvar, threadId) oldPlugins
+ put $ ircbot { ircBotPlugins = newPlugins }
-- | Sends a list of loaded plugins
listPlugins :: IrcMsg -> String -> IrcBot ()