bot

package
v0.0.0-...-eca5cb0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package bot contains all bots implementations and tests to them Multibot is a manager for all bots to simply distribute messages to all bots

Index

Constants

View Source
const (
	ChatTypePrivate = 0
	ChatTypeGroup   = 1
	ChatTypeChannel = 2
)

All recognizable chat types

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot interface {
	OnMessage(msg Message) *Response // nil if nothing to send
	Help() string                    // returns help message - how to use this bot
}

Bot describes a particular bot, that reacts on messages and sends whatever

type ChatType

type ChatType int

ChatType describes type of the chat, where the message came from

type GroupBot

type GroupBot struct {
	GroupBotParams
}

GroupBot gathers usernames into one mention, like @admins

func NewGroupBot

func NewGroupBot(params GroupBotParams) *GroupBot

NewGroupBot initializes an instance of GroupBot

func (*GroupBot) Help

func (g *GroupBot) Help() string

Help returns the usage of this bot

func (*GroupBot) OnMessage

func (g *GroupBot) OnMessage(msg Message) *Response

OnMessage receives any commands, that are listed in help and group aliases

type GroupBotParams

type GroupBotParams struct {
	Store              groups.Store
	RespondAllCommands bool
	GetGroupMembers    func(chatID string) ([]User, error)
}

GroupBotParams describes all necessary parameters for correct working of GroupBot

type Message

type Message struct {
	ID             string
	ChatID         string
	ChatType       ChatType
	From           *User
	Sent           time.Time
	Text           string `json:",omitempty"`
	AddedBotToChat bool
}

Message to pass data from/to bot

type MockBot

type MockBot struct {
	mock.Mock
}

MockBot is an autogenerated mock type for the Bot type

func (*MockBot) Help

func (_m *MockBot) Help() string

Help provides a mock function with given fields:

func (*MockBot) OnMessage

func (_m *MockBot) OnMessage(msg Message) *Response

OnMessage provides a mock function with given fields: msg

type MultiBot

type MultiBot []Bot

MultiBot is bot that delivers messages to bots that it contains

func (*MultiBot) Help

func (m *MultiBot) Help() string

Help composes help from all bots

func (*MultiBot) OnMessage

func (m *MultiBot) OnMessage(msg Message) *Response

OnMessage delivers the message to all bots and returns a response from any bot, that answers

type Response

type Response struct {
	Text        string        // text of the message
	Pin         bool          // enable pin
	Unpin       bool          // unpin current pinned message
	Preview     bool          // enable web preview
	Reply       bool          // message that we have to reply to, might be nil, if caused by other action
	BanInterval time.Duration // bot banning user set the interval
}

Response describes bot's answer on particular message

func (Response) IsEmpty

func (r Response) IsEmpty() bool

IsEmpty checks that response is empty and we do not have to send it

type User

type User struct {
	ID          string
	Username    string // might be "" for users without usernames
	DisplayName string
	IsAdmin     bool
	IsBot       bool
}

User defines user info of the Message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL