package discord import ( "errors" "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) error { args := strings.Fields(cmd.message.Content) if len(args) < 2 { return errors.New("you must give this command your application username") } 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 { accepted = apps[0].Accepted } else { apps, err = models.Application(models.NewDjangoBuilder().Exact(django.ApplicationID, fmt.Sprintf("%d", players[0].ApplicationID))) if len(apps) == 0 { return errors.New("something hecked up, please contact staff") } accepted = apps[0].Accepted } } else if len(apps) > 0 { accepted = apps[0].Accepted if accepted { return errors.New("please join the server and then re-try this command") } } else { return errors.New("no player or applications found for that username") } if !accepted { return errors.New("sorry, your application was denied") } // 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 } sendMessage(cmd.session, cmd.config.RegisteredChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention())) return nil }, help: "Register yourself with the Discord", } }