botmaid

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: MIT Imports: 22 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 Contains

func Contains(s interface{}, a interface{}) bool

Contains checks if the element is in the slice.

func ListToString

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

ListToString convert the list to a string.

Types

type API

type API interface {
	Pull(*PullConfig) (UpdateChannel, ErrorChannel)
	Push(*Update) (*Update, error)

	Platform() string
	ParseUserID(u *Update, s string) (int64, error)
	// contains filtered or unexported methods
}

API is an interface including some common behaviors for APIs.

type APICqhttp

type APICqhttp struct {
	AccessToken       string
	Secret            string
	APIEndpoint       string
	WebsocketEndpoint 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) ParseUserID

func (a *APICqhttp) ParseUserID(u *Update, s string) (int64, error)

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

func (*APICqhttp) Platform

func (a *APICqhttp) Platform() string

Platform returns a string showing the platform of the bot.

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

func (a *APITelegramBot) ParseUserID(u *Update, s string) (int64, error)

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

func (*APITelegramBot) Platform

func (a *APITelegramBot) Platform() string

Platform returns a string showing the platform of the bot.

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

	BotMaid *BotMaid
}

Bot includes some information of a bot.

type BotMaid

type BotMaid struct {
	Bots map[string]*Bot

	Conf *botMaidConfig

	Redis *redis.Client

	Commands CommandSlice
	Timers   []*Timer
	Helps    []*Help

	Words      map[string]string
	SubEntries []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) At

func (bm *BotMaid) At(u *User) string

At returns a string to mention someone in a message.

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

func (bm *BotMaid) Delete(u *Update) (*Update, error)

func (*BotMaid) HelpCommandDo

func (bm *BotMaid) HelpCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) HelpRespCommandDo

func (bm *BotMaid) HelpRespCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) IsBanned

func (bm *BotMaid) IsBanned(c *Chat) 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) MasterCommandDo

func (bm *BotMaid) MasterCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) Reply

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

Reply replies a message back.

func (*BotMaid) ReplyType

func (bm *BotMaid) ReplyType(u *Update, s, t string) (*Update, error)

Reply replies a message back with a type.

func (*BotMaid) Start

func (bm *BotMaid) Start() error

Start starts the BotMaid.

func (*BotMaid) SubscribeCommandDo

func (bm *BotMaid) SubscribeCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) VersetCommandDo

func (bm *BotMaid) VersetCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) VersetCommandHelpSetFlag

func (bm *BotMaid) VersetCommandHelpSetFlag(f *pflag.FlagSet)

func (*BotMaid) VersionCommandDo

func (bm *BotMaid) VersionCommandDo(u *Update, f *pflag.FlagSet) bool

func (*BotMaid) VersionCommandHelpSetFlag

func (bm *BotMaid) VersionCommandHelpSetFlag(f *pflag.FlagSet)

type Chat

type Chat struct {
	ID   int64
	Type string

	Title string

	Update *Update
}

Chat is a struct for a chat.

type Command

type Command struct {
	Do func(*Update, *pflag.FlagSet) bool

	Priority int

	Help *Help
}

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, Usage, Comment string

	Names []string

	SetFlag func(*pflag.FlagSet)
}

Help describes the menu item of the help.

type Message

type Message struct {
	ID   int64
	Type string

	Content string

	Args    []string
	Command string
	Flags   map[string]*pflag.FlagSet

	Update *Update
}

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

	Chat    *Chat
	User    *User
	Message *Message

	Time time.Time

	Bot *Bot
}

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

	Update *Update
}

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