|
|
|
@ -1,13 +1,20 @@
|
|
|
|
|
package discord
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"go.etztech.xyz/sedbot/config"
|
|
|
|
|
|
|
|
|
|
"go.etztech.xyz/go-mcm"
|
|
|
|
|
"go.etztech.xyz/go-mcm/model/django"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const bannedPlayersFile = "banned-players.json"
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
commands["register"] = command{
|
|
|
|
|
validate: func(cmd commandInit) bool {
|
|
|
|
@ -19,17 +26,19 @@ func init() {
|
|
|
|
|
return "You must give this command your application username", nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
username := args[1]
|
|
|
|
|
|
|
|
|
|
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]))
|
|
|
|
|
players, err := models.Player(models.NewDjangoBuilder().IExact(django.PlayerUsername, username))
|
|
|
|
|
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, username))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
@ -37,9 +46,20 @@ func init() {
|
|
|
|
|
var nickname string
|
|
|
|
|
var accepted *bool
|
|
|
|
|
if len(players) > 0 {
|
|
|
|
|
nickname = players[0].Username
|
|
|
|
|
player := players[0]
|
|
|
|
|
|
|
|
|
|
// Check for a ban
|
|
|
|
|
ban, err := findBan(cmd.config, player.UUID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
if ban != nil {
|
|
|
|
|
return fmt.Sprintf("You are currently banned: **%s**", ban.Reason), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nickname = player.Username
|
|
|
|
|
if len(apps) == 0 {
|
|
|
|
|
apps, err = models.Application(models.NewDjangoBuilder().Eq(django.ApplicationID, players[0].ApplicationID))
|
|
|
|
|
apps, err = models.Application(models.NewDjangoBuilder().Eq(django.ApplicationID, player.ApplicationID))
|
|
|
|
|
if len(apps) == 0 {
|
|
|
|
|
return "Something went wrong, please contact staff", nil
|
|
|
|
|
}
|
|
|
|
@ -74,3 +94,32 @@ func init() {
|
|
|
|
|
help: "Register yourself with the Discord",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Ban struct {
|
|
|
|
|
UUID string `json:"uuid"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Created string `json:"created"`
|
|
|
|
|
Source string `json:"source"`
|
|
|
|
|
Expires string `json:"expires"`
|
|
|
|
|
Reason string `json:"reason"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func findBan(cfg *config.Config, uuid string) (*Ban, error) {
|
|
|
|
|
banData, err := ioutil.ReadFile(filepath.Join(cfg.MCPath, bannedPlayersFile))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bans []*Ban
|
|
|
|
|
if err := json.Unmarshal(banData, &bans); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, ban := range bans {
|
|
|
|
|
if uuid == ban.UUID {
|
|
|
|
|
return ban, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|