Safe Haskell | None |
---|---|
Language | Haskell2010 |
- defineScript :: ScriptId -> ScriptDefinition a () -> ScriptInit a
- hear :: Regex -> BotReacting a (User' a, Channel' a, Match, Message, TimeStamp) () -> ScriptDefinition a ()
- respond :: Regex -> BotReacting a (User' a, Channel' a, Match, Message, TimeStamp) () -> ScriptDefinition a ()
- topic :: BotReacting a (User' a, Channel' a, Topic, TimeStamp) () -> ScriptDefinition a ()
- topicIn :: Text -> BotReacting a (User' a, Channel' a, Topic, TimeStamp) () -> ScriptDefinition a ()
- enter :: BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a ()
- exit :: BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a ()
- enterIn :: Text -> BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a ()
- exitFrom :: Text -> BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a ()
- customTrigger :: (Event a -> Maybe d) -> BotReacting a d () -> ScriptDefinition a ()
- send :: (IsAdapter a, Get d (Channel' a)) => Text -> BotReacting a d ()
- reply :: (IsAdapter a, Get d (User' a), Get d (Channel' a)) => Text -> BotReacting a d ()
- messageChannel :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadLoggerIO m) => Text -> Text -> m ()
- messageChannel' :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel (AdapterT m) -> Text -> m ()
- getData :: BotReacting a d d
- getUser :: forall m a. Get m (User' a) => BotReacting a m (User a)
- getMatch :: Get m Match => BotReacting a m Match
- getMessage :: Get m Message => BotReacting a m Message
- getChannel :: forall a m. Get m (Channel' a) => BotReacting a m (Channel a)
- getTopic :: Get m Topic => BotReacting a m Topic
- getBotName :: HasConfigAccess m => m Text
- getChannelName :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel (AdapterT m) -> m Text
- resolveChannel :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Text -> m (Maybe (Channel (AdapterT m)))
- getUsername :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => User (AdapterT m) -> m Text
- getConfigVal :: (Configured a, HasConfigAccess m) => Name -> m (Maybe a)
- requireConfigVal :: (Configured a, HasConfigAccess m) => Name -> m a
- getAppConfigVal :: (Configured a, HasConfigAccess m) => Name -> m (Maybe a)
- requireAppConfigVal :: (Configured a, HasConfigAccess m) => Name -> m a
- getConfig :: HasConfigAccess m => m Config
- getConfigInternal :: HasConfigAccess m => m Config
- type Topic = Text
- extractAction :: BotReacting a () o -> ScriptDefinition a (IO o)
- extractReaction :: BotReacting a s o -> BotReacting a s (IO o)
- defaultBotName :: Text
- runDefinitions :: ScriptId -> ScriptDefinition a () -> a -> Config -> RunnerM (Script a)
- data BotActionState a d = BotActionState ScriptId Config a d
- newtype BotReacting a d r = BotReacting {
- runReaction :: ReaderT (BotActionState a d) RunnerM r
- data Script a = Script (Handlers a) ScriptId Config a
- newtype ScriptDefinition a r = ScriptDefinition {}
- newtype ScriptInit a = ScriptInit (ScriptId, a -> Config -> RunnerM (Script a))
- newtype ScriptId = ScriptId {}
- data Handlers a = Handlers (Vector (Regex, (User' a, Channel' a, Match, Message, TimeStamp) -> RunnerM ())) (Vector (Regex, (User' a, Channel' a, Match, Message, TimeStamp) -> RunnerM ())) (Vector (Event a -> Maybe (RunnerM ()))) (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ())) (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ())) (Vector ((User' a, Channel' a, Topic, TimeStamp) -> RunnerM ())) (HashMap Text (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ()))) (HashMap Text (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ()))) (HashMap Text (Vector ((User' a, Channel' a, Topic, TimeStamp) -> RunnerM ())))
- class HasActions s a | s -> a where
- class HasHears s a | s -> a where
- class HasResponds s a | s -> a where
- class HasJoins s a | s -> a where
- class HasCustoms s a | s -> a where
- class HasJoinsIn s a | s -> a where
- class HasLeaves s a | s -> a where
- class HasLeavesFrom s a | s -> a where
- class HasTopicChange s a | s -> a where
- class HasTopicChangeIn s a | s -> a where
- class AccessAdapter m where
- type AdapterT m
- class Get a b where
Exposed API
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.
Reacting
hear :: Regex -> BotReacting a (User' a, Channel' a, Match, Message, TimeStamp) () -> ScriptDefinition a () Source #
Whenever any message matches the provided regex this handler gets run.
Equivalent to "robot.hear" in hubot
respond :: Regex -> BotReacting a (User' a, Channel' a, Match, Message, TimeStamp) () -> ScriptDefinition a () Source #
Runs the handler only if the bot was directly addressed.
Equivalent to "robot.respond" in hubot
topic :: BotReacting a (User' a, Channel' a, Topic, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs when the topic in any channel the bot is subscribed to changes.
The payload contains the new topic and the channel in which it was set.
topicIn :: Text -> BotReacting a (User' a, Channel' a, Topic, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs when the topic in the specified channel is changed, provided the bot is subscribed to the channel in question.
The argument is the human readable channel name.
enter :: BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs whenever a user enters any channel (which the bot is subscribed to)
The payload contains the entering user and the channel which was entered.
exit :: BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs whenever a user exits any channel (which the bot is subscribed to)
The payload contains the exiting user and the channel which was exited.
enterIn :: Text -> BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs whenever a user enters the specified channel.
The argument is the human readable name for the channel.
The payload contains the entering user.
exitFrom :: Text -> BotReacting a (User' a, Channel' a, TimeStamp) () -> ScriptDefinition a () Source #
This handler runs whenever a user exits the specified channel, provided the bot is subscribed to the channel in question.
The argument is the human readable name for the channel.
The payload contains the exting user.
customTrigger :: (Event a -> Maybe d) -> BotReacting a d () -> ScriptDefinition a () Source #
Sending messages
send :: (IsAdapter a, Get d (Channel' a)) => Text -> BotReacting a d () Source #
Send a message to the channel the triggering message came from.
Equivalent to "robot.send" in hubot
reply :: (IsAdapter a, Get d (User' a), Get d (Channel' a)) => Text -> BotReacting a d () 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 :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadLoggerIO m) => Text -> Text -> m () Source #
Send a message to a Channel (by name)
messageChannel' :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel (AdapterT m) -> Text -> m () Source #
Getting Data
getData :: BotReacting a d d Source #
getUser :: forall m a. Get m (User' a) => BotReacting a m (User a) Source #
Get the user whihc was part of the triggered action.
getMatch :: Get m Match => BotReacting a m Match Source #
Get the results from matching the regular expression.
Equivalent to "msg.match" in hubot.
getMessage :: Get m Message => 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
getChannel :: forall a m. Get m (Channel' a) => BotReacting a m (Channel a) Source #
Get the stored channel in which something happened.
getBotName :: HasConfigAccess m => m Text Source #
Get the configured name of the bot.
getChannelName :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Channel (AdapterT m) -> m Text Source #
Get the human readable name of a channel.
resolveChannel :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => Text -> m (Maybe (Channel (AdapterT m))) Source #
getUsername :: (HasConfigAccess m, AccessAdapter m, IsAdapter (AdapterT m), MonadIO m) => User (AdapterT m) -> m Text Source #
Get the username of a registered user.
Interacting with the config
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.
Access config (advanced, internal)
getAppConfigVal :: (Configured a, HasConfigAccess m) => Name -> m (Maybe a) Source #
INTERNAL, USE WITH CARE
Get a value from the bot config (should be "bot" subconfig)
requireAppConfigVal :: (Configured a, HasConfigAccess m) => Name -> m a Source #
INTERNAL, USE WITH CARE
Get a value from the bot config (should be "bot" subconfig)
getConfig :: HasConfigAccess m => m Config Source #
Get the config part for the currect script
getConfigInternal :: HasConfigAccess m => m Config Source #
INTERNAL USE WITH CARE
Obtain the entire config structure
Types
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.
Internals
Values
Functions
runDefinitions :: ScriptId -> ScriptDefinition a () -> a -> Config -> RunnerM (Script a) Source #
Types
data BotActionState a d Source #
Read only data available to a handler when the bot reacts to an event.
HasScriptId (BotActionState a0 d0) ScriptId Source # | |
MonadReader (BotActionState a d) (BotReacting a d) Source # | |
newtype 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.
BotReacting | |
|
MonadBase IO (BotReacting a d) Source # | |
Monad (BotReacting a d) Source # | |
Functor (BotReacting a d) Source # | |
Applicative (BotReacting a d) Source # | |
MonadIO (BotReacting a d) Source # | |
MonadLogger (BotReacting a d) Source # | |
MonadLoggerIO (BotReacting a d) Source # | |
AccessAdapter (BotReacting a b) Source # | |
IsScript (BotReacting a b) Source # | |
HasConfigAccess (BotReacting a b) Source # | |
MonadReader (BotActionState a d) (BotReacting a d) Source # | |
type AdapterT (BotReacting a b) 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.
HasScriptId (Script a0) ScriptId Source # | |
HasActions (Script a0) (Handlers a0) Source # | |
newtype ScriptDefinition a r Source #
MonadBase IO (ScriptDefinition a) Source # | |
Monad (ScriptDefinition a) Source # | |
Functor (ScriptDefinition a) Source # | |
Applicative (ScriptDefinition a) Source # | |
MonadIO (ScriptDefinition a) Source # | |
MonadLogger (ScriptDefinition a) Source # | |
AccessAdapter (ScriptDefinition a) Source # | |
IsScript (ScriptDefinition a) Source # | |
HasConfigAccess (ScriptDefinition a) Source # | |
type AdapterT (ScriptDefinition a) Source # | |
newtype ScriptInit a Source #
Initializer for a script. This gets run by the server during startup and creates a Script
ScriptInit (ScriptId, a -> Config -> RunnerM (Script a)) |
A type, basically a String, which identifies a script to the config and the logging facilities.
Handlers (Vector (Regex, (User' a, Channel' a, Match, Message, TimeStamp) -> RunnerM ())) (Vector (Regex, (User' a, Channel' a, Match, Message, TimeStamp) -> RunnerM ())) (Vector (Event a -> Maybe (RunnerM ()))) (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ())) (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ())) (Vector ((User' a, Channel' a, Topic, TimeStamp) -> RunnerM ())) (HashMap Text (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ()))) (HashMap Text (Vector ((User' a, Channel' a, TimeStamp) -> RunnerM ()))) (HashMap Text (Vector ((User' a, Channel' a, Topic, TimeStamp) -> RunnerM ()))) |
Helper lenses
class HasActions s a | s -> a where Source #
HasActions (Script a0) (Handlers a0) Source # | |
class HasResponds s a | s -> a where Source #
class HasCustoms s a | s -> a where Source #
class HasJoinsIn s a | s -> a where Source #
class HasLeavesFrom s a | s -> a where Source #
leavesFrom :: Lens' s a Source #
class HasTopicChange s a | s -> a where Source #
topicChange :: Lens' s a Source #
class HasTopicChangeIn s a | s -> a where Source #
topicChangeIn :: Lens' s a Source #
HelperClasses
class AccessAdapter m where Source #
getAdapter :: m (AdapterT m) Source #
AccessAdapter (AdapterM a) Source # | |
AccessAdapter (ScriptDefinition a) Source # | |
AccessAdapter (BotReacting a b) Source # | |
Class which says that there is a way to get to a Message
from this type m
.
Get (a, b, TimeStamp) TimeStamp Source # | |
Get (a, Channel' b, c) (Channel' b) Source # | |
Get (User' a, b, c) (User' a) Source # | |
Get (a, b, Topic, d) Topic Source # | |
Get (a, b, c, TimeStamp) TimeStamp Source # | |
Get (a, Channel' b, c, d) (Channel' b) Source # | |
Get (User' a, b, c, d) (User' a) Source # | |
Get (a, b, c, Message, e) Message Source # | |
Get (a, b, Match, d, e) Match Source # | |
Get (a, b, c, d, TimeStamp) TimeStamp Source # | |
Get (a, Channel' b, c, d, e) (Channel' b) Source # | |
Get (User' a, b, c, d, e) (User' a) Source # | |