Implement some botrulez

This commit is contained in:
Joscha 2020-04-08 18:32:48 +00:00
parent 9df9280f5f
commit 15cd6724d2
5 changed files with 94 additions and 13 deletions

View file

@ -8,14 +8,18 @@ module Haboli.Euphoria.ExampleBot
) where
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.State
import qualified Data.Text as T
import Data.Time
import Haboli.Euphoria
import Haboli.Euphoria.Botrulez
newtype BotState = BotState
{ botListing :: Listing
data BotState = BotState
{ botStartTime :: UTCTime
, botListing :: Listing
} deriving (Show)
type Bot = StateT BotState (Client T.Text)
@ -26,23 +30,26 @@ type Bot = StateT BotState (Client T.Text)
-- > runClient defaultConfig $ exampleBot Nothing
exampleBot :: Maybe T.Text -> Client T.Text ()
exampleBot mPasswd = do
startTime <- liftIO getCurrentTime
initialEvents <- untilConnected $
respondingToBounce mPasswd $
respondingToPing nextEvent
listing <- preferNick "ExampleBot" $ newListing initialEvents
void $ runStateT botMain $ BotState listing
void $ runStateT botMain $ BotState startTime listing
botMain :: Bot ()
botMain = forever $ do
s <- get
let name = svNick $ self $ botListing s
lift $ respondingToCommands
[ cmdGeneral "ping" $ \msg -> void $ reply msg "Pong!"
, cmdSpecific "ping" name $ \msg -> void $ reply msg "Pong!"
, cmdSpecific "help" name $ \msg ->
void $ reply msg "I am an example bot for https://github.com/Garmelon/haboli/."
, cmdSpecific "kill" name $ \msg -> do
void $ reply msg "/me dies"
throw $ "I was killed by " <> svNick (msgSender msg)
[ botrulezPingGeneral
, botrulezPingSpecific name
, botrulezHelpSpecific name "I am an example bot for https://github.com/Garmelon/haboli/."
, botrulezUptimeSpecific name $ botStartTime s
, botrulezKillSpecific name
, cmdGeneral "hello" $ \msg ->
void $ reply msg $ "Hi there, " <> nickMention (svNick $ msgSender msg) <> "!"
, cmdSpecific "hug" name $ \msg ->
void $ reply msg "/me hugs back"
] $ respondingToPing nextEvent