Skip to content

Commit

Permalink
Improve regex of team selection logic
Browse files Browse the repository at this point in the history
Having a team such as "test-team-2025" would cause an issue where the regex would presume that because the word "team" was in it, that there was no need to prepend the "Team: " string. This resolves that issue by more strictly checking at the beginning of the string.
  • Loading branch information
duckfullstop committed Jan 3, 2025
1 parent 1c05c14 commit 1ebc664
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func validateUserCanJoinRole(s *discordgo.Session, u *discordgo.User, guild stri
if err != nil {
return err
}
getRoleName := regexp.MustCompile(`(?i)(?:team):* ?(.*)`)
getRoleName := regexp.MustCompile(`(?i)^(?:Team):* ?(.*)`)
roleName := getRoleName.FindAllStringSubmatch(role.Name, -1)
// role names get normalized to lower case during the lookup only
if roleName != nil && strings.ToLower(roleName[0][1]) == strings.ToLower(targetRole) {
Expand All @@ -212,7 +212,7 @@ func validateUserCanJoinRole(s *discordgo.Session, u *discordgo.User, guild stri

func createOrReturnRole(s *discordgo.Session, guild string, rname string) (v *discordgo.Role, err error) {
roles, err := s.GuildRoles(guild)
getRole := regexp.MustCompile(`(?i)(?:team):*`)
getRole := regexp.MustCompile(`(?i)^(?:Team):*`)
if !getRole.MatchString(rname) {
rname = fmt.Sprintln("Team:", rname)
}
Expand Down

0 comments on commit 1ebc664

Please sign in to comment.