diff options
author | Julien Dessaux | 2010-02-04 21:05:37 +0100 |
---|---|---|
committer | Julien Dessaux | 2010-02-04 21:05:37 +0100 |
commit | fd8d5faf5f4ab085b01316e15403779ca30cf3f9 (patch) | |
tree | 83dfae790dcb184d651567f06929fc69338733a9 /Plugins/Ping.hs | |
parent | Fixed some types' functions. (diff) | |
download | hsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.tar.gz hsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.tar.bz2 hsbot-fd8d5faf5f4ab085b01316e15403779ca30cf3f9.zip |
Began a complete rewrite of command and plugin management.
Wrote a command routing statement, added an IrcPlugin monad.
Diffstat (limited to 'Plugins/Ping.hs')
-rw-r--r-- | Plugins/Ping.hs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Plugins/Ping.hs b/Plugins/Ping.hs index 46351aa..6102fe4 100644 --- a/Plugins/Ping.hs +++ b/Plugins/Ping.hs @@ -3,20 +3,27 @@ module Plugins.Ping ) where import Control.Concurrent.Chan +import Control.Monad.State +import Hsbot.IRCPlugin import Hsbot.Types +-- | The plugin's main entry point mainPing :: Chan BotMsg -> Chan BotMsg -> IO () mainPing serverChan chan = do - loop - where - loop = do - input <- readChan chan - eval input - loop - eval :: BotMsg -> IO () - eval (InputMsg msg) - | (command msg) == "PING" = writeChan serverChan $ OutputMsg $ IrcMsg Nothing "PONG" (parameters msg) - | otherwise = return () - eval _ = return () + let plugin = PluginInstance "Ping" serverChan chan + (runStateT run plugin) `catch` (const $ return ((), plugin)) + return () + +-- | The IrcPlugin monad main function +run :: IrcPlugin () +run = forever $ do + msg <- readMsg + eval msg + where + eval :: BotMsg -> IrcPlugin () + eval (InputMsg msg) + | (command msg) == "PING" = writeMsg $ OutputMsg $ IrcMsg Nothing "PONG" (parameters msg) + | otherwise = return () + eval _ = return () |