module Rasa.Ext.Cmd
( addCmd
, runCmd
) where
import Rasa.Ext
import Control.Lens
import Data.Map
import Data.Default
import Data.Typeable
data Cmd = Cmd
{ _commands :: Map String (String -> Action ())
} deriving (Typeable)
instance Show Cmd where
show (Cmd cmds) = show (keys cmds)
makeLenses ''Cmd
instance Default Cmd where
def = Cmd
{ _commands=empty
}
addCmd :: String -> (String -> Action ()) -> Action ()
addCmd alias mkEvent = ext.commands.at alias ?= mkEvent
runCmd :: String -> String -> Action ()
runCmd alias args = do
mCmd <- use (ext.commands.at alias)
case mCmd of
Just cmd -> cmd args
Nothing -> return ()