From 0127b22f69d706b21aed48663b9a8dd496aa33e7 Mon Sep 17 00:00:00 2001 From: Kyle Roth Date: Mon, 18 Sep 2023 13:54:43 +0000 Subject: [PATCH] add pre-ACME role specified by setting FinishYear to -1 --- cmd/client/upload.go | 4 +++- pkg/bouncerbot/guildinfo.go | 7 +++++++ pkg/bouncerbot/guildinfo_test.go | 13 ++++++++++--- .../testdata/TestGetGuildInfo/empty/test.log | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cmd/client/upload.go b/cmd/client/upload.go index 76cfe79..dc86e86 100644 --- a/cmd/client/upload.go +++ b/cmd/client/upload.go @@ -31,6 +31,8 @@ header below: If no data is provided on stdin, the information will be prompted for in the terminal. +The finish year may be set to -1 if the user is pre-ACME. + As users are uploaded, the name and key will be printed to stdout like this: id,name,key @@ -134,7 +136,7 @@ func promptUser(c chan<- *db.User) { //nolint:cyclop // it's not bad var err error set := false - fmt.Fprint(os.Stderr, "Finish year: ") + fmt.Fprint(os.Stderr, "Finish year (-1 for pre-ACME): ") for scanner.Scan() { u.FinishYear, err = strconv.Atoi(scanner.Text()) if err == nil { diff --git a/pkg/bouncerbot/guildinfo.go b/pkg/bouncerbot/guildinfo.go index 2a31849..00db6ab 100644 --- a/pkg/bouncerbot/guildinfo.go +++ b/pkg/bouncerbot/guildinfo.go @@ -14,6 +14,7 @@ const ( studentLeadershipRole = "student leadership" alumniBoardRole = "alumni board" newbieRole = "newbie" + preACMERole = "pre-ACME" ) // GuildInfo contains IDs necessary for the bot to interact with roles and users in the guild. @@ -25,6 +26,7 @@ type GuildInfo struct { 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"` } @@ -53,6 +55,8 @@ func GetGuildInfo(l log.Logger, roles []*discordgo.Role, guildID string) *GuildI out.AlumniBoardRole = role.ID case newbieRole: out.NewbieRole = role.ID + case preACMERole: + out.PreACMERole = role.ID } } @@ -61,6 +65,7 @@ func GetGuildInfo(l log.Logger, roles []*discordgo.Role, guildID string) *GuildI checkRoleFilled(l, out.StudentLeadershipRole, studentLeadershipRole) checkRoleFilled(l, out.AlumniBoardRole, alumniBoardRole) checkRoleFilled(l, out.NewbieRole, newbieRole) + checkRoleFilled(l, out.PreACMERole, preACMERole) return &out } @@ -99,6 +104,8 @@ func (i *GuildInfo) GetRoleIDsForUser(l log.Logger, u *db.User) []string { } else { l.Info("msg", "no role for finish year", "finishYear", u.FinishYear) } + } else if u.FinishYear == -1 { + roleIDs = append(roleIDs, i.PreACMERole) } if u.Professor { diff --git a/pkg/bouncerbot/guildinfo_test.go b/pkg/bouncerbot/guildinfo_test.go index b1083fd..5dd53f2 100644 --- a/pkg/bouncerbot/guildinfo_test.go +++ b/pkg/bouncerbot/guildinfo_test.go @@ -48,6 +48,10 @@ var ( ID: "i", Name: "newbie", } + preACMERole = discordgo.Role{ + ID: "k", + Name: "pre-ACME", + } trickyRole = discordgo.Role{ ID: "j", Name: "teehee (l00l)", @@ -68,7 +72,7 @@ func TestGetGuildInfo(t *testing.T) { "everything": { []*discordgo.Role{ &adminRole, &cohort2016, &cohort2019, &cohort2022, &profRole, &taRole, &slRole, - &boardRole, &newbieRole, + &boardRole, &newbieRole, &preACMERole, }, bouncerbot.GuildInfo{ GuildID: guildID, @@ -77,6 +81,7 @@ func TestGetGuildInfo(t *testing.T) { StudentLeadershipRole: slRole.ID, AlumniBoardRole: boardRole.ID, NewbieRole: newbieRole.ID, + PreACMERole: preACMERole.ID, RolesByYear: map[int]string{ 2016: cohort2016.ID, 2019: cohort2019.ID, 2022: cohort2022.ID, }, @@ -85,12 +90,13 @@ func TestGetGuildInfo(t *testing.T) { "missingSome": { []*discordgo.Role{ &adminRole, &cohort2016, &cohort2019, &cohort2022, &taRole, - &boardRole, + &boardRole, &preACMERole, }, bouncerbot.GuildInfo{ GuildID: guildID, TARole: taRole.ID, AlumniBoardRole: boardRole.ID, + PreACMERole: preACMERole.ID, RolesByYear: map[int]string{ 2016: cohort2016.ID, 2019: cohort2019.ID, 2022: cohort2022.ID, }, @@ -99,7 +105,7 @@ func TestGetGuildInfo(t *testing.T) { "tricky": { []*discordgo.Role{ &adminRole, &trickyRole, &profRole, &taRole, &slRole, - &boardRole, &newbieRole, + &boardRole, &newbieRole, &preACMERole, }, bouncerbot.GuildInfo{ GuildID: guildID, @@ -108,6 +114,7 @@ func TestGetGuildInfo(t *testing.T) { StudentLeadershipRole: slRole.ID, AlumniBoardRole: boardRole.ID, NewbieRole: newbieRole.ID, + PreACMERole: preACMERole.ID, }, }, } diff --git a/pkg/bouncerbot/testdata/TestGetGuildInfo/empty/test.log b/pkg/bouncerbot/testdata/TestGetGuildInfo/empty/test.log index 62d053a..f0b0244 100644 --- a/pkg/bouncerbot/testdata/TestGetGuildInfo/empty/test.log +++ b/pkg/bouncerbot/testdata/TestGetGuildInfo/empty/test.log @@ -3,3 +3,4 @@ error {"msg":"role info not found","role":"TA"} error {"msg":"role info not found","role":"student leadership"} error {"msg":"role info not found","role":"alumni board"} error {"msg":"role info not found","role":"newbie"} +error {"msg":"role info not found","role":"pre-ACME"}