summaryrefslogtreecommitdiff
path: root/HsbotIrcBot/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2010-08-20 19:08:13 +0200
committerJulien Dessaux2010-08-20 23:36:00 +0200
commit8bbe88a07879a4c3c6205756135972df33aa9b09 (patch)
treedb17b54190127816b062db1d0ace6350e69e6aab /HsbotIrcBot/Hsbot
parentGreatly improved configuration file handling. (diff)
downloadhsbot-8bbe88a07879a4c3c6205756135972df33aa9b09.tar.gz
hsbot-8bbe88a07879a4c3c6205756135972df33aa9b09.tar.bz2
hsbot-8bbe88a07879a4c3c6205756135972df33aa9b09.zip
Improved message dispatching in core.
Diffstat (limited to '')
-rw-r--r--HsbotIrcBot/Hsbot/Irc/Core.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/HsbotIrcBot/Hsbot/Irc/Core.hs b/HsbotIrcBot/Hsbot/Irc/Core.hs
index 525c3d6..a280549 100644
--- a/HsbotIrcBot/Hsbot/Irc/Core.hs
+++ b/HsbotIrcBot/Hsbot/Irc/Core.hs
@@ -105,26 +105,26 @@ ircBotCore = do
-- | Dispatches an input message
dispatchMessage :: IrcBotMsg -> IrcBot (BotStatus)
dispatchMessage (InIrcMsg inIrcMsg) = do
- config <- gets ircBotConfig
- plugins <- gets ircBotPlugins
- cmds <- gets ircBotCommands
- if (isPluginCommand config)
+ bot <- get
+ let config = ircBotConfig bot
+ plugins = ircBotPlugins bot
+ cmds = ircBotCommands bot
+ if isPluginCommand config
then
- let key = tail . head $ words getMsgContent
+ let getMsgContent = unwords . tail $ ircMsgParameters inIrcMsg
+ key = tail . head $ words getMsgContent
pluginNames = fromMaybe [] $ M.lookup key cmds
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'
else
mapM_ (sendToPlugin (InIrcMsg inIrcMsg) . first) (M.elems plugins)
return BotContinue
where
- isPluginCommand :: IrcConfig -> Bool
- isPluginCommand config =
- and [ ircMsgCommand inIrcMsg == "PRIVMSG"
- , (head getMsgContent) == ircConfigCommandPrefix config ]
- sendRunCommand :: String -> IrcPluginState -> IrcBot ()
- sendRunCommand cmd plugin = sendToPlugin (IntIrcCmd $ IrcCmd "RUN" "CORE" (ircPluginName plugin) cmd inIrcMsg) plugin
- getMsgContent :: String
- getMsgContent = unwords . tail $ ircMsgParameters inIrcMsg
+ isPluginCommand config = and [ ircMsgCommand inIrcMsg == "PRIVMSG", prefix == ircConfigCommandPrefix config ]
+ prefix | length msgWords >= 1 = head . head $ msgWords
+ | otherwise = ' '
+ where
+ msgWords = tail $ ircMsgParameters inIrcMsg
dispatchMessage _ = return (BotContinue)