2020-06-09 13:04:44 +00:00
|
|
|
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
|
|
|
|
},
|
2020-06-12 05:17:58 +00:00
|
|
|
run: func(cmd commandInit) (string, error) {
|
2020-06-09 13:04:44 +00:00
|
|
|
args := strings.Fields(cmd.message.Content)
|
|
|
|
if len(args) < 2 {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "You must give this command your application username", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sendTyping(cmd.session, cmd.message.ChannelID)
|
|
|
|
|
|
|
|
manager := mcm.NewMCM(cmd.config.MCMToken, cmd.config.MCMURL)
|
|
|
|
models := manager.NewModel()
|
|
|
|
|
2020-06-11 06:00:29 +00:00
|
|
|
players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, args[1]))
|
|
|
|
if err != nil {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "", err
|
2020-06-11 06:00:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 13:04:44 +00:00
|
|
|
apps, err := models.Application(models.NewDjangoBuilder().IExact(django.ApplicationUsername, args[1]))
|
|
|
|
if err != nil {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "", err
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 06:00:29 +00:00
|
|
|
var nickname string
|
2020-06-11 06:16:04 +00:00
|
|
|
var accepted *bool
|
2020-06-11 06:00:29 +00:00
|
|
|
if len(players) > 0 {
|
|
|
|
nickname = players[0].Username
|
2020-06-11 06:05:33 +00:00
|
|
|
if len(apps) == 0 {
|
2020-06-11 06:16:04 +00:00
|
|
|
apps, err = models.Application(models.NewDjangoBuilder().Eq(django.ApplicationID, players[0].ApplicationID))
|
2020-06-11 06:00:29 +00:00
|
|
|
if len(apps) == 0 {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "Something went wrong, please contact staff", nil
|
2020-06-11 06:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if len(apps) > 0 {
|
2020-06-11 06:16:04 +00:00
|
|
|
if apps[0].Accepted != nil && *apps[0].Accepted {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "Please join the server and then re-try this command", nil
|
2020-06-11 06:00:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "No player or applications found for that username", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
2020-06-11 06:05:33 +00:00
|
|
|
accepted = apps[0].Accepted
|
2020-06-09 13:04:44 +00:00
|
|
|
|
2020-06-11 06:16:04 +00:00
|
|
|
if accepted == nil {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "Your application is still being reviewed, hang tight", nil
|
2020-06-11 06:16:04 +00:00
|
|
|
} else if !*accepted {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "Your application was denied, good luck finding a new server", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accepted
|
2020-06-11 06:00:29 +00:00
|
|
|
if err := cmd.session.GuildMemberNickname(cmd.message.GuildID, cmd.message.Author.ID, nickname); err != nil {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "", err
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
|
|
|
if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.RegisterRole); err != nil {
|
2020-06-12 05:17:58 +00:00
|
|
|
return "", err
|
2020-06-09 13:04:44 +00:00
|
|
|
}
|
2020-06-12 05:17:58 +00:00
|
|
|
|
|
|
|
// Don't return feedback because this goes in a different channel
|
2020-06-09 13:04:44 +00:00
|
|
|
sendMessage(cmd.session, cmd.config.RegisteredChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()))
|
2020-06-12 05:17:58 +00:00
|
|
|
return "", nil
|
2020-06-09 13:04:44 +00:00
|
|
|
},
|
|
|
|
help: "Register yourself with the Discord",
|
|
|
|
}
|
|
|
|
}
|