Skip to content

Commit

Permalink
add pre-ACME role
Browse files Browse the repository at this point in the history
specified by setting FinishYear to -1
  • Loading branch information
kylrth committed Sep 18, 2023
1 parent b3f63be commit 0127b22
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/client/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/bouncerbot/guildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
}
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions pkg/bouncerbot/guildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -108,6 +114,7 @@ func TestGetGuildInfo(t *testing.T) {
StudentLeadershipRole: slRole.ID,
AlumniBoardRole: boardRole.ID,
NewbieRole: newbieRole.ID,
PreACMERole: preACMERole.ID,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/bouncerbot/testdata/TestGetGuildInfo/empty/test.log
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

0 comments on commit 0127b22

Please sign in to comment.