Documentation ¶
Overview ¶
Package bot contains a simple Matrix bot framework.
Index ¶
- type Client
- type ClientConfig
- type Command
- type Event
- type EventType
- type Message
- type Room
- func (r *Room) Allowed() bool
- func (r *Room) Join() (id string, err error)
- func (r *Room) SendHTML(plain, html string) (string, error)
- func (r *Room) SendMarkdown(markdown string) (string, error)
- func (r *Room) SendMessage(message *Message) (string, error)
- func (r *Room) SendText(plain string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Client *matrix.Client Config *ClientConfig // contains filtered or unexported fields }
Client represents a Matrix Client This is a slightly modified version of gomatrix.Client.
func NewClient ¶
func NewClient(homeserverURL, userID, accessToken string, config *ClientConfig) (c *Client, err error)
NewClient returns a configured Matrix client.
func (*Client) SetCommand ¶
SetCommand registers a command for use in the bot.
func (*Client) SetMessageHandler ¶
SetMessageHandler sets the default event handlers for a message type. Note that setting the handler for EventTypeRoomMessage will disable the simple Command interface.
type ClientConfig ¶
type ClientConfig struct { // MessageType contains the message type of any message by the bot. // Defaults to `m.notice`. MessageType string // CommandPrefixes contains required prefixes for commands. // Add an empty string to match all messages. CommandPrefixes []string // IgnoreHighlights disables command matching on highlights. // This means that only the CommandPrefixes will be matched. IgnoreHighlights bool // Commands contains a set of commands to handle. // It defaults to a map containing only the "help" command. Commands map[string]*Command // AllowRooms contains a list of allowed room IDs. // All rooms are allowed if left empty. AllowedRooms []string }
ClientConfig contains all tunable Client configuration.
type Command ¶
type Command struct { // Summary contains a short description of the command. Summary string // Description (optional) contains a longer description of the command. Description string // MessageHandler contains a simple Matrix Message handler. // The Matrix ID of the sender, original command and arguments are provided. MessageHandler func(sender, cmd string, args ...string) *Message // Subcommands (optional) contains any subcommands under this command. // These subcommands are executed instead of the main command when matched. Subcommands map[string]*Command }
Command represents a simple Matrix command.
func (*Command) GetCommand ¶
GetCommand returns the Command that will be executed when the command is called using the given command name and arguments.
func (*Command) Help ¶
Help returns the help message for the Command. This is either the Description (if provided) or the Summary.
func (*Command) HelpCommand ¶
HelpCommand returns the help command for a command.
func (*Command) HelpMessage ¶
HelpMessage returns the help message for a command and its subcommands.
type Message ¶
type Message struct { MsgType string `json:"msgtype"` Body string `json:"body"` FormattedBody string `json:"formatted_body,omitempty"` Format string `json:"format,omitempty"` }
Message represents a formatted Matrix Message.
func NewHTMLMessage ¶
NewHTMLMessage creates a new message with plain-text and HTML content.
func NewMarkdownMessage ¶
NewMarkdownMessage creates a new message with the original Markdown as the plain-text content, and the rendered markdown as HTML content. The given Markdown is not sanitized.
func NewTextMessage ¶
NewTextMessage creates a new plain-text message. messageType may be left empty, in which case it's overridden by the configured message type.
type Room ¶
type Room struct { ID string // contains filtered or unexported fields }
Room represents a Matrix Room.
func (*Room) SendMarkdown ¶
SendMarkdown sends a Markdown formatted message as plain text and HTML. The given Markdown is not sanitized.
func (*Room) SendMessage ¶
SendMessage sends a message to a room.