Archived
1
0
Fork 0
This repository has been archived on 2025-03-10. You can view files and clone it, but cannot push or open issues or pull requests.
hsbot/Hsbot/Plugin/Ping.hs
Julien Dessaux 864a364da9 Some API refactoring.
I can't say how I hate the Types.hs thing in Haskell!
2011-05-01 03:28:22 +02:00

37 lines
898 B
Haskell

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
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 ()