summaryrefslogtreecommitdiff
path: root/Hsbot/Irc/Plugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-29 00:55:14 +0200
committerJulien Dessaux2010-05-29 01:01:31 +0200
commitdaea135424857594622573fa1a900b436d7ee0ae (patch)
tree586338270b862a7c44e597828413e918b2cd24a0 /Hsbot/Irc/Plugin.hs
parentCleaned further the bot updates handling. (diff)
downloadhsbot-daea135424857594622573fa1a900b436d7ee0ae.tar.gz
hsbot-daea135424857594622573fa1a900b436d7ee0ae.tar.bz2
hsbot-daea135424857594622573fa1a900b436d7ee0ae.zip
Implemented the clean killing of plugins' threads.
Diffstat (limited to 'Hsbot/Irc/Plugin.hs')
-rw-r--r--Hsbot/Irc/Plugin.hs22
1 files changed, 15 insertions, 7 deletions
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 ()