bot

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MsgBroadcastStarted defines text to be sent by the bot when the broadcast started
	MsgBroadcastStarted = "Вещание началось. Приобщиться можно тут: https://stream.radio-t.com/"

	// MsgBroadcastFinished defines text to be sent by the bot when the broadcast finished
	MsgBroadcastFinished = "Вещание завершилось"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Anecdote

type Anecdote struct {
	// contains filtered or unexported fields
}

Anecdote bot, returns from http://rzhunemogu.ru/RandJSON.aspx?CType=1

func NewAnecdote

func NewAnecdote(client HTTPClient) *Anecdote

NewAnecdote makes a bot for http://rzhunemogu.ru

func (Anecdote) Help

func (a Anecdote) Help() string

Help returns help message

func (Anecdote) OnMessage

func (a Anecdote) OnMessage(msg Message) (response Response)

OnMessage returns one entry

func (Anecdote) ReactOn

func (a Anecdote) ReactOn() []string

ReactOn keys

type BroadcastParams

type BroadcastParams struct {
	URL          string        // URL for "ping"
	PingInterval time.Duration // Ping interval
	DelayToOff   time.Duration // State will be switched to off in no ok replies from URL in this intrval
	Client       http.Client   // http client
}

BroadcastParams defines parameters for broadcast detection

type BroadcastStatus

type BroadcastStatus struct {
	// contains filtered or unexported fields
}

BroadcastStatus bot replies with current broadcast status

func NewBroadcastStatus

func NewBroadcastStatus(ctx context.Context, params BroadcastParams) *BroadcastStatus

NewBroadcastStatus starts status checking goroutine and returns bot instance

func (*BroadcastStatus) Help

func (b *BroadcastStatus) Help() string

Help returns help message

func (*BroadcastStatus) OnMessage

func (b *BroadcastStatus) OnMessage(_ Message) (response Response)

OnMessage returns current broadcast status if it was changed

func (*BroadcastStatus) ReactOn

func (b *BroadcastStatus) ReactOn() []string

ReactOn keys

type Duck

type Duck struct {
	// contains filtered or unexported fields
}

Duck bot, returns from duckduckgo via mashape

func NewDuck

func NewDuck(key string, client HTTPClient) *Duck

NewDuck makes a bot for duckduckgo

func (*Duck) Help

func (d *Duck) Help() string

Help returns help message

func (*Duck) OnMessage

func (d *Duck) OnMessage(msg Message) (response Response)

OnMessage pass msg to all bots and collects responses

func (*Duck) ReactOn

func (d *Duck) ReactOn() []string

ReactOn keys

type Entity

type Entity struct {
	Type   string
	Offset int
	Length int
	URL    string `json:",omitempty"` // For “text_link” only, url that will be opened after user taps on the text
	User   *User  `json:",omitempty"` // For “text_mention” only, the mentioned user
}

Entity represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

type Excerpt

type Excerpt struct {
	// contains filtered or unexported fields
}

Excerpt bot, returns link excerpt

func NewExcerpt

func NewExcerpt(api string, token string) *Excerpt

NewExcerpt makes a bot extracting articles excerpt

func (*Excerpt) Help

func (e *Excerpt) Help() string

Help returns help message

func (*Excerpt) OnMessage

func (e *Excerpt) OnMessage(msg Message) (response Response)

OnMessage pass msg to all bots and collects responses

func (*Excerpt) ReactOn

func (e *Excerpt) ReactOn() []string

ReactOn keys

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient wrap http.Client to allow mocking

type Image

type Image struct {
	// FileID corresponds to Telegram file_id
	FileID   string
	Width    int
	Height   int
	Caption  string    `json:",omitempty"`
	Entities *[]Entity `json:",omitempty"`
}

Image represents image

type Interface

type Interface interface {
	OnMessage(msg Message) (response Response)
	ReactOn() []string
	Help() string
}

Interface is a bot reactive spec. response will be sent if "send" result is true

type Message

type Message struct {
	ID       int
	From     User
	Sent     time.Time
	HTML     string    `json:",omitempty"`
	Text     string    `json:",omitempty"`
	Entities *[]Entity `json:",omitempty"`
	Image    *Image    `json:",omitempty"`
}

Message is primary record to pass data from/to bots

type MockHTTPClient

type MockHTTPClient struct {
	mock.Mock
}

MockHTTPClient is an autogenerated mock type for the HTTPClient type

func (*MockHTTPClient) Do

