Add more validation to register

Signed-off-by: Etzelia <etzelia@hotmail.com>
rate-insult
Etzelia 2020-06-11 01:00:29 -05:00
parent 9fc6b4e99c
commit 7531e1c8af
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
1 changed files with 27 additions and 4 deletions

View File

@ -25,21 +25,44 @@ func init() {
manager := mcm.NewMCM(cmd.config.MCMToken, cmd.config.MCMURL) manager := mcm.NewMCM(cmd.config.MCMToken, cmd.config.MCMURL)
models := manager.NewModel() 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])) apps, err := models.Application(models.NewDjangoBuilder().IExact(django.ApplicationUsername, args[1]))
if err != nil { if err != nil {
return err return err
} }
if len(apps) == 0 { var nickname string
return errors.New("no application found with that username") 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 !apps[0].Accepted { if !accepted {
return errors.New("sorry, your application was denied") return errors.New("sorry, your application was denied")
} }
// Accepted // Accepted
if err := cmd.session.GuildMemberNickname(cmd.message.GuildID, cmd.message.Author.ID, apps[0].Username); err != nil { if err := cmd.session.GuildMemberNickname(cmd.message.GuildID, cmd.message.Author.ID, nickname); err != nil {
return err 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.RegisterRole); err != nil {