diff options
author | Julien Dessaux | 2010-02-08 00:11:46 +0100 |
---|---|---|
committer | Julien Dessaux | 2010-02-08 00:16:02 +0100 |
commit | bfc06f1ff188c9d7faa817034363a27e34eae15a (patch) | |
tree | b775c8401982544b273da8a22e1c28854eac58d5 /Plugins/Core.hs | |
parent | Continue rewriting, found a problem in the way I kill plugins. (diff) | |
download | hsbot-bfc06f1ff188c9d7faa817034363a27e34eae15a.tar.gz hsbot-bfc06f1ff188c9d7faa817034363a27e34eae15a.tar.bz2 hsbot-bfc06f1ff188c9d7faa817034363a27e34eae15a.zip |
Fixed the clean killing of plugin's threads, fixed exception management and cleaned plugins' main functions.
Diffstat (limited to 'Plugins/Core.hs')
-rw-r--r-- | Plugins/Core.hs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/Plugins/Core.hs b/Plugins/Core.hs index 99abfc0..b05e9aa 100644 --- a/Plugins/Core.hs +++ b/Plugins/Core.hs @@ -3,7 +3,9 @@ module Plugins.Core ) where import Control.Concurrent.Chan +import Control.Exception import Control.Monad.State +import Prelude hiding (catch) import Hsbot.IRCPlugin import Hsbot.Types @@ -13,18 +15,13 @@ import Hsbot.Utils mainCore :: Chan BotMsg -> Chan BotMsg -> IO () mainCore serverChan chan = do let plugin = PluginInstance "Core" serverChan chan - (runStateT run plugin) `catch` (const $ return ((), plugin)) - return () + evalStateT (mapM_ sendRegisterCommand ["list", "load", "reload", "unload"]) plugin + (execStateT run plugin) `catch` (\(ex :: AsyncException) -> return plugin) + evalStateT (mapM_ sendUnregisterCommand ["list", "load", "reload", "unload"]) plugin -- | The IrcPlugin monad main function run :: IrcPlugin () -run = do - mapM_ sendRegisterCommand ["load", "reload", "unload"] - runPlugin - mapM_ sendUnregisterCommand ["load", "reload", "unload"] - -runPlugin :: IrcPlugin () -runPlugin = forever $ do +run = forever $ do msg <- readMsg eval msg where |