botmaid

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 18 Imported by: 1

README

botmaid

This repository holds a package for managing bots.

Download / Install

The easiest way to install is to run go get -u github.com/catsworld/botmaid. You can also manually git clone the repository to $GOPATH/src/catsworld/botmaid.

Documentation

Overview

Package botmaid is a package for managing bots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func In

func In(a interface{}, s ...interface{}) bool

In checks if the element is in the slice.

func ListToString

func ListToString(list []string, format string, separator string, andWord string) string

ListToString convert the list to a string.

Types

type API

type API interface {
	GetUpdates(GetUpdatesConfig) (UpdateChannel, ErrorChannel)
	Push(Update) (Update, error)
}

API is an interface including some common behaviors for APIs.

GetUpdates always gets updates and errors into the channels with a given config.

Push always pushes an update and returns it back if existing.

Delete always deletes a specific update.

type APICqhttp

type APICqhttp struct {
	AccessToken string
	Secret      string
	APIEndpoint string
}

APICqhttp is a struct stores some basic information of the CQHTTP. Please search in CQHTTP document for details.

func (*APICqhttp) API

func (a *APICqhttp) API(end string, m map[string]interface{}) (interface{}, error)

API returns the body of an HTTP response to the CQHTTP.

func (*APICqhttp) GetUpdates added in v1.9.0

GetUpdates gets updates and errors into the channels with a given config.

func (*APICqhttp) Push

func (a *APICqhttp) Push(update Update) (Update, error)

Push pushes an update and returns it back if existing.

type APITelegramBot

type APITelegramBot struct {
	Token  string
	Offset int64
}

APITelegramBot is a struct stores some basic information of the Telegram Bot API. Please search in official API document for details.

func (*APITelegramBot) API

func (a *APITelegramBot) API(end string, m map[string]interface{}) (interface{}, error)

API returns the body of an HTTP response to the Telegram Bot API.

func (*APITelegramBot) GetUpdates added in v1.9.0

GetUpdates gets updates and errors into the channels with a given config.

func (*APITelegramBot) Push

func (a *APITelegramBot) Push(update Update) (Update, error)

Push pushes an update and returns it back if existing.

type Bot

type Bot struct {
	ID      string
	API     API
	Self    *User
	BotMaid *BotMaid
}

Bot includes some information of a bot.

func (*Bot) At added in v1.0.1

func (b *Bot) At(u *User) []string

At returns a string to mention someone in a message.

func (*Bot) BeAt added in v1.3.0

func (b *Bot) BeAt(u *Update) bool

BeAt checks if a message of an update is mentioning the bot.

func (*Bot) IsCommand added in v1.0.1

func (b *Bot) IsCommand(u *Update, c []string) bool

IsCommand checks if a message is a specific command.

func (*Bot) IsMaster added in v1.0.1

func (b *Bot) IsMaster(u *User) bool

IsMaster checks if a user is master of the bot.

func (*Bot) Platform

func (b *Bot) Platform() string

Platform returns a string showing the platform of the bot.

func (*Bot) Reply added in v1.4.0

func (b *Bot) Reply(u *Update, s ...string) (Update, error)

Reply replies a message back.

type BotMaid

type BotMaid struct {
	Bots      map[string]*Bot
	Conf      *botMaidConfig
	Redis     *redis.Client
	Commands  CommandSlice
	Timers    []Timer
	HelpMenus []HelpMenu
	Words     map[string][]string
	RespTime  time.Time
}

BotMaid includes a slice of Bot and some methods to use them.

func New

func New(configFile string) (*BotMaid, error)

New creates a BotMaid.

func (*BotMaid) AddCommand

func (bm *BotMaid) AddCommand(c *Command)

AddCommand adds a command into the []Command.

func (*BotMaid) AddTimer

func (bm *BotMaid) AddTimer(t Timer)

AddTimer adds a timer into the []Timer.

func (*BotMaid) Broadcast

func (bm *BotMaid) Broadcast(key string, m *Message)

Broadcast sends an update to all chats in the table.

func (*BotMaid) Start

func (bm *BotMaid) Start() error

Start starts the BotMaid.

func (*BotMaid) SwitchBroadcast

func (bm *BotMaid) SwitchBroadcast(key string, c *Chat, b *Bot)

SwitchBroadcast switches the broadcast on/off of a chat.

type Chat

type Chat struct {
	ID    int64
	Type  string
	Title string
}

Chat is a struct for a chat.

type Command

type Command struct {
	Do                     func(*Update, *Bot) bool
	Priority               int
	Menu, MenuText, Help   string
	Names                  []string
	ArgsMinLen, ArgsMaxLen int
	Master                 bool
}

Command is a func with priority value so that we can sort some Commands to make them in a specific order.

type CommandSlice

type CommandSlice []*Command

CommandSlice is a slice of Command that could be sort.

func (CommandSlice) Len

func (cs CommandSlice) Len() int

Len is the length of a CommandSlice.

func (CommandSlice) Less

func (cs CommandSlice) Less(i, j int) bool

Less returns true if CommandSlice[i] is less then CommandSlice[j].

func (CommandSlice) Swap

func (cs CommandSlice) Swap(i, j int)

Swap swaps CommandSlice[i] and CommandSlice[j].

type ErrorChannel

type ErrorChannel chan error

ErrorChannel is a channel for saving errors.

type GetUpdatesConfig added in v1.4.0

type GetUpdatesConfig struct {
	Limit            int
	Timeout          int
	RetryWaitingTime time.Duration
}

GetUpdatesConfig is a struct for getting updates.

Limit decides the number of updates pulled once. Timeout decides the timeout of long polling. RetryWaitingTime decides decides the time waiting after pulling an error.

type HelpMenu added in v1.7.0

type HelpMenu struct {
	Menu, Help string
	Names      []string
}

HelpMenu describes the menu item of the help.

type Message

type Message struct {
	ID      int64
	Text    string
	Image   string
	Audio   string
	Args    []string
	Command string
}

Message is a struct for a message of an update.

type Timer

type Timer struct {
	Do         func()
	Start, End time.Time
	Frequency  time.Duration
}

Timer is a func with time and frequency so that we can call it at some specific time.

type Update

type Update struct {
	ID      int64
	Type    string
	Time    time.Time
	Chat    *Chat
	User    *User
	Message *Message
}

Update is a struct for an update of APIs.

type UpdateChannel

type UpdateChannel chan Update

UpdateChannel is a channel for saving updates.

type User

type User struct {
	ID       int64
	UserName string
	NickName string
}

User is a struct for a user.

type Word added in v1.0.1

type Word struct {
	Word   string
	Weight int
}

Word is a string with weight so that we can choose them randomly.

type WordSlice added in v1.3.0

type WordSlice []Word

WordSlice is a slice of Word.

func (WordSlice) Random added in v1.3.0

func (ws WordSlice) Random() string

Random returns a random string from the WordSlice.

Jump to

Keyboard shortcuts

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