needles-0.1.0.0: Pokemon Showdown bot library

Copyright(c) Leon Medvinsky, 2015
LicenseGPL-3
Maintainerlmedvinsky@hotmail.com
Stabilityexperimental
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

Needles.Bot.Trigger

Contents

Description

 

Synopsis

Documentation

data MessageInfo Source

The info of a message

Constructors

MessageInfo 

Fields

mType :: MessageType
 
what :: Text
 
who :: Text
 
rank :: Char
 
mRoom :: Text
 
respond :: forall a b. Text -> TriggerAct a b ()
 

data MessageType Source

The type of a message

Constructors

MTChat 
MTPm 
MTRaw 
MTBase 
MTUnknown 

Triggers

data Trigger Source

A trigger. They respond to certain messages by doing things.

data TriggerAct var perma r Source

An effect that a Trigger might produce. var is the type of the runtime variable the trigger uses to store data. perma is the type of the persistent data for this trigger. r is the type of the result of this effect.

Construction

mkTrigger :: (MessageInfo -> Bool) -> (MessageInfo -> TriggerAct a b c) -> a -> Trigger Source

mkTrigger takes a predicate on message types, and a function to create a TriggerAct. The predicate is used to see if a message should be processed by this Trigger, and the second function determines what actually happens when the Trigger is triggered. The third argument is the initial state of the trigger.

mkTrigger_ :: (MessageInfo -> Bool) -> (MessageInfo -> TriggerAct () b c) -> Trigger Source

Version for TriggerActs with no state

Actions

Basic

send :: Text -> TriggerAct a b () Source

Sends the given message to the server.

printLn :: Text -> TriggerAct a b () Source

Prints the given message to the console.

getVar :: TriggerAct a b a Source

Gets the value of the trigger's runtime store.

storeVar :: a -> TriggerAct a b () Source

Stores a value into the trigger's runtime store.

duraGet :: TriggerAct a b b Source

Gets the persistent data for this trigger.

duraStore :: b -> TriggerAct a b () Source

Stores persistent data for this trigger.

Convenience

sendChat :: Text -> Text -> TriggerAct a b () Source

Takes a room and a message, then sends a message to that room

sendPm :: Text -> Text -> TriggerAct a b () Source

Takes a user and a message, sending a pm to that user

command :: Text -> Text -> TriggerAct a b () Source

Executes a command in the given room (empty string means default room) and given command string.

clusterTrigger :: forall a b. [(MessageInfo -> Bool, MessageInfo -> TriggerAct a b ())] -> a -> Trigger Source

Combines multiple predicate and TriggerActions into one big blob that shares runtime state. Second argument is initial state.