From daea135424857594622573fa1a900b436d7ee0ae Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 29 May 2010 00:55:14 +0200 Subject: Implemented the clean killing of plugins' threads. --- Hsbot/Irc/Plugin.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Hsbot/Irc/Plugin.hs') diff --git a/Hsbot/Irc/Plugin.hs b/Hsbot/Irc/Plugin.hs index d972db2..28026aa 100644 --- a/Hsbot/Irc/Plugin.hs +++ b/Hsbot/Irc/Plugin.hs @@ -1,6 +1,7 @@ module Hsbot.Irc.Plugin ( IrcPlugin , IrcPluginState (..) + , killIrcPlugin , listPlugins , loadIrcPlugin , sendToPlugin @@ -72,16 +73,23 @@ listPlugins originalRequest dest = do -- | Unloads a plugin unloadIrcPlugin :: String -> IrcBot () unloadIrcPlugin name = do + killIrcPlugin name ircbot <- get - let oldPlugins = ircBotPlugins ircbot - oldResumeData = ircBotResumeData ircbot + let oldResumeData = ircBotResumeData ircbot + newPlugins = M.keys $ ircBotPlugins ircbot + newResumeData = M.insert "PLUGINS" (show newPlugins) oldResumeData + put $ ircbot { ircBotResumeData = newResumeData } + +-- | kills a plugin +killIrcPlugin :: String -> IrcBot () +killIrcPlugin name = do + ircbot <- get + let oldPlugins = ircBotPlugins ircbot -- We check if the plugin exists case M.lookup name oldPlugins of Just (_, threadId) -> do - let newPlugins = M.delete name oldPlugins - newResumeData = M.insert "PLUGINS" (show $ M.keys newPlugins) oldResumeData + let newPlugins = M.delete name oldPlugins liftIO $ throwTo threadId UserInterrupt - put $ ircbot { ircBotPlugins = newPlugins - , ircBotResumeData = newResumeData } - Nothing -> return () + put $ ircbot { ircBotPlugins = newPlugins } + Nothing -> return () -- cgit v1.2.3