module Needles.Bot.Trigger.Examples (
replyTrig
, replyPmTrig
, simpleStateTrig
, stateTrig
) where
import Data.Text (Text, append)
import qualified Data.Text as T
import Needles.Bot.Trigger
replyTrig :: Trigger
replyTrig = mkTrigger replyTest replyAct ()
replyTest :: MessageInfo -> Bool
replyTest mi = mType mi == MTChat && (".replychat" == what mi)
replyAct :: MessageInfo -> TriggerAct a b ()
replyAct mi = respond mi message
where message = "Hi " `append` who mi `append` ", this is an example message."
replyPmTrig :: Trigger
replyPmTrig = mkTrigger replyPmTest replyPmAct ()
replyPmTest :: MessageInfo -> Bool
replyPmTest mi = (mType mi == MTChat || mType mi == MTPm) && (".replypm" == what mi)
replyPmAct :: MessageInfo -> TriggerAct a b ()
replyPmAct mi = sendPm (who mi) "This is an example pm."
simpleStateTrig :: Trigger
simpleStateTrig = mkTrigger simpleStateTest simpleStateAct "Not Set"
simpleStateTest :: MessageInfo -> Bool
simpleStateTest mi = (mType mi == MTChat || mType mi == MTPm) &&
(".sSimple " `T.isPrefixOf` what mi)
simpleStateAct :: MessageInfo -> TriggerAct Text b ()
simpleStateAct mi = do
prev <- getVar
respond mi ("Previous data: " `append` prev)
storeVar (T.drop 9 $ what mi)
statePutTest :: MessageInfo -> Bool
statePutTest mi = (mType mi == MTChat || mType mi == MTPm) &&
(".sPut " `T.isPrefixOf` what mi)
statePutAct :: MessageInfo -> TriggerAct Text b ()
statePutAct mi = do
storeVar (T.drop 6 $ what mi)
testdata <- getVar
respond mi ("Data stored: " `append` testdata)
stateGetTest :: MessageInfo -> Bool
stateGetTest mi = (mType mi == MTChat || mType mi == MTPm) &&
(".sGet" `T.isPrefixOf` what mi)
stateGetAct :: MessageInfo -> TriggerAct Text b ()
stateGetAct mi = do
datas <- getVar
respond mi ("Data: " `append` datas)
stateTrig :: Trigger
stateTrig = clusterTrigger [(statePutTest, statePutAct), (stateGetTest, stateGetAct)] ""