commandhelper

package module
v0.0.0-...-858d7d1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2017 License: GPL-3.0 Imports: 6 Imported by: 0

README

command-helper

A library which allows easy creation of commands for a Discord bot.

Documentation

Overview

Package commandhelper provides tools for creating command-based Discord bots

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInitialized = errors.New("bot not yet initialized, use AddHandler on Bot.ReadyHandler")
	// HelpCommand the prints the help menu
	//
	// It is bundled by default by NewBot().
	HelpCommand = Command{
		Usage:       "[command]",
		Description: "prints the help menu or given command's usage",
		Action:      HelpAction,
	}
)

Functions

func HelpAction

func HelpAction(bot Bot, args []string, s *discordgo.Session, m *discordgo.Message) error

Types

type Action

type Action func(Bot, []string, *discordgo.Session, *discordgo.Message) error

CommandAction is the type of a Command's Action

type Bot

type Bot struct {
	Name        string             // Name shown in help menu
	Description string             // Description shown in help menu
	Commands    map[string]Command // Mapping of command name to Command
	// contains filtered or unexported fields
}

Bot is the main structure of a discord bot. It is recommended to create these using NewBot

func NewBot

func NewBot() *Bot

NewBot returns a Bot with bundles HelpCommand.

func (Bot) Help

func (bot Bot) Help() string

Help returns the global help menu for a bot

func (*Bot) MessageHandler

func (bot *Bot) MessageHandler(s *discordgo.Session, m *discordgo.MessageCreate)

MessageHandler reads the configuration of bot to determine how to parse input. Feed this into AddHandler after configuring your bot.

func (*Bot) ReadyHandler

func (bot *Bot) ReadyHandler(s *discordgo.Session, r *discordgo.Ready)

ReadyHandler gives the bot data made available after opening the discordgo.Session.

Feed this into AddHandler after configuring your bot.

func (Bot) Usage

func (bot Bot) Usage(commandName string) string

Usage returns the command specific help menu for a bot.

type Command

type Command struct {
	Usage       string       // Available postional arguments shown in help menu
	Description string       // Description show in help menu
	Flags       flag.FlagSet // Custom flags for the command
	Action      Action       // Function to run if command is called
}

Command is a sub-command for a Bot.

Jump to

Keyboard shortcuts

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