From 1ebc664f1f8f3c1f5dd2c5323ea79132222c47ff Mon Sep 17 00:00:00 2001 From: "duck." Date: Fri, 3 Jan 2025 00:03:56 +0000 Subject: [PATCH] Improve regex of team selection logic 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. --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 5df0d8f..247c6e3 100644 --- a/main.go +++ b/main.go @@ -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) { @@ -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) }