Add more validation to register
Signed-off-by: Etzelia <etzelia@hotmail.com>rate-insult
parent
9fc6b4e99c
commit
7531e1c8af
|
@ -25,21 +25,44 @@ func init() {
|
|||
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("no application found with that username")
|
||||
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")
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.RegisterRole); err != nil {
|
||||
|
|
Loading…
Reference in New Issue