This commit introduces a new feature for global role synchronization in Discord, allowing for periodic reconciliation of managed roles. A new environment variable, `DISCORD_GLOBAL_SYNC_INTERVAL`, has been added to configure the synchronization interval, defaulting to 5 minutes. The `RoleWorker` has been updated to schedule global sync jobs, ensuring that missing managed roles are restored and extra assignments are removed without affecting unrelated server roles. Database schema changes support the new synchronization logic, and tests have been added to validate the functionality of the global reconciliation process.
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package application
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"mixmaker/backend/internal/domain"
|
|
)
|
|
|
|
const (
|
|
DiscordRoleScopeGlobal = "global"
|
|
DiscordRoleScopeEvent = "event"
|
|
|
|
DiscordRoleKindTank = "tank"
|
|
DiscordRoleKindDamage = "damage"
|
|
DiscordRoleKindSupport = "support"
|
|
DiscordRoleKindTeam = "team"
|
|
DiscordRoleKindCaptain = "captain"
|
|
DiscordRoleKindRegistered = "registered"
|
|
DiscordRoleKindGoing = "going"
|
|
DiscordRoleKindMaybe = "maybe"
|
|
DiscordRoleKindNotGoing = "not_going"
|
|
|
|
DiscordRoleActionReconcile = "reconcile"
|
|
DiscordRoleActionRSVP = "rsvp"
|
|
DiscordRoleActionFullReconcile = "full_reconcile"
|
|
DiscordRoleActionTeardown = "teardown"
|
|
)
|
|
|
|
type DiscordManagedRole struct {
|
|
Scope string
|
|
EventID string
|
|
TeamID string
|
|
Kind string
|
|
DiscordRoleID string
|
|
RoleName string
|
|
Hoist bool
|
|
}
|
|
|
|
type DiscordRoleSyncJob struct {
|
|
ID int64
|
|
EventID string
|
|
Action string
|
|
Generation int64
|
|
RoleSnapshot []string
|
|
Attempts int
|
|
}
|
|
|
|
type DiscordRoleRoster struct {
|
|
Roster domain.RosterDraft
|
|
PlayerDiscordIDs map[string]string
|
|
}
|
|
|
|
type DiscordRoleRegistration struct {
|
|
Event domain.Event
|
|
Registrations []domain.RSVP
|
|
PlayerDiscordIDs map[string]string
|
|
}
|
|
|
|
type DiscordRoleStore interface {
|
|
SeedDiscordRoleSyncJobs(context.Context) error
|
|
ScheduleGlobalDiscordRoleSync(context.Context, int64) error
|
|
ClaimDiscordRoleSyncJob(context.Context) (DiscordRoleSyncJob, error)
|
|
CompleteDiscordRoleSyncJob(context.Context, int64, string) error
|
|
RetryDiscordRoleSyncJob(context.Context, int64, string, time.Time) error
|
|
ListDiscordManagedRoles(context.Context, string) ([]DiscordManagedRole, error)
|
|
ListAllDiscordManagedRoles(context.Context) ([]DiscordManagedRole, error)
|
|
UpsertDiscordManagedRole(context.Context, DiscordManagedRole) error
|
|
DeleteDiscordManagedRole(context.Context, DiscordManagedRole) error
|
|
ListDiscordRoleAssignments(context.Context, string) ([]string, error)
|
|
UpsertDiscordRoleAssignment(context.Context, string, string) error
|
|
DeleteDiscordRoleAssignment(context.Context, string, string) error
|
|
SetDiscordRoleAssignments(context.Context, string, []string) error
|
|
GetDiscordRoleRoster(context.Context, string) (DiscordRoleRoster, error)
|
|
ListActiveDiscordRoleRosters(context.Context) ([]DiscordRoleRoster, error)
|
|
GetDiscordRoleRegistration(context.Context, string) (DiscordRoleRegistration, error)
|
|
ListActiveDiscordRoleRegistrations(context.Context) ([]DiscordRoleRegistration, error)
|
|
}
|