summaryrefslogtreecommitdiff
path: root/Hsbot/Plugin
diff options
context:
space:
mode:
authorJulien Dessaux2011-04-23 13:35:04 +0200
committerJulien Dessaux2011-04-23 13:35:04 +0200
commitd4be110200ba3f3a2f19236ec3c16f980ab458aa (patch)
tree832402a3a83927b0f3242b2306b4f1a79e681de8 /Hsbot/Plugin
parentBegan a big refactoring/rewriting (again) (diff)
downloadhsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.tar.gz
hsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.tar.bz2
hsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.zip
Continue refactoring, worked on the core loop and the plugin infrastructure.
Diffstat (limited to 'Hsbot/Plugin')
-rw-r--r--Hsbot/Plugin/Ping.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/Hsbot/Plugin/Ping.hs b/Hsbot/Plugin/Ping.hs
new file mode 100644
index 0000000..b020359
--- /dev/null
+++ b/Hsbot/Plugin/Ping.hs
@@ -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 ()
+