| Copyright | (c) Justus Adam 2016 |
|---|---|
| License | BSD3 |
| Maintainer | dev@justus.science |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Marvin
Description
- data Script a = Script [WrappedAction a] ScriptId Config a
- defineScript :: ScriptId -> ScriptDefinition a () -> ScriptInit a
- data ScriptInit a
- data ScriptId
- data ScriptDefinition a r
- class IsAdapter a
- hear :: Regex -> BotReacting a MessageReactionData () -> ScriptDefinition a ()
- respond :: Regex -> BotReacting a MessageReactionData () -> ScriptDefinition a ()
- customTrigger :: (Event -> Maybe d) -> BotReacting a d () -> ScriptDefinition a ()
- send :: (IsAdapter a, HasMessage m) => String -> BotReacting a m ()
- reply :: (IsAdapter a, HasMessage m) => String -> BotReacting a m ()
- messageChannel :: (AccessAdapter m, IsAdapter (AdapterT m), IsScript m, MonadIO m) => String -> String -> m ()
- getData :: BotReacting a d d
- getMessage :: HasMessage m => BotReacting a m Message
- getMatch :: HasMatch m => BotReacting a m Match
- getUsername :: (AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => User -> m String
- getChannelName :: (AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel -> m String
- data Message = Message {}
- data User
- data Channel
- getConfigVal :: (Configured a, HasConfigAccess m) => Name -> m (Maybe a)
- requireConfigVal :: (Configured a, HasConfigAccess m) => Name -> m a
- data BotReacting a d r
- class HasMessage m where
- class HasMatch m where
- extractAction :: BotReacting a () o -> ScriptDefinition a (IO o)
- extractReaction :: BotReacting a s o -> BotReacting a s (IO o)
- class HasScriptId s a | s -> a where
- class HasConfig s a | s -> a where
- class HasAdapter s a | s -> a where
- class HasMessageField s a | s -> a where
- class HasMatchField s a | s -> a where
- class HasVariable s a | s -> a where
- data BotActionState a d = BotActionState ScriptId Config a d
- data MessageReactionData = MessageReactionData Message Match
- class HasActions s a | s -> a where
Scripts
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.
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
A type, basically a String, which identifies a script to the config and the logging facilities.
data ScriptDefinition a r Source #
Instances
Minimal complete definition
adapterId, messageChannel, runWithAdapter, getUsername, getChannelName, resolveChannel
Instances
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 #
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.
Constructors
| Message | |
Instances
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 # | |
| Functor (BotReacting a d) Source # | |
| Applicative (BotReacting a d) Source # | |
| MonadIO (BotReacting a d) Source # | |
| IsScript (BotReacting a b) Source # | |
| HasConfigAccess (BotReacting a b) Source # | |
| MonadReader (BotActionState a d) (BotReacting a d) Source # | |
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
Methods
messageLens :: Lens' m Message Source #
Instances
| HasMessageField m Message => HasMessage m Source # | |
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
Instances
| HasMatchField m Match => HasMatch m Source # | |
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
Instances
| HasScriptId (Script a0) ScriptId Source # | |
| HasScriptId (BotActionState a0 d0) ScriptId Source # | |
class HasAdapter s a | s -> a where Source #
Minimal complete definition
Instances
| HasAdapter (Script a0) a0 Source # | |
| HasAdapter (BotActionState a0 d0) a0 Source # | |
class HasMessageField s a | s -> a where Source #
Minimal complete definition
Methods
messageField :: Lens' s a Source #
Instances
class HasMatchField s a | s -> a where Source #
Minimal complete definition
Methods
matchField :: Lens' s a Source #
Instances
class HasVariable s a | s -> a where Source #
Minimal complete definition
Instances
| HasVariable (BotActionState a0 d0) d0 Source # | |
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 |
Instances
| HasScriptId (BotActionState a0 d0) ScriptId Source # | |
| HasVariable (BotActionState a0 d0) d0 Source # | |
| HasConfig (BotActionState a0 d0) Config Source # | |
| HasAdapter (BotActionState a0 d0) a0 Source # | |
| MonadReader (BotActionState a d) (BotReacting a d) Source # | |
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.
Constructors
| MessageReactionData Message Match |