Archived
1
0
Fork 0

Implemented unregisterCommand.

This commit is contained in:
Julien Dessaux 2010-02-04 20:41:22 +01:00
parent cf68de02be
commit 46d9dd301d
2 changed files with 13 additions and 2 deletions

View file

@ -1,9 +1,11 @@
module Hsbot.Command
( dispatchCommand
, registerCommand
, unregisterCommand
) where
import Control.Monad.State
import qualified Data.List as L
import qualified Data.Map as M
import Data.Maybe
@ -39,14 +41,23 @@ registerCommand cmd pluginName' = do
bot <- get
cmds <- gets botCommands
exists <- pluginExists pluginName'
-- TODO : improve this crap and remove at least one if!
if exists
then
let cmds' = if cmd `M.member` cmds
then cmds
else M.singleton cmd []
-- TODO : remove duplicates ?
newCmds = M.adjust (++ [pluginName']) cmd cmds'
in put $ bot { botCommands = newCmds }
else
traceM $ inColor ("Couldn't register command \"" ++ cmd ++ "\" for plugin \""
++ pluginName' ++ "\" : plugin does not exists") [31]
unregisterCommand :: String -> String -> IrcBot ()
unregisterCommand cmd pluginName' = do
bot <- get
cmds <- gets botCommands
let newCmds = M.adjust (L.delete pluginName') cmd cmds
put $ bot { botCommands = newCmds }

4
TODO
View file

@ -1,7 +1,7 @@
* implement InternalCommands "register command"
* unregister command, add it to internal commands
* implement InternalCommands "register command" and "unregister command"
* kill threads
* unload plugin
* part chan
* restore \r in IRCParser