coffeebeanbot

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 15 Imported by: 0

README

CoffeeBeanBot

Discord Invite GoDoc Go Report Card Build Status

coffeebeanbot is a coffee bean inspired Discord bot created to help me through my day. Its current focus is to handle "Pomodoro Technique"-style timeboxing notification.

If you simply want to use the bot, and not run your own or customize it, you can invite it to your Discord server using this link.

Use !cbb help to show the list of available commands.

Getting Started

Running using Docker

For Linux, assuming your discord.toml lives at ./secrets:

docker run -v $(pwd)/secrets:/secrets docker.pkg.github.com/seanpfeifer/coffeebeanbot/cbb:1.0.5

For Windows PowerShell, assuming your discord.toml lives at ./secrets:

docker run -v ${PWD}\secrets:/secrets docker.pkg.github.com/seanpfeifer/coffeebeanbot/cbb:1.0.5

Metrics are disabled by default (see Metrics below). If you want your container to report to Stackdriver, you need to override the Docker container's parameters to add -stackdriver:

docker run -v $(pwd)/secrets:/secrets docker.pkg.github.com/seanpfeifer/coffeebeanbot/cbb:1.0.5 -cfg /bot/cfg.toml -secrets /secrets/discord.toml -stackdriver
Installation

If you simply want to build + install the cbb binary on your own, run the following:

go get github.com/seanpfeifer/coffeebeanbot/cmd/cbb

Retrieve the package using:

go get github.com/seanpfeifer/coffeebeanbot

Build and install the cbb bot binary using:

go install github.com/seanpfeifer/coffeebeanbot/cmd/cbb
Configuration

Two files are used for configuration:

  • cfg.toml - general bot config
  • discord.toml - bot secrets that shouldn't be shared with others

Create a cfg.toml file that exists wherever you want to run the bot from.

Sample cfg.toml:

cmdPrefix = "!cbb "
workEndAudio =  "audio/airhorn.dca"

Sample discord.toml:

authToken = "PASTE_AUTH_TOKEN_HERE"
clientID = "PASTE_CLIENT_ID_HERE"

The authToken and clientID values can be found at https://discordapp.com/developers/applications/me

  • Create your App and copy the Client ID into your discord.toml.
  • Click Create a Bot User.
  • Under "App Bot User" click "click to reveal" on Token and copy the value into your discord.toml.
  • Save Changes.
  • Ensure your bot's Public Bot setting is what you want it to be.
Usage

Run the bot's cbb executable from the directory containing your cfg.toml and ./secrets/discord.toml. See the output of cbb -h for details.

Invite the bot to one of your servers via the URL https://discordapp.com/api/oauth2/authorize?client_id=CLIENT_ID_HERE&scope=bot, replacing CLIENT_ID_HERE with your client ID shown in your config.

To show the current list of commands (and your bot's invite link), use the following command after you've invited the bot to one of your servers:

!cbb help
Metrics

The following aggregated metrics can be recorded so you can tell how your service is performing:

  • connected_servers - the current number of connected servers (Discord Guilds)
  • pomodoros_running - the current number of Pomodoros actively running
  • pomodoros_started - the count of Pomodoros started

Aggregated metrics for your running servers are only ever sent to either standard output, or to your Stackdriver if you have it configured. No personal information is ever sent from this service.

To enable sending metrics to stdout, use the command-line parameter -stdoutMetrics

To enable sending metrics to your configured Stackdriver, use the command-line parameter -stackdriver

Documentation

Overview

Package coffeebeanbot is a coffee bean inspired bot created to help me through my day. Its current focus is to handle "Pomodoro Technique"-style timeboxing notification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDiscordAudio

func LoadDiscordAudio(filename string) ([][]byte, error)

LoadDiscordAudio will load a DCA file, returning the data and/or any error that occurred.

func LogIfError

func LogIfError(logger Logger, err error, msg string, extraInfo ...interface{}) bool

LogIfError will log the [error + extra info] if the error is non-nil. Returns true if err is non-nil.

Types

type Bot

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

Bot contains the information needed to run the Discord bot

func NewBot

func NewBot(config Config, secrets Secrets, logger Logger, recorder metrics.Recorder) *Bot

NewBot is how you should create a new Bot in order to assure that all initialization has been completed.

func (*Bot) Start

func (bot *Bot) Start() error

Start will start the bot, blocking until completion

type Config

type Config struct {
	CmdPrefix    string `toml:"cmdPrefix"`    // The prefix the bot will look for in chat before all known commands
	WorkEndAudio string `toml:"workEndAudio"` // The DCA audio file that will be played when a Pomodoro ends. This is only played if the user is in voice chat in the Discord Server (Guild).
}

Config is the Bot's configuration data

func LoadConfigFile

func LoadConfigFile(path string) (*Config, error)

LoadConfigFile loads the config from the given path, returning the config or an error if one occurred. I generally prefer config files over environment variables, due to the ease of setting them up as secrets in Kubernetes.

type Logger

type Logger interface {
	// Info logs a message with some additional context as key-value pairs
	Info(msg string, kvPairs ...interface{})
	// Error logs a message with some additional context as key-value pairs
	Error(msg string, kvPairs ...interface{})
	// Named adds a sub-scope to the logger's name
	Named(name string) Logger
}

Logger is the interface that all logs are expected to use with this package.

type Secrets

type Secrets struct {
	AuthToken string `toml:"authToken"` // AuthToken is all that we need to authenticate with Discord as the bot's user
	ClientID  string `toml:"clientID"`  // Used to create the invite link for the bot - this isn't necessary for Discord login, nor does it need to be "secret"
}

Secrets is the Bot's per-user data, some of which is secret

func LoadSecretsFile

func LoadSecretsFile(path string) (*Secrets, error)

LoadSecretsFile loads the Discord secrets from the given path, returning the Secrets or an error if one occurred.

Directories

Path Synopsis
cmd
cbb
Package metrics handles the aggregated stats that can be reported to a metrics exporter for bot monitoring.
Package metrics handles the aggregated stats that can be reported to a metrics exporter for bot monitoring.
Package pomodoro contains functionality for timing work tasks and calling a user-supplied callback on end or cancel.
Package pomodoro contains functionality for timing work tasks and calling a user-supplied callback on end or cancel.

Jump to

Keyboard shortcuts

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