bouncerbot

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bouncerbot implements the bouncer bot.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("user info not found")

ErrNotFound is returned by a Decrypter if the key did not decrypt any info.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	*discordgo.Session

	// If left blank, this info is set when the first user joins the server. Currently the bot does
	// not support serving more than one guild.
	Guild *GuildInfo
	// contains filtered or unexported fields
}

Bot assigns roles to users once they send the correct code to the bot in a DM. The correct code is determined by attempting to decrypt the names in the database using the code as the key. If the decryption is successful, the user is given the name as a server nickname and the appropriate roles are assigned.

func New

func New(l log.Logger, token string, users *db.UserTable) (*Bot, error)

New creates a new bouncer bot using the provided bot token, backed by the provided UserTable.

func NewWithDecrypter

func NewWithDecrypter(l log.Logger, token string, d Decrypter) (*Bot, error)

NewWithDecrypter sets up the bot using the provided Decrypter, instead of the default Decrypter backed with a db.UserTable.

func (*Bot) AddGuildInfoCallback

func (b *Bot) AddGuildInfoCallback(f func(*GuildInfo))

AddGuildInfoCallback ensures f will be called when the b.Guild is filled in.

type Decrypter

type Decrypter interface {
	// Decrypt attempts to decrypt any user info using the key provided. It returns ErrNotFound if
	// the key did not decrypt anything.
	Decrypt(key string) (*db.User, error)

	// Delete removes the user info after it's been decrypted and used. It should be called only
	// after the successful use of data returned by Decrypt.
	Delete(id int) error
}

Decrypter provides user information conditioned on receiving the decryption key for it.

type GuildInfo

type GuildInfo struct {
	GuildID string `json:"guild_id"`

	ProfessorRole         string `json:"professor_role"`
	TARole                string `json:"ta_role"`
	StudentLeadershipRole string `json:"student_leadership_role"`
	AlumniBoardRole       string `json:"alumni_board_role"`
	NewbieRole            string `json:"newbie_role"`
	PreACMERole           string `json:"preacme_role"`

	RolesByYear map[int]string `json:"roles_by_year"`
}

GuildInfo contains IDs necessary for the bot to interact with roles and users in the guild.

func GetGuildInfo

func GetGuildInfo(l log.Logger, roles []*discordgo.Role, guildID string) *GuildInfo

GetGuildInfo collects the guild information using the discordgo session.

func (*GuildInfo) GetRoleIDsForUser

func (i *GuildInfo) GetRoleIDsForUser(l log.Logger, u *db.User) []string

GetRoleIDsForUser returns the role IDs that the user should be given.

type TableDecrypter

type TableDecrypter struct {
	Table *db.UserTable
}

TableDecrypter implements Decrypter by using the key to attempt to decrypt all the users in the database.

func (TableDecrypter) Decrypt

func (d TableDecrypter) Decrypt(key string) (*db.User, error)

func (TableDecrypter) Delete added in v0.1.2

func (d TableDecrypter) Delete(id int) error

Jump to

Keyboard shortcuts

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