From 06e5003d78a7768c0eb0d831776b0de922e4a3fc Mon Sep 17 00:00:00 2001 From: Etzelia Date: Fri, 9 Jul 2021 15:17:17 -0500 Subject: [PATCH] Add config for register URL and check for dupes Signed-off-by: Etzelia --- config/canopeas.example.toml | 16 ++++++++++------ config/config.go | 24 +++++++++++++----------- discord/register.go | 22 ++++++++++++++++++---- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/config/canopeas.example.toml b/config/canopeas.example.toml index f01f229..471a13a 100644 --- a/config/canopeas.example.toml +++ b/config/canopeas.example.toml @@ -13,12 +13,6 @@ mc_path = "/home/minecraft/server/" # fired_role is to check how many time Carolyn has been fired fired_role = "0" -# register_role is the role to assign to a user after registering -register_role = "0" - -# registered_channel is the channel to message to welcome the newly registered user -registered_channel = "0" - # leave_channel is the channel to post leave messages to leave_channel = "0" @@ -31,6 +25,16 @@ meme_rate = "0" # Imgur Client ID imgur_client_id = "" +# welcome_channel is the channel to message to welcome the newly registered user +welcome_channel = "0" + +[register] +# role is the role to assign to a user after registering +role = "0" + +# url is the URL to show to new users +url = "https://google.com" + # ServerAPI options [serverapi] # API endpoint diff --git a/config/config.go b/config/config.go index 73101a0..a37a0a4 100644 --- a/config/config.go +++ b/config/config.go @@ -35,17 +35,19 @@ type Config struct { AccessToken string `toml:"access_token"` AccessSecret string `toml:"access_secret"` } `toml:"twitter"` - - StaffRoles []string `toml:"staff_roles"` - Echoes []Echo `toml:"echoes"` - Albums []Album `toml:"albums"` - MessageRoles []MessageRole `toml:"message_roles"` - RegisterRole string `toml:"register_role"` - RegisteredChannel string `toml:"registered_channel"` - LeaveChannel string `toml:"leave_channel"` - FiredRole string `toml:"fired_role"` - MemeRate string `toml:"meme_rate"` - Insult struct { + StaffRoles []string `toml:"staff_roles"` + Echoes []Echo `toml:"echoes"` + Albums []Album `toml:"albums"` + MessageRoles []MessageRole `toml:"message_roles"` + Register struct { + URL string `toml:"url"` + Role string `toml:"role"` + } `toml:"register"` + WelcomeChannel string `toml:"welcome_channel"` + LeaveChannel string `toml:"leave_channel"` + FiredRole string `toml:"fired_role"` + MemeRate string `toml:"meme_rate"` + Insult struct { Targets []string `toml:"targets"` Comparisons []string `toml:"comparisons"` Adjectives []string `toml:"adjectives"` diff --git a/discord/register.go b/discord/register.go index 7a4a3e3..3930057 100644 --- a/discord/register.go +++ b/discord/register.go @@ -69,7 +69,7 @@ func init() { } } else if len(apps) > 0 { if apps[0].Accepted != nil && *apps[0].Accepted { - return "Please join the server and then re-try this command", nil + return fmt.Sprintf("Please join the server at `%s` and then re-try this command", cmd.config.Register.URL), nil } } else { return "No player or applications found for that username", nil @@ -82,16 +82,30 @@ func init() { return "Your application was denied, good luck finding a new server", nil } - // Accepted + // Accepted, check for dupe user + guild, err := cmd.session.State.Guild(cmd.message.GuildID) + if err != nil { + return "", err + } + for _, member := range guild.Members { + nick := member.Nick + if nick == "" { + } + nick = member.User.Username + if strings.EqualFold(nickname, nick) { + return "A member with that name already exists in this Discord. Please contact staff.", nil + } + } + if err := cmd.session.GuildMemberNickname(cmd.message.GuildID, cmd.message.Author.ID, nickname); err != nil { return "", err } - if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.RegisterRole); err != nil { + if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.Register.Role); err != nil { return "", err } // Don't return feedback because this goes in a different channel - sendMessage(cmd.session, cmd.config.RegisteredChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()), false) + sendMessage(cmd.session, cmd.config.WelcomeChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()), false) return "", nil }, help: "Register yourself with the Discord",