marvin-0.0.4: A modular bot for slack

Copyright(c) Justus Adam 2016
LicenseBSD3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Marvin

Contents

Description

 

Synopsis

Scripts

data Script a Source #

An abstract type describing a marvin script.

This is basically a collection of event handlers.

Internal structure is exposed for people wanting to extend this.

Constructors

Script [WrappedAction a] ScriptId Config a 

defineScript :: ScriptId -> ScriptDefinition a () -> ScriptInit a Source #

Define a new script for marvin

You need to provide a ScriptId (which can simple be written as a non-empty string). This id is used as the key for the section in the bot config belonging to this script and in logging output.

Roughly equivalent to "module.exports" in hubot.

data ScriptInit a Source #

Initializer for a script. This gets run by the server during startup and creates a Script

data ScriptId Source #

A type, basically a String, which identifies a script to the config and the logging facilities.

Reacting

hear :: Regex -> BotReacting a MessageReactionData () -> ScriptDefinition a () Source #

Whenever any message matches the provided regex this handler gets run.

Equivalent to "robot.hear" in hubot

respond :: Regex -> BotReacting a MessageReactionData () -> ScriptDefinition a () Source #

Runs the handler only if the bot was directly addressed.

Equivalent to "robot.respond" in hubot

customTrigger :: (Event -> Maybe d) -> BotReacting a d () -> ScriptDefinition a () Source #

Extension point for the user

Allows you to handle the raw event yourself. Returning Nothing from the trigger function means you dont want to react to the event. The value returned inside the Just is available in the handler later using getData.

send :: (IsAdapter a, HasMessage m) => String -> BotReacting a m () Source #

Send a message to the channel the triggering message came from.

Equivalent to "robot.send" in hubot

reply :: (IsAdapter a, HasMessage m) => String -> BotReacting a m () Source #

Send a message to the channel the original message came from and address the user that sent the original message.

Equivalent to "robot.reply" in hubot

messageChannel :: (AccessAdapter m, IsAdapter (AdapterT m), IsScript m, MonadIO m) => String -> String -> m () Source #

Send a message to a Channel (by name)

getData :: BotReacting a d d Source #

Obtain the event reaction data.

The type of this data depends on the reacion function used. For instance hear and respond will contain MessageReactionData. The actual contents comes from the event itself and was put together by the trigger.

getMessage :: HasMessage m => BotReacting a m Message Source #

Get the message that triggered this action Includes sender, target channel, as well as the full, untruncated text of the original message

getMatch :: HasMatch m => BotReacting a m Match Source #

Get the results from matching the regular expression.

Equivalent to "msg.match" in hubot.

getUsername :: (AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => User -> m String Source #

Get the username of a registered user.

getChannelName :: (AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel -> m String Source #

Get the human readable name of a channel.

getConfigVal :: (Configured a, HasConfigAccess m) => Name -> m (Maybe a) Source #

Get a value out of the config, returns Nothing if the value didn't exist.

This config is the config for this script. Ergo all config vars registered under the config section for the ScriptId of this script.

The HasConfigAccess Constraint means this function can be used both during script definition and when a handler is run.

requireConfigVal :: (Configured a, HasConfigAccess m) => Name -> m a Source #

Get a value out of the config and fail with an error if the specified key is not found.

This config is the config for this script. Ergo all config vars registered under the config section for the ScriptId of this script.

The HasConfigAccess Constraint means this function can be used both during script definition and when a handler is run.

data BotReacting a d r Source #

Monad for reacting in the bot. Allows use of functions like send, reply and messageChannel as well as any arbitrary IO action using liftIO.

The type parameter d is the accessible data provided by the trigger for this action and can be obtained with getData or other custom functions like getMessage and getMatch which typically depend on a particular type of data in d. For message handlers like hear and respond this would be a regex Match and a Message for instance.

For completeness: a is the adapter type and r is the return type of the monadic computation.

This is also a MonadReader instance, there you can inspect the entire state of this reaction. This is typically only used in internal or utility functions and not necessary for the user. To inspect particular pieces of this state refer to the *Lenses* section.

Instances

Monad (BotReacting a d) Source # 

Methods

(>>=) :: BotReacting a d a -> (a -> BotReacting a d b) -> BotReacting a d b #

(>>) :: BotReacting a d a -> BotReacting a d b -> BotReacting a d b #

return :: a -> BotReacting a d a #

fail :: String -> BotReacting a d a #

Functor (BotReacting a d) Source # 

Methods

fmap :: (a -> b) -> BotReacting a d a -> BotReacting a d b #

(<$) :: a -> BotReacting a d b -> BotReacting a d a #

Applicative (BotReacting a d) Source # 

Methods

pure :: a -> BotReacting a d a #

(<*>) :: BotReacting a d (a -> b) -> BotReacting a d a -> BotReacting a d b #

(*>) :: BotReacting a d a -> BotReacting a d b -> BotReacting a d b #

(<*) :: BotReacting a d a -> BotReacting a d b -> BotReacting a d a #

MonadIO (BotReacting a d) Source # 

Methods

liftIO :: IO a -> BotReacting a d a #

IsScript (BotReacting a b) Source # 
HasConfigAccess (BotReacting a b) Source # 
MonadReader (BotActionState a d) (BotReacting a d) Source # 

Methods

ask :: BotReacting a d (BotActionState a d) #

local :: (BotActionState a d -> BotActionState a d) -> BotReacting a d a -> BotReacting a d a #

reader :: (BotActionState a d -> a) -> BotReacting a d a #

class HasMessage m where Source #

Class which says that there is a way to get to a Message from this type m.

Minimal complete definition

messageLens

class HasMatch m where Source #

Class which says that there is a way to get to a Match from this type m.

Minimal complete definition

matchLens

Advanced actions

extractAction :: BotReacting a () o -> ScriptDefinition a (IO o) Source #

Take an action and produce an IO action with the same effect. Useful for creating actions which can be scheduled to execute a certain time or asynchronous. The idea is that one can conveniently send messages from inside a schedulable action.

extractReaction :: BotReacting a s o -> BotReacting a s (IO o) Source #

Take a reaction and produce an IO action with the same effect. Useful for creating actions which can be scheduled to execute a certain time or asynchronous. The idea is that one can conveniently send messages from inside a schedulable action.

Lenses and internal types

class HasScriptId s a | s -> a where Source #

Minimal complete definition

scriptId

Methods

scriptId :: Lens' s a Source #

class HasConfig s a | s -> a where Source #

Minimal complete definition

config

Methods

config :: Lens' s a Source #

class HasAdapter s a | s -> a where Source #

Minimal complete definition

adapter

Methods

adapter :: Lens' s a Source #

Instances

HasAdapter (Script a0) a0 Source # 

Methods

adapter :: Lens' (Script a0) a0 Source #

HasAdapter (BotActionState a0 d0) a0 Source # 

Methods

adapter :: Lens' (BotActionState a0 d0) a0 Source #

class HasMatchField s a | s -> a where Source #

Minimal complete definition

matchField

Methods

matchField :: Lens' s a Source #

class HasVariable s a | s -> a where Source #

Minimal complete definition

variable

Methods

variable :: Lens' s a Source #

Instances

data BotActionState a d Source #

Read only data available to a handler when the bot reacts to an event.

Constructors

BotActionState ScriptId Config a d 

data MessageReactionData Source #

Payload in the reaction Monad when triggered by a message. Contains a field for the Message and a field for the Match from the Regex.

Both fields are accessible directly via the getMessage and getMatch functions or this data via getData.

class HasActions s a | s -> a where Source #

Minimal complete definition

actions

Methods

actions :: Lens' s a Source #