Archived
1
0
Fork 0

Continue refactoring, worked on the core loop and the plugin infrastructure.

This commit is contained in:
Julien Dessaux 2011-04-23 13:35:04 +02:00
parent ff07633fb8
commit d4be110200
7 changed files with 140 additions and 38 deletions

38
Hsbot/Plugin/Ping.hs Normal file
View file

@ -0,0 +1,38 @@
module Hsbot.Plugin.Ping
( pingId
, ping
) where
import Control.Concurrent.Chan ()
import Control.Exception
import Control.Monad.State (execStateT, forever)
import qualified Network.IRC as IRC
import Prelude hiding (catch)
import Hsbot.Message
import Hsbot.Types
import Hsbot.Utils
pingId :: PluginId
pingId = PluginId
{ pluginName = "ping"
, pluginEp = ping }
-- | The plugin's main entry point
ping :: PluginState -> IO ()
ping state = do
_ <- (execStateT run state) `catch` (\(_ :: AsyncException) -> return state)
return ()
-- | The IrcPlugin monad main function
run :: Plugin IO ()
run = forever $ do
msg <- readMsg
eval msg
where
eval :: Message -> Plugin IO ()
eval (IncomingMsg msg)
| (IRC.msg_command msg) == "PING" = writeMsg . OutgoingMsg . IRC.Message Nothing "PONG" $ IRC.msg_params msg
| otherwise = return ()
eval _ = return ()