botmaid

package module
v1.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 12 Imported by: 1

README

botmaid

This repository holds a package includes more useful public functions for 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 includes more useful public functions for bots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommand added in v1.0.1

func AddCommand(cs *[]Command, f func(*api.Event, *Bot) bool, p int)

AddCommand adds a command into the []Command.

func AddTimer added in v1.0.1

func AddTimer(ts *[]Timer, f func(), t time.Time, fre string)

AddTimer adds a timer into the []Timer.

func RandomWordWithWeight added in v1.0.1

func RandomWordWithWeight(ws []Word) string

RandomWordWithWeight returns a random string from the Word slice according to the weight.

func RegHelpCommand added in v1.0.1

func RegHelpCommand(cs *[]Command, hs *Help)

RegHelpCommand adds help as a high-priority command if a Help is defined and going to be used.

func SplitCommand added in v1.0.1

func SplitCommand(c string) []string

SplitCommand splits a string into a slice of string.

Types

type Bot

type Bot struct {
	API api.API

	Self *api.User
	// contains filtered or unexported fields
}

Bot includes some information of a bot.

func (*Bot) At added in v1.0.1

func (b *Bot) At(u *api.User) string

At returns a string to mention someone in a message.

func (*Bot) CheckBeAt added in v1.0.1

func (b *Bot) CheckBeAt(u *api.Event) bool

CheckBeAt checks if someone send a message without commands and at the api.

func (*Bot) IsCommand added in v1.0.1

func (b *Bot) IsCommand(u *api.Event, 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 *api.User) bool

IsMaster checks if a user is master of the bot.

func (*Bot) IsTestPlace added in v1.0.1

func (b *Bot) IsTestPlace(c *api.Place) bool

IsTestPlace checks if a place is test place of the bot.

type BotMaid

type BotMaid struct {
	Bots []Bot
}

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

func (*BotMaid) Init added in v1.0.1

func (bm *BotMaid) Init(conf *toml.Tree) error

Init reads information of bots from the toml and add them into the manager.

func (*BotMaid) Run added in v1.0.1

func (bm *BotMaid) Run(conf *toml.Tree, cs []Command, ts []Timer)

Run begins to get updates and run commands.

type Command

type Command struct {
	Do       func(*api.Event, *Bot) bool
	Priority int
}

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 Help

type Help struct {
	SelfIntro, HelpMenu, UndefCommand string
	HelpSubMenu                       map[string]string
}

Help stores a full help menus that would be used in '/help' command.

type Timer

type Timer struct {
	Do        func()
	Time      time.Time
	Frequency string
}

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

type Word added in v1.0.1

type Word struct {
	Word   string
	Weight int64
}

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

Jump to

Keyboard shortcuts

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