summaryrefslogtreecommitdiff
path: root/Hsbot/Irc/Plugin
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-24 22:46:20 +0200
committerJulien Dessaux2010-05-24 22:46:20 +0200
commita12e4927728c9907537b221257c5e2914f5f1c48 (patch)
tree8b8f2dcaa3e796e53767531d654c7e437437ff05 /Hsbot/Irc/Plugin
parentCleaned the definition of irc plugins' data structure. (diff)
downloadhsbot-a12e4927728c9907537b221257c5e2914f5f1c48.tar.gz
hsbot-a12e4927728c9907537b221257c5e2914f5f1c48.tar.bz2
hsbot-a12e4927728c9907537b221257c5e2914f5f1c48.zip
Implemented ircbot update messages.
Diffstat (limited to '')
-rw-r--r--Hsbot/Irc/Plugin.hs32
1 files changed, 20 insertions, 12 deletions
diff --git a/Hsbot/Irc/Plugin.hs b/Hsbot/Irc/Plugin.hs
index 3e6bef0..d972db2 100644
--- a/Hsbot/Irc/Plugin.hs
+++ b/Hsbot/Irc/Plugin.hs
@@ -5,7 +5,7 @@ module Hsbot.Irc.Plugin
, loadIrcPlugin
, sendToPlugin
, spawnIrcPlugins
- , unloadPlugin
+ , unloadIrcPlugin
) where
import Control.Concurrent
@@ -45,16 +45,20 @@ loadIrcPlugin pluginName = do
"Ping" -> ircBotPluginPing
"Quote" -> ircBotPluginQuote
_ -> ircBotPluginDummy
- let oldPlugins = ircBotPlugins ircbot
+ let oldPlugins = ircBotPlugins ircbot
+ oldResumeData = ircBotResumeData ircbot
-- We check for unicity
case M.lookup pluginName oldPlugins of
Just _ -> return ()
Nothing -> do
threadId <- liftIO $ forkIO (entryPoint pluginChan masterChan)
- let plugin = IrcPluginState { ircPluginName = pluginName
- , ircPluginChan = pluginChan
- , ircPluginMasterChan = masterChan }
- put $ ircbot { ircBotPlugins = M.insert pluginName (plugin, threadId) oldPlugins }
+ let plugin = IrcPluginState { ircPluginName = pluginName
+ , ircPluginChan = pluginChan
+ , ircPluginMasterChan = masterChan }
+ newPlugins = M.insert pluginName (plugin, threadId) oldPlugins
+ newResumeData = M.insert "PLUGINS" (show $ M.keys newPlugins) oldResumeData
+ put $ ircbot { ircBotPlugins = newPlugins
+ , ircBotResumeData = newResumeData }
-- | Sends a list of loaded plugins
listPlugins :: IrcMsg -> String -> IrcBot ()
@@ -66,14 +70,18 @@ listPlugins originalRequest dest = do
Nothing -> return ()
-- | Unloads a plugin
-unloadPlugin :: String -> IrcBot ()
-unloadPlugin name = do
- bot <- get
- let oldPlugins = ircBotPlugins bot
+unloadIrcPlugin :: String -> IrcBot ()
+unloadIrcPlugin name = do
+ ircbot <- get
+ let oldPlugins = ircBotPlugins ircbot
+ oldResumeData = ircBotResumeData ircbot
+ -- We check if the plugin exists
case M.lookup name oldPlugins of
Just (_, threadId) -> do
- let newPlugins = M.delete name oldPlugins
+ let newPlugins = M.delete name oldPlugins
+ newResumeData = M.insert "PLUGINS" (show $ M.keys newPlugins) oldResumeData
liftIO $ throwTo threadId UserInterrupt
- put $ bot { ircBotPlugins = newPlugins }
+ put $ ircbot { ircBotPlugins = newPlugins
+ , ircBotResumeData = newResumeData }
Nothing -> return ()