func (_m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

Do provides a mock function with given fields: req

type MockInterface

type MockInterface struct {
	mock.Mock
}

MockInterface is an autogenerated mock type for the Interface type

func (*MockInterface) Help

func (_m *MockInterface) Help() string

Help provides a mock function with given fields:

func (*MockInterface) OnMessage

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

OnMessage provides a mock function with given fields: msg

func (*MockInterface) ReactOn

func (_m *MockInterface) ReactOn() []string

ReactOn provides a mock function with given fields:

type MockSuperUser

type MockSuperUser struct {
	mock.Mock
}

MockSuperUser is an autogenerated mock type for the SuperUser type

func (*MockSuperUser) IsSuper

func (_m *MockSuperUser) IsSuper(userName string) bool

IsSuper provides a mock function with given fields: userName

type MultiBot

type MultiBot []Interface

MultiBot combines many bots to one virtual

func (MultiBot) Help

func (b MultiBot) Help() string

Help returns help message

func (MultiBot) OnMessage

func (b MultiBot) OnMessage(msg Message) (response Response)

OnMessage pass msg to all bots and collects reposnses (combining all of them) noinspection GoShadowedVar

func (MultiBot) ReactOn

func (b MultiBot) ReactOn() (res []string)

ReactOn returns combined list of all keywords

type News

type News struct {
	// contains filtered or unexported fields
}

News bot, returns numArticles last articles in MD format from https://news.radio-t.com/api/v1/news/lastmd/5

func NewNews

func NewNews(client HTTPClient, api string, max int) *News

NewNews makes new News bot

func (News) Help

func (n News) Help() string

Help returns help message

func (News) OnMessage

func (n News) OnMessage(msg Message) (response Response)

OnMessage returns N last news articles

func (News) ReactOn

func (n News) ReactOn() []string

ReactOn keys

type Podcasts

type Podcasts struct {
	// contains filtered or unexported fields
}

Podcasts search bot, returns search result via site-api see https://radio-t.com/api-docs/ GET /search?q=text-to-search&skip=10&limit=5, example: : https://radio-t.com/site-api/search?q=mongo&limit=10

func NewPodcasts

func NewPodcasts(client HTTPClient, api string, maxResults int) *Podcasts

NewPodcasts makes new Podcasts bot

func (*Podcasts) Help

func (p *Podcasts) Help() string

Help returns help message

func (*Podcasts) OnMessage

func (p *Podcasts) OnMessage(msg Message) (response Response)

OnMessage returns result of search via https://radio-t.com/site-api/search?

func (*Podcasts) ReactOn

func (p *Podcasts) ReactOn() []string

ReactOn keys

type PrepPost

type PrepPost struct {
	// contains filtered or unexported fields
}

PrepPost bot notifies on new prep topic on the site

func NewPrepPost

func NewPrepPost(client HTTPClient, api string, d time.Duration) *PrepPost

NewPrepPost makes new PrepPost bot sending and pinning message "Начался сбор тем"

func (*PrepPost) Help

func (p *PrepPost) Help() string

Help returns help message

func (*PrepPost) OnMessage

func (p *PrepPost) OnMessage(Message) (response Response)

OnMessage reacts on any message and, from time to time (every checkDuration) hits site api and gets the latest prep article. In case if article's url changed returns pinned response. Skips the first check to avoid false-positive on restart

func (*PrepPost) ReactOn

func (p *PrepPost) ReactOn() []string

ReactOn keys

type Response

type Response struct {
	Text        string
	Send        bool          // status
	Pin         bool          // enable pin
	Unpin       bool          // enable unpin
	Preview     bool          // enable web preview
	BanInterval time.Duration // bots banning user set the interval
}

Response describes bot's answer on particular message

type StackOverflow

type StackOverflow struct{}

StackOverflow bot, returns from "https://api.stackexchange.com/2.2/questions?order=desc&sort=activity&site=stackoverflow" reacts on "so!" prefix, i.e. "so! golang"

func NewStackOverflow

func NewStackOverflow() *StackOverflow

NewStackOverflow makes a bot for SO

func (StackOverflow) Help

func (s StackOverflow) Help() string

Help returns help message

func (StackOverflow) OnMessage

func (s StackOverflow) OnMessage(msg Message) (response Response)

OnMessage returns one entry

func (StackOverflow) ReactOn

func (s StackOverflow) ReactOn() []string

ReactOn keys

type SuperUser

type SuperUser interface {
	IsSuper(userName string) bool
}

SuperUser defines interface checking ig user name in su list

type Sys

type Sys struct {
	// contains filtered or unexported fields
}

Sys implements basic bot function to responds on ping and others from basic.data file. also reacts and say! with keys/values from say.data file

func NewSys

func NewSys(dataLocation string) (*Sys, error)

NewSys makes new sys bot and load data to []say and basic map

func (Sys) Help

func (p Sys) Help() (line string)

Help returns help message

func (Sys) OnMessage

func (p Sys) OnMessage(msg Message) (response Response)

OnMessage implements bot.Interface

func (Sys) ReactOn

func (p Sys) ReactOn() []string

ReactOn keys

type User

type User struct {
	ID          int
	Username    string
	DisplayName string
}

User defines user info of the Message

type WTF

type WTF struct {
	// contains filtered or unexported fields
}

WTF bot bans user for random interval

func NewWTF

func NewWTF(minDuration, maxDuration time.Duration, luckFactor float64) *WTF

NewWTF makes a random ban bot

func (WTF) Help

func (w WTF) Help() string

Help returns help message

func (WTF) OnMessage

func (w WTF) OnMessage(msg Message) (response Response)

OnMessage sets duration of ban randomly

func (WTF) ReactOn

func (w WTF) ReactOn() []string

ReactOn keys

Jump to

Keyboard shortcuts

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