Fixed the plugin loading process.
This commit is contained in:
parent
d0b0fb6ac1
commit
a6ba40c252
1 changed files with 19 additions and 18 deletions
|
@ -40,24 +40,25 @@ loadIrcPlugin :: String -> IrcBot ()
|
||||||
loadIrcPlugin pluginName = do
|
loadIrcPlugin pluginName = do
|
||||||
ircbot <- get
|
ircbot <- get
|
||||||
let masterChan = ircBotChan ircbot
|
let masterChan = ircBotChan ircbot
|
||||||
pluginChan <- liftIO (newChan :: IO (Chan IrcBotMsg))
|
(entryPoint, loadIt) = case pluginName of
|
||||||
let entryPoint = case pluginName of
|
"Core" -> (ircBotPluginCore, True)
|
||||||
"Core" -> ircBotPluginCore
|
"Ping" -> (ircBotPluginPing, True)
|
||||||
"Ping" -> ircBotPluginPing
|
"Quote" -> (ircBotPluginQuote, True)
|
||||||
"Quote" -> ircBotPluginQuote
|
_ -> (ircBotPluginDummy, False)
|
||||||
_ -> ircBotPluginDummy
|
when loadIt $ do
|
||||||
let oldPlugins = ircBotPlugins ircbot
|
pluginChan <- liftIO (newChan :: IO (Chan IrcBotMsg))
|
||||||
-- We check for unicity
|
let oldPlugins = ircBotPlugins ircbot
|
||||||
case M.lookup pluginName oldPlugins of
|
-- We check for unicity
|
||||||
Just _ -> return ()
|
case M.lookup pluginName oldPlugins of
|
||||||
Nothing -> do
|
Just _ -> return ()
|
||||||
mvar <- liftIO newEmptyMVar
|
Nothing -> do
|
||||||
threadId <- liftIO . forkIO $ finally (entryPoint pluginChan masterChan) (putMVar mvar ())
|
mvar <- liftIO newEmptyMVar
|
||||||
let plugin = IrcPluginState { ircPluginName = pluginName
|
threadId <- liftIO . forkIO $ finally (entryPoint pluginChan masterChan) (putMVar mvar ())
|
||||||
, ircPluginChan = pluginChan
|
let plugin = IrcPluginState { ircPluginName = pluginName
|
||||||
, ircPluginMasterChan = masterChan }
|
, ircPluginChan = pluginChan
|
||||||
newPlugins = M.insert pluginName (plugin, mvar, threadId) oldPlugins
|
, ircPluginMasterChan = masterChan }
|
||||||
put $ ircbot { ircBotPlugins = newPlugins }
|
newPlugins = M.insert pluginName (plugin, mvar, threadId) oldPlugins
|
||||||
|
put $ ircbot { ircBotPlugins = newPlugins }
|
||||||
|
|
||||||
-- | Sends a list of loaded plugins
|
-- | Sends a list of loaded plugins
|
||||||
listPlugins :: IrcMsg -> String -> IrcBot ()
|
listPlugins :: IrcMsg -> String -> IrcBot ()
|
||||||
|
|
Reference in a new issue