From 70951d30b5a4f22d00991f6190201933a1dcccfa Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 9 Jan 2020 08:16:10 +0000 Subject: [PATCH] Add example bot that duplicates itself --- src/Haboli/Euphoria/Example.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Haboli/Euphoria/Example.hs b/src/Haboli/Euphoria/Example.hs index 08572f3..b0de6b2 100644 --- a/src/Haboli/Euphoria/Example.hs +++ b/src/Haboli/Euphoria/Example.hs @@ -3,6 +3,7 @@ -- | This module contains a few basic example bots. module Haboli.Euphoria.Example where +import Control.Concurrent import Control.Monad import Control.Monad.IO.Class import Data.Foldable @@ -60,3 +61,15 @@ sendMessagesThreadedBot = forever $ do t6 <- fork $ reply subtree2 "subtree 2.2" for_ [t3, t4, t5, t6] wait reply msg "tree done" + +cloneItselfBot :: Client () () +cloneItselfBot = forever $ do + event <- respondingToPing nextEvent + case event of + EventSnapshot _ -> void $ nick "CloneBot" + EventSend e + | msgContent (sendMessage e) == "!clone" -> do + config <- getConnectionConfig + void $ liftIO $ forkIO $ void $ runClient config cloneItselfBot + | otherwise -> pure () + _ -> pure ()