Improved message dispatching in core.
This commit is contained in:
parent
41f442028d
commit
8bbe88a078
2 changed files with 19 additions and 16 deletions
|
@ -105,26 +105,26 @@ ircBotCore = do
|
||||||
-- | Dispatches an input message
|
-- | Dispatches an input message
|
||||||
dispatchMessage :: IrcBotMsg -> IrcBot (BotStatus)
|
dispatchMessage :: IrcBotMsg -> IrcBot (BotStatus)
|
||||||
dispatchMessage (InIrcMsg inIrcMsg) = do
|
dispatchMessage (InIrcMsg inIrcMsg) = do
|
||||||
config <- gets ircBotConfig
|
bot <- get
|
||||||
plugins <- gets ircBotPlugins
|
let config = ircBotConfig bot
|
||||||
cmds <- gets ircBotCommands
|
plugins = ircBotPlugins bot
|
||||||
if (isPluginCommand config)
|
cmds = ircBotCommands bot
|
||||||
|
if isPluginCommand config
|
||||||
then
|
then
|
||||||
let key = tail . head $ words getMsgContent
|
let getMsgContent = unwords . tail $ ircMsgParameters inIrcMsg
|
||||||
|
key = tail . head $ words getMsgContent
|
||||||
pluginNames = fromMaybe [] $ M.lookup key cmds
|
pluginNames = fromMaybe [] $ M.lookup key cmds
|
||||||
plugins' = fromMaybe [] $ mapM (flip M.lookup plugins) pluginNames
|
plugins' = fromMaybe [] $ mapM (flip M.lookup plugins) pluginNames
|
||||||
|
sendRunCommand cmd plugin = sendToPlugin (IntIrcCmd $ IrcCmd "RUN" "CORE" (ircPluginName plugin) cmd inIrcMsg) plugin
|
||||||
in mapM_ (sendRunCommand (tail getMsgContent) . first) plugins'
|
in mapM_ (sendRunCommand (tail getMsgContent) . first) plugins'
|
||||||
else
|
else
|
||||||
mapM_ (sendToPlugin (InIrcMsg inIrcMsg) . first) (M.elems plugins)
|
mapM_ (sendToPlugin (InIrcMsg inIrcMsg) . first) (M.elems plugins)
|
||||||
return BotContinue
|
return BotContinue
|
||||||
where
|
where
|
||||||
isPluginCommand :: IrcConfig -> Bool
|
isPluginCommand config = and [ ircMsgCommand inIrcMsg == "PRIVMSG", prefix == ircConfigCommandPrefix config ]
|
||||||
isPluginCommand config =
|
prefix | length msgWords >= 1 = head . head $ msgWords
|
||||||
and [ ircMsgCommand inIrcMsg == "PRIVMSG"
|
| otherwise = ' '
|
||||||
, (head getMsgContent) == ircConfigCommandPrefix config ]
|
where
|
||||||
sendRunCommand :: String -> IrcPluginState -> IrcBot ()
|
msgWords = tail $ ircMsgParameters inIrcMsg
|
||||||
sendRunCommand cmd plugin = sendToPlugin (IntIrcCmd $ IrcCmd "RUN" "CORE" (ircPluginName plugin) cmd inIrcMsg) plugin
|
|
||||||
getMsgContent :: String
|
|
||||||
getMsgContent = unwords . tail $ ircMsgParameters inIrcMsg
|
|
||||||
dispatchMessage _ = return (BotContinue)
|
dispatchMessage _ = return (BotContinue)
|
||||||
|
|
||||||
|
|
9
TODO
9
TODO
|
@ -1,10 +1,9 @@
|
||||||
:julien!~julien@ogu21.corp PRIVMSG #shbot :@quote graou snif
|
:julien!~julien@ogu21.corp PRIVMSG #shbot :@quote graou snif
|
||||||
|
|
||||||
* Find a way to prevent the socket from being garbage collected, by writing a connection handler for example
|
|
||||||
* Design another way to launch and manage hsbot and it's configuration
|
* Design another way to launch and manage hsbot and it's configuration
|
||||||
* Find a way to handle bot reloading threw exec
|
* Improved configuration file errors display
|
||||||
* Find a way so that not a single message/information would be lost in the case of a reboot
|
|
||||||
|
|
||||||
|
* implement quick quoting for one line quotes
|
||||||
* write the vote system for the quote module
|
* write the vote system for the quote module
|
||||||
* only the quote reporter should be able to edit it
|
* only the quote reporter should be able to edit it
|
||||||
* detect too identical quoting in a raw, or implement quote abort
|
* detect too identical quoting in a raw, or implement quote abort
|
||||||
|
@ -28,3 +27,7 @@
|
||||||
* write a safe reload : try reload before unloading
|
* write a safe reload : try reload before unloading
|
||||||
* remove from Types.hs what can be removed from it
|
* remove from Types.hs what can be removed from it
|
||||||
|
|
||||||
|
* Find a way to handle bot reloading threw exec
|
||||||
|
* Find a way to prevent the socket from being garbage collected, by writing a connection handler for example
|
||||||
|
* Find a way so that not a single message/information would be lost in the case of a reboot
|
||||||
|
|
||||||
|
|
Reference in a new issue