summaryrefslogtreecommitdiff
path: root/Plugins/Ping.hs
blob: 6102fe4c711758d46b69a5f0350f5ff52f5fcdc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Plugins.Ping
    ( mainPing
    ) 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
    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 ()