monebot

package module
v0.0.0-...-9dac1f1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2016 License: MIT Imports: 7 Imported by: 0

README

Monebot

(soon available on @ClaptrapBot)

Documentation

Index

Constants

View Source
const (
	ParseMarkdown = "Markdown"
	ParseHTML     = "HTML"
)

Variables

View Source
var (
	ErrNotFound = errors.New("Not found")
)

Functions

func MessageCommandInfo

func MessageCommandInfo(c Command) (Text, Parse string)

func MessageMissingContent

func MessageMissingContent() (Text, Parse string)

func MessageMissingName

func MessageMissingName() (Text, Parse string)

func MessageSavedCommand

func MessageSavedCommand(c Command) (Text, Parse string)

Types

type Answer

type Answer struct {
	Text      string `bson:"text,omitempty"`
	NumParams int    `bson:"numParams"`
	Parse     string `bson:"parseMode,omitempty"`
	Sticker   string `bson:"sticker,omitempty"`
}

Answer holds the possible messages the bot can send

type Command

type Command struct {
	Pack       string    `bson:"pack"`
	Name       string    `bson:"name"`
	Answer     Answer    `bson:"answer"`
	Time       time.Time `bson:"time"`
	Creator    string    `bson:"creator,omitempty"`
	NumChanged int       `bson:"numChanged,omitempty"`
}

Command holds the data about for persistent commands

func (Command) FullName

func (c Command) FullName() string

FullName returns the a string of the form <pack>.<name>

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database holds the necessary data for all persistent data operations

func NewDatabase

func NewDatabase(connURI string) (*Database, error)

NewDatabase returns a new database connected through the connURI

func (Database) Close

func (db Database) Close()

Close the database session

func (Database) FindCommand

func (db Database) FindCommand(pack, name string, numParams int) (Command, error)

FindCommand returns the one command filtered by the pack, name and numParams, or an error if not found

func (Database) FindPack

func (db Database) FindPack(chat int64) (string, error)

FindPack returns the default pack name for the chat

func (Database) FindState

func (db Database) FindState(chat int64, user int) (State, error)

func (Database) RemoveState

func (db Database) RemoveState(chat int64, user int) error

func (Database) UpsertCommand

func (db Database) UpsertCommand(c Command) error

UpsertCommand updates or inserts the given command

func (Database) UpsertState

func (db Database) UpsertState(s State) error

type Pack

type Pack struct {
	Name  string  `bson:"name"`
	Chats []int64 `bson:"chats"`
}

Pack holds a name for the pack and all chats that use it by default

type State

type State struct {
	Chat       int64        `bson:"chat"`
	User       int          `bson:"user"`
	Waiting    WaitingState `bson:"waiting,omitempty"`
	LastUpdate time.Time    `bson:"lastUpdate"`
}

func NewWaitingState

func NewWaitingState(chat int64, user int, w WaitingState) State

type WaitingState

type WaitingState struct {
	ForCommand bool   `bson:"forCommand,omitempty"`
	Pack       string `bson:"pack,omitempty"`
	Command    string `bson:"command,omitempty"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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