From fd8d5faf5f4ab085b01316e15403779ca30cf3f9 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 4 Feb 2010 21:05:37 +0100 Subject: Began a complete rewrite of command and plugin management. Wrote a command routing statement, added an IrcPlugin monad. --- Plugins/Ping.hs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'Plugins/Ping.hs') 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 () -- cgit v1.2.3