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

gerbil

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: MIT Imports: 9 Imported by: 0

README

gerbil

Release Actions Status Go Report Card Godoc

gerbil is a framework designed to help you create and orchestrate discord bots. It can be used in one of two main ways.

Single Bot Use

To use gerbil to create a single bot you can just create your own go file that creates a new gerbil bot.

package main

import "github.com/jamiecorrigan/gerbil"

func main() {
	bot := gerbil.NewBot(token, []*gerbil.Command{
		&gerbil.Command{
			Name:        "ping",
			Description: "Returns a response from the bot. Used to check if the bot is running.",
			Op: func(s *discordgo.Session, m *discordgo.MessageCreate) { 
        s.ChannelMessageSend(m.ChannelID, "Pong.")
      },
		},
	})
  
  bot.Start()
}
Controller Use

To use the full power of gerbil you should use the controller. This allows you to orchestrate your bots and also allow them to easily communicate with each other. It even provides it's own database!

package main

import (
  "github.com/jamiecorrigan/gerbil"
  "github.com/example/mybot1"
  "github.com/example/mybot2"
  "github.com/example/mybot3"
)

func main() {
	var ctrl = gerbil.NewController()
	ctrl.RegisterBot("mybot1", mybot1.New("key_1")
	ctrl.RegisterBot("mybot2", mybot2.New("key_2")
	ctrl.RegisterBot("mybot3", mybot3.New("key_3")
	ctrl.StartBots()
}

Documentation

Index

Constants

View Source
const MAX_ITER = 100

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Running     bool
	HelpEnabled bool
	Prefix      string

	ChannelIDs map[string]string
	// contains filtered or unexported fields
}

func NewBot

func NewBot(s BotSettings) *Bot

func (*Bot) GetHelpString

func (b *Bot) GetHelpString() string

func (*Bot) LogError added in v0.3.0

func (b *Bot) LogError(err error)

func (*Bot) LogString added in v0.3.0

func (b *Bot) LogString(s string)

func (*Bot) Run

func (b *Bot) Run()

func (*Bot) SendMessage added in v0.4.0

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

func (*Bot) Stop

func (b *Bot) Stop()

type BotSettings added in v0.3.0

type BotSettings struct {
	Token            string
	Prefix           string
	Commands         []*Command
	Handlers         []interface{}
	ChannelIDs       map[string]string
	CronMessages     []CronMessage
	LoggingChannelID string
}

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Op          func(ci CommandInput)
	ArgNames    []string
}

func (*Command) Run

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

type CommandInput added in v0.2.0

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

type Controller

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

func NewController

func NewController() *Controller

func (*Controller) HasBotsRunning

func (c *Controller) HasBotsRunning() bool

func (*Controller) RegisterBot

func (c *Controller) RegisterBot(key string, b *Bot)

func (*Controller) RunBot

func (c *Controller) RunBot(key string)

func (*Controller) RunBots

func (c *Controller) RunBots()

func (*Controller) Start

func (c *Controller) Start()

func (*Controller) StopBot

func (c *Controller) StopBot(key string)

func (*Controller) StopBots

func (c *Controller) StopBots()

type CronHandler added in v0.4.0

type CronHandler struct {
	Messages []*CronMessage
	// contains filtered or unexported fields
}

func NewCronHandler added in v0.4.0

func NewCronHandler(b *Bot) *CronHandler

func (*CronHandler) AddMessage added in v0.4.0

func (c *CronHandler) AddMessage(m CronMessage)

func (*CronHandler) AddMessages added in v0.4.0

func (c *CronHandler) AddMessages(m []CronMessage)

func (*CronHandler) LogEntries added in v0.4.0

func (c *CronHandler) LogEntries()

func (*CronHandler) Start added in v0.4.0

func (c *CronHandler) Start()

func (*CronHandler) Stop added in v0.4.0

func (c *CronHandler) Stop()

type CronMessage added in v0.2.0

type CronMessage struct {
	Message   string
	Exp       string
	ChannelID string
}

type Queue

type Queue struct {
	Running bool
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue() Queue

func (*Queue) Enqueue

func (q *Queue) Enqueue(n *QueueNode)

type QueueNode

type QueueNode struct {
	FuncKey string
	FuncRef func()
}

Jump to

Keyboard shortcuts

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