csufbot

package
v0.0.0-...-4c137d3 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrNotFound can be returned if storers can't find the requested resource.

Functions

func GuildsCourses

func GuildsCourses(store Store, out map[discord.GuildID][]Course) error

GuildsCourses searches for the enrolled courses of each guild. It writes directly to the given output map. Guilds that cannot be found will be set to nil.

func SortCoursesByName

func SortCoursesByName(courses []Course)

SortCourses sorts the given list of courses alphabetically.

Types

type Course

type Course struct {
	lms.Course
	ServiceHost lms.Host
}

Course represents a course with a service host string attached to it to identify its source.

func MapCoursesToList

func MapCoursesToList(courseMap map[lms.CourseID]Course) []Course

MapCoursesToList converts a map of courses to its list. The order of the returned list is undefined.

type CourseStorer

type CourseStorer interface {
	// Course gets a single course.
	Course(id lms.CourseID) (*Course, error)
	// Courses searches in bulk for the given output map of course IDs to
	// courses.
	Courses(out map[lms.CourseID]Course) error
	// UpsertCourses updates or inserts the given list of courses into the
	// database.
	UpsertCourses(courses ...Course) error
}

CourseStorer stores an internal database state of known courses.

type Guild

type Guild struct {
	ID discord.GuildID
	// RoleMap maps each course to its appropriate role.
	RoleMap map[lms.CourseID]discord.RoleID
}

Guild contains per-guild relationships.

func (Guild) CourseMap

func (g Guild) CourseMap() map[discord.RoleID]lms.CourseID

CourseMap constructs a backwards-lookup map to look up courses from roles.

func (Guild) Courses

func (g Guild) Courses(store CourseStorer) (map[lms.CourseID]Course, error)

Courses returns a map of courses registered with the guild.

type GuildStorer

type GuildStorer interface {
	// Guild gets a guild.
	Guild(id discord.GuildID) (*Guild, error)
	// AddCourses adds courses into the guild wherein each course must be mapped
	// to a role. The courses must already be added into the database through
	// CourseStorer.
	SetCourses(guild discord.GuildID, roleMap map[lms.CourseID]discord.RoleID) error
}

GuildStorer stores guild relationships and states.

type Store

type Store struct {
	Users   UserStorer
	Guilds  GuildStorer
	Courses CourseStorer
}

Store contains database store interfaces. These store interfaces may optionally implement io.Closer.

func (Store) Close

func (s Store) Close() error

Close tries to close the backing store.

type User

type User struct {
	ID discord.UserID
	// Services is the list of services that the user has previously synced
	// with.
	Services []UserInService
}

User describes per-user data and relationships. Note that a user does not have to be guild-specific.

func (User) LastSynced

func (u User) LastSynced(host lms.Host) time.Time

LastSynced returns the last synced time of the user's service. It returns a zero-value time if the user has never synced with the given service.

type UserInService

type UserInService struct {
	lms.User
	// Enrolled contains a list of course IDs that the user is enrolled in.
	Enrolled []lms.CourseID
	// ServiceHost is the service host that this information is from.
	ServiceHost lms.Host
	// LastSynced is the last time this information was synced.
	LastSynced time.Time
}

UserInService describes the user in a service.

type UserStorer

type UserStorer interface {
	// User gets a user.
	User(id discord.UserID) (*User, error)
	// Sync synchronizes the given list of courses and the user information from
	// the service with the database.
	Sync(id discord.UserID, svc UserInService) error
}

UserStorer stores an internal database of users and their relationships.

Directories

Path Synopsis
lms
Package lms provides common interfaces for different authentication methods for a Learning Management System.
Package lms provides common interfaces for different authentication methods for a Learning Management System.

Jump to

Keyboard shortcuts

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