Implemented unregisterCommand.
This commit is contained in:
parent
cf68de02be
commit
46d9dd301d
2 changed files with 13 additions and 2 deletions
|
@ -1,9 +1,11 @@
|
||||||
module Hsbot.Command
|
module Hsbot.Command
|
||||||
( dispatchCommand
|
( dispatchCommand
|
||||||
, registerCommand
|
, registerCommand
|
||||||
|
, unregisterCommand
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
import qualified Data.List as L
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
|
@ -39,14 +41,23 @@ registerCommand cmd pluginName' = do
|
||||||
bot <- get
|
bot <- get
|
||||||
cmds <- gets botCommands
|
cmds <- gets botCommands
|
||||||
exists <- pluginExists pluginName'
|
exists <- pluginExists pluginName'
|
||||||
|
-- TODO : improve this crap and remove at least one if!
|
||||||
if exists
|
if exists
|
||||||
then
|
then
|
||||||
let cmds' = if cmd `M.member` cmds
|
let cmds' = if cmd `M.member` cmds
|
||||||
then cmds
|
then cmds
|
||||||
else M.singleton cmd []
|
else M.singleton cmd []
|
||||||
|
-- TODO : remove duplicates ?
|
||||||
newCmds = M.adjust (++ [pluginName']) cmd cmds'
|
newCmds = M.adjust (++ [pluginName']) cmd cmds'
|
||||||
in put $ bot { botCommands = newCmds }
|
in put $ bot { botCommands = newCmds }
|
||||||
else
|
else
|
||||||
traceM $ inColor ("Couldn't register command \"" ++ cmd ++ "\" for plugin \""
|
traceM $ inColor ("Couldn't register command \"" ++ cmd ++ "\" for plugin \""
|
||||||
++ pluginName' ++ "\" : plugin does not exists") [31]
|
++ 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
4
TODO
|
@ -1,7 +1,7 @@
|
||||||
* implement InternalCommands "register command"
|
* implement InternalCommands "register command" and "unregister command"
|
||||||
* unregister command, add it to internal commands
|
|
||||||
* kill threads
|
* kill threads
|
||||||
* unload plugin
|
* unload plugin
|
||||||
|
* part chan
|
||||||
|
|
||||||
* restore \r in IRCParser
|
* restore \r in IRCParser
|
||||||
|
|
||||||
|
|
Reference in a new issue