botmaid

package module
v1.3.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 14 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 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 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 {
	ID string

	API api.API

	Self *api.User

	BotMaid *BotMaid
}

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) BeAt added in v1.3.0

func (b *Bot) BeAt(e *api.Event) bool

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

func (*Bot) IsCommand added in v1.0.1

func (b *Bot) IsCommand(e *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(p api.Place) bool

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

func (*Bot) Platform

func (b *Bot) Platform() string

Platform returns a string showing the platform of the bot.

func (*Bot) UserNameFromAt added in v1.3.0

func (b *Bot) UserNameFromAt(s string) string

UserNameFromAt returns the UserName of the user in the mention query.

type BotMaid

type BotMaid struct {
	Bots map[string]Bot

	Conf *toml.Tree

	DB *sql.DB

	Commands []Command
	Timers   []Timer

	HelpMenus map[string]string

	Words map[string][]string

	RespTime time.Time
}

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

func (*BotMaid) AddCommand

func (bm *BotMaid) AddCommand(c Command)

AddCommand adds a command into the []Command.

func (*BotMaid) AddTimer

func (bm *BotMaid) AddTimer(f func(), t time.Time, fre string)

AddTimer adds a timer into the []Timer.

func (*BotMaid) Init added in v1.0.1

func (bm *BotMaid) Init() error

Init initializes the BotMaid.

func (*BotMaid) Run added in v1.0.1

func (bm *BotMaid) Run()

Run begins to get updates and run commands.

type Command

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

	Menu, Help   string
	Names        []string
	Master, Test 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 Help

type Help struct {
	HelpMenu                string
	SelfIntro, UndefCommand []string
	HelpSubMenu, HelpAlias  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