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

gerbil

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2019 License: MIT Imports: 7 Imported by: 0

README

gerbil

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
	// contains filtered or unexported fields
}

func NewBot

func NewBot(token string, prefix string, commands []*Command, handlers []interface{}) *Bot

func (*Bot) GetHelpString

func (b *Bot) GetHelpString() string

func (*Bot) Run

func (b *Bot) Run()

func (*Bot) Stop

func (b *Bot) Stop()

type Command

type Command struct {
	Name        string
	Aliases     []string
	Description string
	Op          func(b *Bot, s *discordgo.Session, m *discordgo.MessageCreate)
}

func (*Command) Run

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

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 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