Yogurt-0.4: A MUD client library

Network.Yogurt.Utils

Contents

Description

Convenience functions on top of Yogurt.Mud.

Synopsis

Hook derivatives

mkTrigger :: Pattern -> Mud a -> Mud HookSource

Creates a hook that watches messages headed to the terminal. When fired, the message is passed on to the terminal and the action is executed.

mkTriggerOnce :: Pattern -> Mud a -> Mud HookSource

Like mkTrigger, but fires at most once.

triggerOneOf :: [(Pattern, Mud ())] -> Mud ()Source

For each pair (pattern, action) a hook is installed. As soon as one of the hooks fires, the hooks are removed and the corresponding action is executed.

mkAlias :: String -> String -> Mud HookSource

mkAlias command subst creates a hook that watches messages headed to the remote MUD. If the message is or starts with the word command, the command is replaced by subst before being sent to the MUD.

mkArgAlias :: String -> ([String] -> String) -> Mud HookSource

Like mkAlias, mkArgAlias command subst creates a hook that watches messages headed to the remote MUD. But here the whole message is substituted instead of just the first command word, and the substitution depends on the command's arguments.

mkCommand :: String -> Mud a -> Mud HookSource

Like mkAlias, but instead of substituting the command, a program is executed. The command's arguments are available as group 1.

Timers

data Timer Source

The abstract Timer type.

type Interval = IntSource

Interval in milliseconds.

mkTimer :: Interval -> Mud a -> Mud TimerSource

mkTimer interval prog creates a timer that executes prog every interval milliseconds.

mkTimerOnce :: Interval -> Mud a -> Mud TimerSource

Creates a timer that fires only once.

rmTimer :: Timer -> Mud ()Source

Disables the timer.

isTimerActive :: Timer -> Mud BoolSource

Checks whether a timer is active. A timer is deactivated by rmTimer.

Sending messages

receive :: String -> Mud ()Source

Sends a message to the terminal, triggering hooks.

sendln :: String -> Mud ()Source

Sends a message appended with a newline character to the MUD, triggering hooks.

echo :: String -> Mud ()Source

Sends a message to the terminal, without triggering hooks.

echoln :: String -> Mud ()Source

Sends a message appended with a newline character to the terminal, without triggering hooks.

echorln :: String -> Mud ()Source

Sends a message appended with a newline character to the MUD, without triggering hooks.

bell :: Mud ()Source

Sends a bell character to the terminal.

Logging

startLogging :: String -> Mud LoggerSource

startLogging name causes all messages to be logged in a file called name-yyyymmdd-hhmm.log. The used hooks have priority 100.

stopLogging :: Logger -> Mud ()Source

Stops the logger.

Triggering multiple hooks

By default, when a message causes a hook to fire, the message is stopped and discarded unless the hook decides otherwise. These functions provide ways to give other hooks with lower priorities a chance to fire as well.

matchMore :: Mud ()Source

When called from a hook body, gives hooks that haven't been considered yet a chance to match on the currently triggering message. If no other hooks match, the message is sent on to its destination. Useful if you want to build a hook that only has a side-effect and doesn't want to directly affect the other active hooks.

matchMoreOn :: String -> Mud ()Source

Like matchMore, but allows specification of the message that is passed on.

matchMoreOn' :: String -> Mud ()Source

Like matchMoreOn, but also makes the currently firing hook eligible for firing again.