botmaid

package module
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 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 GetArgument added in v1.3.0

func GetArgument(c string) []string

GetArgument returns a slice with a command and an argument.

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(t Timer)

AddTimer adds a timer into the []Timer.

func (*BotMaid) Broadcast

func (bm *BotMaid) Broadcast(tableName string, m *api.Message)

Broadcast pushes an event to all places in the table.

func (*BotMaid) InitBroadcastTable added in v1.3.0

func (bm *BotMaid) InitBroadcastTable(tableName string) error

InitBroadcastTable creates a table with the standard structure of a broadcast.

func (*BotMaid) Start

func (bm *BotMaid) Start() error

Start starts the BotMaid.

func (*BotMaid) SwitchBroadcast

func (bm *BotMaid) SwitchBroadcast(tableName string, place *api.Place, b *Bot)

SwitchBroadcast switches the broadcast on/off of a place.

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

type DBBroadcastPlace struct {
	ID        int64
	BotID     string
	PlaceType string
	PlaceID   int64
}

DBBroadcastPlace is a struct saved some information of the place to broadcast.

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.

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 Word slice.

Jump to

Keyboard shortcuts

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