summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:41:22 +0100
committerJulien Dessaux2010-02-04 20:41:22 +0100
commit46d9dd301dde46b1f0c4d8fe2aea58312cd9caa5 (patch)
tree9928dac9ddfb1745598c45b2338c959a5e157aa2 /Hsbot
parentAdded command registering and dispatching for plugins. (diff)
downloadhsbot-46d9dd301dde46b1f0c4d8fe2aea58312cd9caa5.tar.gz
hsbot-46d9dd301dde46b1f0c4d8fe2aea58312cd9caa5.tar.bz2
hsbot-46d9dd301dde46b1f0c4d8fe2aea58312cd9caa5.zip
Implemented unregisterCommand.
Diffstat (limited to 'Hsbot')
-rw-r--r--Hsbot/Command.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/Hsbot/Command.hs b/Hsbot/Command.hs
index 20e5525..92f304c 100644
--- a/Hsbot/Command.hs
+++ b/Hsbot/Command.hs
@@ -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 }
+