package discord import ( "fmt" "strings" "go.etztech.xyz/go-mcm" "go.etztech.xyz/go-mcm/model/django" ) func init() { commands["register"] = command{ validate: func(cmd commandInit) bool { return len(cmd.message.Member.Roles) == 0 }, run: func(cmd commandInit) (string, error) { args := strings.Fields(cmd.message.Content) if len(args) < 2 { return "You must give this command your application username", nil } sendTyping(cmd.session, cmd.message.ChannelID) manager := mcm.NewMCM(cmd.config.MCMToken, cmd.config.MCMURL) models := manager.NewModel() players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, args[1])) if err != nil { return "", err } apps, err := models.Application(models.NewDjangoBuilder().IExact(django.ApplicationUsername, args[1])) if err != nil { return "", err } var nickname string var accepted *bool if len(players) > 0 { nickname = players[0].Username if len(apps) == 0 { apps, err = models.Application(models.NewDjangoBuilder().Eq(django.ApplicationID, players[0].ApplicationID)) if len(apps) == 0 { return "Something went wrong, please contact staff", nil } } } 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 } } else { return "No player or applications found for that username", nil } accepted = apps[0].Accepted if accepted == nil { return "Your application is still being reviewed, hang tight", nil } else if !*accepted { return "Your application was denied, good luck finding a new server", nil } // Accepted 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 { 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) return "", nil }, help: "Register yourself with the Discord", } }