From ef9563563987605084f74e79dee817c8786c9ade Mon Sep 17 00:00:00 2001 From: Etzelia Date: Tue, 20 Jul 2021 18:54:08 -0500 Subject: [PATCH] Add Discord sync to register Signed-off-by: Etzelia --- discord/register.go | 14 +++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/discord/register.go b/discord/register.go index e1fb0e4..1fdccc9 100644 --- a/discord/register.go +++ b/discord/register.go @@ -10,6 +10,7 @@ import ( "git.canopymc.net/Etzelia/canopeas/config" "git.canopymc.net/Etzelia/go-mcm" + "git.canopymc.net/Etzelia/go-mcm/model" "git.canopymc.net/Etzelia/go-mcm/model/django" ) @@ -45,8 +46,9 @@ func init() { } var nickname string + var player *model.Player if len(players) > 0 { - player := players[0] + player = players[0] // Check for a ban ban, err := findBan(cmd.config, player.UUID) @@ -103,6 +105,16 @@ func init() { if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.Register.Role); err != nil { return "", err } + if player != nil { + player.DiscordID = cmd.message.Author.ID + if status, err := player.Save(); err != nil { + var msg string + if status != nil { + msg = status.Message + } + return msg, err + } + } // Don't return feedback because this goes in a different channel sendMessage(cmd.session, cmd.config.Register.WelcomeChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()), false) diff --git a/go.mod b/go.mod index 2e0b0b8..0b0e93b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451 - git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0 + git.canopymc.net/Etzelia/go-mcm v0.0.0-20210720234332-05b38710c5fc git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304 git.canopymc.net/Etzelia/inspiro v0.0.3-0.20210713233035-ffd88077147f gitea.com/jolheiser/gojang v0.0.7 diff --git a/go.sum b/go.sum index 8b1ea55..47b4979 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451 h1:EbxWDS7sOyxv8einE7ps8WsywvlFqyKp3vdvk4PYVw4= git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451/go.mod h1:bgGHtcoYFmNIFgcU4P2LwqANZsJxoygnLI0C6OWE/U4= -git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0 h1:UrwR0Ap4sjoRDfbi/ow76OeBAR9pI+BFKMYU6Jj9EtU= -git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0/go.mod h1:M9yjY5mBSK5vGVPru7RG6K5bUfoRH7dTtyQ+MCuJ33g= +git.canopymc.net/Etzelia/go-mcm v0.0.0-20210720234332-05b38710c5fc h1:OQh94kGqMOE6WFbAyhCRshoQfR/TO/+UkxR1KCIUvaI= +git.canopymc.net/Etzelia/go-mcm v0.0.0-20210720234332-05b38710c5fc/go.mod h1:M9yjY5mBSK5vGVPru7RG6K5bUfoRH7dTtyQ+MCuJ33g= git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304 h1:gBzoEToJCO1nKbfhfzhGMgSWY6szwDbA8doVmPr3SIY= git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304/go.mod h1:U0H8WgtAzR+L+65odnpUH1lT6z7ylcG6R9keOOTG+fk= git.canopymc.net/Etzelia/inspiro v0.0.3-0.20210713233035-ffd88077147f h1:CupD+6/4Vrx0fGDIFf+cu8ponr19or3bCzkPPQXmRJk=