Added plugin loading, and the most basic hook capability.
This commit is contained in:
parent
7e89b50bfe
commit
c497b24700
6 changed files with 68 additions and 35 deletions
|
@ -1,35 +1,28 @@
|
|||
module Hsbot.Plugin.Ping
|
||||
( pingId
|
||||
, ping
|
||||
( ping
|
||||
, thePing
|
||||
) where
|
||||
|
||||
import Control.Concurrent.Chan ()
|
||||
import Control.Exception
|
||||
import Control.Monad.State (execStateT, forever)
|
||||
import Control.Monad.State
|
||||
import qualified Network.IRC as IRC
|
||||
import Prelude hiding (catch)
|
||||
|
||||
import Hsbot.Message
|
||||
import Hsbot.Types
|
||||
|
||||
pingId :: PluginId
|
||||
pingId = PluginId
|
||||
ping :: PluginId
|
||||
ping = 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 ()
|
||||
, pluginEp = thePing }
|
||||
|
||||
-- | The IrcPlugin monad main function
|
||||
run :: Plugin IO ()
|
||||
run = forever $ do
|
||||
thePing :: Plugin (Env IO) ()
|
||||
thePing = forever $ do
|
||||
msg <- readMsg
|
||||
eval msg
|
||||
where
|
||||
eval :: Message -> Plugin IO ()
|
||||
eval :: Message -> Plugin (Env IO) ()
|
||||
eval (IncomingMsg msg)
|
||||
| (IRC.msg_command msg) == "PING" = writeMsg . OutgoingMsg . IRC.Message Nothing "PONG" $ IRC.msg_params msg
|
||||
| otherwise = return ()
|
||||
|
|
Reference in a new issue