Archived
1
0
Fork 0

Wrote the list plugin command.

This commit is contained in:
Julien Dessaux 2010-04-22 00:05:35 +02:00
parent 50b21c21ee
commit d922240e9a
6 changed files with 40 additions and 15 deletions

View file

@ -76,7 +76,9 @@ processInternalCommand _ = return ()
processCoreCommand :: IntCmd -> IrcBot ()
processCoreCommand intCmd = do
let command' = intCmdCmd intCmd
originalRequest = intCmdBotMsg intCmd
case command' of
"LIST" -> listPlugins originalRequest (intCmdFrom intCmd)
"LOAD" -> traceM $ inColor "hsbot has been compiled in static mode." [31]
"UNLOAD" -> unloadPlugin $ intCmdMsg intCmd
"REGISTER" -> registerCommand (intCmdMsg intCmd) (intCmdFrom intCmd)

View file

@ -18,8 +18,8 @@ pMsg = do
pfx <- optionMaybe pPrefix
cmd <- pCommand
params <- many (char ' ' >> (pLongParam <|> pShortParam))
--char '\r'
eof
char '\r'
--eof
return $ IrcMsg pfx cmd params
pPrefix :: ParsecT String u Identity [Char]

View file

@ -1,6 +1,7 @@
module Hsbot.IRCPlugin
( readMsg
, sendCommand
, sendCommandWithRequest
, sendRegisterCommand
, sendUnregisterCommand
, writeMsg
@ -25,10 +26,13 @@ writeMsg botMsg = do
-- | Commands management
sendCommand :: String -> String -> String -> IrcPlugin ()
sendCommand cmd to params = do
sendCommand cmd to params = sendCommandWithRequest cmd to params Nothing
sendCommandWithRequest :: String -> String -> String -> Maybe IrcMsg -> IrcPlugin ()
sendCommandWithRequest cmd to params originalRequest = do
serverChan <- gets instanceServerChan
from <- gets instanceName
liftIO $ writeChan serverChan $ InternalCmd $ IntCmd cmd from to params Nothing
liftIO $ writeChan serverChan $ InternalCmd $ IntCmd cmd from to params originalRequest
sendRegisterCommand :: String -> IrcPlugin ()
sendRegisterCommand cmd = sendCommand "REGISTER" "CORE" cmd

View file

@ -1,5 +1,6 @@
module Hsbot.Plugin
( loadPlugin
( listPlugins
, loadPlugin
, sendToPlugin
, unloadPlugin
) where
@ -31,6 +32,15 @@ effectivelyLoadPlugin name entryPoint serverChan = do
threadId <- forkIO $ entryPoint serverChan chan
return $ Plugin name threadId chan
-- | Sends a list of loaded plugins
listPlugins :: Maybe IrcMsg -> String -> IrcBot ()
listPlugins originalRequest dest = do
plugins <- gets botPlugins
let listing = unwords $ M.keys plugins
case M.lookup dest plugins of
Just plugin -> sendToPlugin (InternalCmd $ IntCmd "ANSWER" "CORE" dest listing originalRequest) plugin
Nothing -> return ()
-- | Unloads a plugin
unloadPlugin :: String -> IrcBot ()
unloadPlugin name = do