botbot

package module
v0.0.0-...-aa8991b Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: MIT Imports: 8 Imported by: 0

README

botbot

A package inspired by urfave/cli for writting discord bots in the same manner as you write CLI applicaitons.

Example

bot, err := botbot.New("test", clix.GlobalString("token"))
if err != nil {
	return err
}
bot.Commands = []*botbot.Command{
	timeCommand,
}
if err := bot.Start(); err != nil {
	return err
}
<-s
return bot.Close()
var timeCommand = &botbot.Command{
	Name:        "time",
	Description: "returns the current time",
	Action: func(ctx *botbot.Context) error {
		now := time.Now()
		return ctx.Send(now.Format(time.RFC3339))
	},
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Commands   []*Command
	Handle     string
	AppContext map[string]interface{}
	// contains filtered or unexported fields
}

Bot for handling discord messages

func New

func New(handle, token string) (*Bot, error)

New returns a new bot

func (*Bot) Close

func (b *Bot) Close() error

Close the server

func (*Bot) Start

func (b *Bot) Start() error

Start listening and processing messages

type Command

type Command struct {
	// Name of the command
	Name string
	// Description of the command shown in help output
	Description string
	// Channel that this command is bound to
	// if no channel is specified, this command can be called
	// from any channel
	Channel string
	// Action of the command
	Action func(*Context) error
	// Subcommands
	Subcommands []*Command
}

Command for a message

type Context

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

Context of a message

func (*Context) Arg

func (c *Context) Arg(i int) string

Arg in the message

func (*Context) Attachment

func (c *Context) Attachment(i int) (io.ReadCloser, error)

Attachment reader of the message

func (*Context) Channel

func (c *Context) Channel() string

Channel name that is known to users

func (*Context) Send

func (c *Context) Send(msg string) error

Send a response to the same channel

func (*Context) Value

func (c *Context) Value(name string) interface{}

Value of a global context var

type Handler

type Handler interface {
	Run(*Context) error
}

Handler of messages

Jump to

Keyboard shortcuts

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