Archived
1
0
Fork 0

Some refactoring + cosmetics.

This commit is contained in:
Julien Dessaux 2010-04-25 16:43:01 +02:00
parent 727adadc28
commit b6d119cf5b
13 changed files with 71 additions and 63 deletions

View file

@ -5,7 +5,6 @@ module Plugins.Core
import Control.Concurrent.Chan(Chan)
import Control.Exception
import Control.Monad.State
import Data.Maybe(fromMaybe)
import Prelude hiding (catch)
import Hsbot.IRCPlugin
@ -15,7 +14,7 @@ import Hsbot.Utils
-- | The plugin's main entry point
mainCore :: Chan BotMsg -> Chan BotMsg -> IO ()
mainCore serverChan chan = do
let plugin = PluginInstance "Core" serverChan chan
let plugin = PluginState "Core" serverChan chan
evalStateT (mapM_ sendRegisterCommand ["list", "load", "reload", "unload"]) plugin
plugin' <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
evalStateT (mapM_ sendUnregisterCommand ["list", "load", "reload", "unload"]) plugin'
@ -36,15 +35,15 @@ run = forever $ do
"load" -> loadPlugin $ tail stuff
"reload" -> reloadPlugin $ tail stuff
"unload" -> unloadPlugin $ tail stuff
_ -> lift $ trace $ show intCmd -- TODO : help message
_ -> lift . trace $ show intCmd -- TODO : help message
"ANSWER" -> let stuff = intCmdMsg intCmd
in answerMsg request ("Loaded plugins : " ++ stuff)
_ -> lift $ trace $ show intCmd
_ -> lift . trace $ show intCmd
eval (InputMsg _) = return ()
eval _ = return ()
-- | The list command
listPlugins :: Maybe IrcMsg -> IrcPlugin ()
listPlugins :: IrcMsg -> IrcPlugin ()
listPlugins request = do
sendCommandWithRequest "LIST" "CORE" (unwords []) request

View file

@ -13,7 +13,7 @@ import Hsbot.Types
-- | The plugin's main entry point
mainPing :: Chan BotMsg -> Chan BotMsg -> IO ()
mainPing serverChan chan = do
let plugin = PluginInstance "Ping" serverChan chan
let plugin = PluginState "Ping" serverChan chan
_ <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
return ()

View file

@ -29,9 +29,9 @@ type QuoteBot a = StateT QuoteDB IO a
-- | The plugin's main entry point
mainQuote :: Chan BotMsg -> Chan BotMsg -> IO ()
mainQuote serverChan chan = do
let plugin = PluginInstance "Quote" serverChan chan
let plugin = PluginState "Quote" serverChan chan
evalStateT (mapM_ sendRegisterCommand ["quote"]) plugin
(execStateT run plugin) `catch` (\(ex :: AsyncException) -> return plugin)
_ <- (evalStateT (run quoteBot) plugin) `catch` (\(_ :: AsyncException) -> return quoteBot)
evalStateT (mapM_ sendUnregisterCommand ["quote"]) plugin
-- | The IrcPlugin monad main function