diff options
author | Julien Dessaux | 2011-04-13 20:15:55 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-04-13 20:15:55 +0200 |
commit | ff07633fb8f81577ffec409cbf0a3c7361990f6c (patch) | |
tree | 5021a2e13f878c6b29ad3ec835f694d0726b7e9c /HsbotIrcBot/Hsbot/Irc/Command.hs | |
parent | Regressed from parsec3 to parsec2 to solve a cabal install weird dependency p... (diff) | |
download | hsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.tar.gz hsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.tar.bz2 hsbot-ff07633fb8f81577ffec409cbf0a3c7361990f6c.zip |
Began a big refactoring/rewriting (again)
Diffstat (limited to 'HsbotIrcBot/Hsbot/Irc/Command.hs')
-rw-r--r-- | HsbotIrcBot/Hsbot/Irc/Command.hs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/HsbotIrcBot/Hsbot/Irc/Command.hs b/HsbotIrcBot/Hsbot/Irc/Command.hs deleted file mode 100644 index 1b913e2..0000000 --- a/HsbotIrcBot/Hsbot/Irc/Command.hs +++ /dev/null @@ -1,63 +0,0 @@ -module Hsbot.Irc.Command - ( processInternalCommand - , registerCommand - , unregisterCommand - ) where - -import Control.Monad.State -import qualified Data.List as L -import qualified Data.Map as M -import Data.Maybe - -import Hsbot.Irc.Message -import Hsbot.Irc.Plugin -import Hsbot.Irc.Types - --- | Registers a plugin's command -registerCommand :: String -> String -> IrcBot () -registerCommand cmd pluginName' = do - ircBot <- get - let cmds = ircBotCommands ircBot - plugins = ircBotPlugins ircBot - case M.lookup pluginName' plugins of - Just _ -> let pluginNames = pluginName' : fromMaybe [] (M.lookup cmd cmds) -- TODO : remove/check for duplicates ? - newCmds = M.insert cmd pluginNames cmds - in put $ ircBot { ircBotCommands = newCmds } - Nothing -> return () - --- | Unregisters a plugin's command -unregisterCommand :: String -> String -> IrcBot () -unregisterCommand cmd pluginName' = do - ircBot <- get - let cmds = ircBotCommands ircBot - newCmds = M.adjust (L.delete pluginName') cmd cmds - put $ ircBot { ircBotCommands = newCmds } - --- | Processes an internal command -processInternalCommand :: IrcBotMsg -> IrcBot (BotStatus) -processInternalCommand (IntIrcCmd ircCmd) - | ircCmdTo ircCmd == "CORE" = processCoreCommand ircCmd - | otherwise = do - plugins <- gets ircBotPlugins - case M.lookup (ircCmdTo ircCmd) plugins of - Just (plugin, _, _) -> sendToPlugin (IntIrcCmd ircCmd) plugin - Nothing -> return () - return BotContinue -processInternalCommand _ = return (BotContinue) - --- | Processes a core command -processCoreCommand :: IrcCmd -> IrcBot (BotStatus) -processCoreCommand ircCmd = do - let command' = ircCmdCmd ircCmd - originalRequest = ircCmdBotMsg ircCmd - case command' of - "LIST" -> listPlugins originalRequest (ircCmdFrom ircCmd) - "LOAD" -> loadIrcPlugin $ ircCmdMsg ircCmd - "REGISTER" -> registerCommand (ircCmdMsg ircCmd) (ircCmdFrom ircCmd) - "UNLOAD" -> unloadIrcPlugin $ ircCmdMsg ircCmd - "UNREGISTER" -> unregisterCommand (ircCmdMsg ircCmd) (ircCmdFrom ircCmd) - _ -> return () - if command' == "REBOOT" - then return BotReboot - else return BotContinue - |