Help us shape the future of Go! Take the 2026 Go Developer Survey

gerbil

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 8 Imported by: 0

README

gerbil

Release Actions Status Go Report Card Godoc

gerbil is a high level wrapper around DiscordGo designed to make the creation of Discord bots much faster.

Usage

package main

import "github.com/jamiecorrigan/gerbil"

func main() {
	config := gerbil.Config{
		name: "Ping Bot",
		token: "ENV:PING_BOT_TOKEN", // Using ENV: at the start will cause gerbil to look at env vars.
		prefix: "!",
	}
	bot := gerbil.NewBot(&config)
	bot.Start() // handles cleanup when an INT is retrieved.
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveConfigString added in v0.5.0

func ResolveConfigString(s string) (string, bool)

ResolveConfigString resolves the value of a configuration string.

Types

type Bot

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

Bot represents ALL of the state of the bot.

func NewBot

func NewBot(c *Config) *Bot

NewBot constructs a new bot.

func (*Bot) ReplyToMessage added in v0.5.0

func (b *Bot) ReplyToMessage(m *discordgo.Message, msg string)

ReplyToMessage reoplies to a message.

func (*Bot) Run

func (b *Bot) Run()

Run starts up the bot. This operation is blocking and cleanups after receiving a kill instruction.

func (*Bot) SendMessage added in v0.4.0

func (b *Bot) SendMessage(cid string, msg string)

SendMessage sends a message to a specific channel.

type Command

type Command struct {
	Name          string
	Aliases       []string
	Desc          string
	Op            func(ci CommandInput)
	Args          []CommandArg
	ApprovedRoles []string
}

Command represents a discord command.

func (*Command) Run

func (c *Command) Run(b *Bot, s *discordgo.Session, m *discordgo.MessageCreate, argString string)

Run a command.

type CommandArg added in v0.5.0

type CommandArg struct {
	Name    string
	Repeats bool
}

CommandArg represents an argument for a Command.

type CommandInput added in v0.2.0

type CommandInput struct {
	Bot     *Bot
	Session *discordgo.Session
	Message *discordgo.Message
	Args    map[string][]string
}

CommandInput represents the input to a command handler.

type Config added in v0.5.0

type Config struct {
	// public
	Name             string
	Token            string
	Commands         []Command
	Events           []Event
	EnableHelp       bool
	Prefix           string
	LoggingChannelID string
	// contains filtered or unexported fields
}

Config represents the configuration options for a bot.

func (*Config) Parse added in v0.5.0

func (c *Config) Parse() []error

Parse checks a config for errors and performs any transforms or setup required.

type Event added in v0.5.0

type Event struct {
	Message   string
	Exp       string
	ChannelID string
}

Event represents a scheduled CRON event.

type EventScheduler added in v0.5.0

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

EventScheduler represents the scheduler for CRON events.

func NewEventScheduler added in v0.5.0

func NewEventScheduler(sendFunc func(string, string), e []Event) *EventScheduler

NewEventScheduler constructs a new EventScheduler.

func (*EventScheduler) Start added in v0.5.0

func (e *EventScheduler) Start()

Start cron.

func (*EventScheduler) Stop added in v0.5.0

func (e *EventScheduler) Stop()

Stop cron.

type Logger added in v0.5.0

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

Logger represents an instance of a logger. If the bot is running and a logging channel is setup then the bot will log to that channel, otherwise it'll log to stdout.

func NewLogger added in v0.5.0

func NewLogger(session *discordgo.Session, loggingChannelID string) *Logger

NewLogger constructs a new Logger.

func (*Logger) Error added in v0.5.0

func (l *Logger) Error(err error)

Error logs an error.

func (*Logger) Output added in v0.5.0

func (l *Logger) Output(s string)

Output logs a message.

Jump to

Keyboard shortcuts

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