From 14e58f26c8a52bd9b377c6771996c774e74cf3cb Mon Sep 17 00:00:00 2001 From: Tobias Messner Date: Mon, 10 Jul 2023 01:20:11 +0200 Subject: [PATCH] Update Discord Tags on slmngg login Co-authored-by: MrLotU --- server/src/discord/auth.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/discord/auth.js b/server/src/discord/auth.js index 5c9d685f..acfe8f9c 100644 --- a/server/src/discord/auth.js +++ b/server/src/discord/auth.js @@ -1,5 +1,6 @@ const bodyParser = require("body-parser"); const fetch = require("node-fetch"); +const { updateRecord } = require("../action-utils/action-utils"); function discordEnvSet() { return ["DISCORD_CLIENT_ID", "DISCORD_CLIENT_SECRET"].every(key => !!process.env[key]) @@ -146,6 +147,11 @@ module.exports = ({ app, router, cors, Cache, io }) => { let airtable = await getAirtablePlayer(discord); + if (![discord.username, `${discord.username}#${discord.discriminator}`].includes(airtable.discord_tag)) { + const updatedUsername = discord.discriminator === "0" ? discord.username : `${discord.username}#${discord.discriminator}`; + await updateRecord(Cache, "Players", airtable, { "Discord Tag": updatedUsername }); + } + return { discord, airtable }; }