botmaid

package module
v1.0.0-alpha.27 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: MIT Imports: 21 Imported by: 1

README

botmaid

A package for managing bots.

Documentation

Overview

Package botmaid is a package for managing bots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func At

func At(u *User) string

At returns a string to mention someone in a message.

func In

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

In checks if the element is in the slice.

func IsCommand

func IsCommand(u *Update, c ...interface{}) bool

IsCommand checks if a message is a specific command.

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 {
	Pull(*PullConfig) (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) Pull

Pull pulls 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) Pull

Pull pulls 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
}

Bot includes some information of a bot.

func (*Bot) Platform

func (b *Bot) Platform() string

Platform returns a string showing the platform of the bot.

type BotMaid

type BotMaid struct {
	Bots map[string]*Bot

	Conf *botMaidConfig

	Redis *redis.Client

	Commands CommandSlice
	Timers   []*Timer
	Helps    []*Help
	Flags    map[string]*pflag.FlagSet

	Words map[string][]string
	// contains filtered or unexported fields
}

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) BeAt

func (bm *BotMaid) BeAt(u *Update) bool

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

func (*BotMaid) Broadcast

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

Broadcast sends an update to all chats in the table.

func (*BotMaid) IsBanned

func (bm *BotMaid) IsBanned(u *User) bool

IsBanned checks if a user has been banned.

func (*BotMaid) IsMaster

func (bm *BotMaid) IsMaster(u *User) bool

IsMaster checks if a user is master of the bot.

func (*BotMaid) ParseUserID

func (bm *BotMaid) ParseUserID(u *Update, s string) (int64, error)

ParseUserID parses the ID of the User in the At string.

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) bool

	Priority int

	Help *Help

	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 Help

type Help struct {
	Menu, Help, Full string

	Names []string

	SetFlag func(*pflag.FlagSet)
}

Help 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 PullConfig

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

PullConfig is a struct for pulling.

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 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

	Bot *Bot
}

Update is a struct for an update of APIs.

func Reply

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

Reply replies a message back.

type UpdateChannel

type UpdateChannel chan *Update

UpdateChannel is a channel for saving updates.

type User

type User struct {
	ID int64

	UserName string
	NickName string

	Bot *Bot
}

User is a struct for a user.

Directories

Path Synopsis
Package random includes some functions relative to random.
Package random includes some functions relative to random.

Jump to

Keyboard shortcuts

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