bot

package
v0.0.0-...-229b3a6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MongoConnectionTime the time in seconds that the
	// bot has to connect to the mongo database before
	// timeingout.
	MongoConnectionTime = 10

	// MongoQueryTimeout the time in seconds that the
	// mongo database has to perform a query before it
	// times out.
	MongoQueryTimeout = 2

	// MongoPingTime is the time the mongo database has
	// to respond to a ping before
	MongoPingTime = 2

	// PingInterval is the time between each ping to check
	// that the Bot is still connected to the mongodb.
	PingInterval = 20
)

Variables

This section is empty.

Functions

func RemoveIndex

func RemoveIndex(s []string, i int) []string

RemoveIndex is just a general function which removes an item from a slice given an index.

Types

type Bot

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

Bot handels all of the incoming messages for the bot and stores all of the information for each of the discord servers

func NewBot

func NewBot(token, mongoURI string) *Bot

NewBot returns a pointer to a new instance of a Bot

func (*Bot) MonitorMongoConnection

func (b *Bot) MonitorMongoConnection(ctx context.Context) chan error

MonitorMongoConnection constantly pings the mongo database to ensure the Bot is till connected.

func (*Bot) Setup

func (b *Bot) Setup(databaseName, collectionName string) error

Setup creates a new session with the token set when the bot was created. Setup returns an error if the Bot could not connect to the discord API.

func (*Bot) Shutdown

func (b *Bot) Shutdown()

Shutdown gracefully stops the discord websocket.

func (*Bot) Start

func (b *Bot) Start() chan bool

Start the discord bot listening for messsages from all of the servers the bot is connected to. This function runs forever in a goroutine (thread) and returns a channel. The channel has a true placed in it once this function has finished (when an error has occurred).

type DiscordServer

type DiscordServer struct {
	// guildID is the unique ID given to a discord
	// server
	GuildID string `bson:"guildID"`

	// lists stores a collection of items assigned
	// to a list id.
	Lists map[string][]string `bson:"lists"`
}

DiscordServer has all of the functions that the not can perform for a server.

func NewDiscordServer

func NewDiscordServer(guildID string) *DiscordServer

NewDiscordServer returns a pointer to a DiscordServer instance.

Jump to

Keyboard shortcuts

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