Add force link/unlink commands
This commit is contained in:
parent
3bb32e1352
commit
a06d532ff1
|
@ -7,24 +7,20 @@ const execute = async (interaction) => {
|
||||||
if (!discordID) return interaction.reply({ content: "You must provide a Discord User", ephemeral: true });
|
if (!discordID) return interaction.reply({ content: "You must provide a Discord User", ephemeral: true });
|
||||||
if (!robloxId) return interaction.reply({ content: "You must provide a Roblox ID", ephemeral: true });
|
if (!robloxId) return interaction.reply({ content: "You must provide a Roblox ID", ephemeral: true });
|
||||||
try {
|
try {
|
||||||
const connection = await pool.getConnection();
|
const [user] = await pool.query('SELECT * FROM users WHERE discordId = ?', [discordID]);
|
||||||
const [rows] = await connection.query("SELECT * FROM users WHERE robloxId = ?", [robloxId]);
|
if (user) return interaction.reply({ content: "This user is already linked to an account. Unlink before proceeding.", ephemeral: true });
|
||||||
|
|
||||||
if (rows.length === 0) {
|
const [row] = await pool.query('SELECT * FROM users WHERE robloxId = ?', [robloxId]);
|
||||||
await connection.query("INSERT INTO users (robloxId, discordId) VALUES (?, ?)", [robloxId, discordID]);
|
if (!row) {
|
||||||
|
await pool.query('INSERT INTO users (robloxId, discordId) VALUES (?, ?)', [robloxId, discordID]);
|
||||||
|
return interaction.reply({ content: "Successfully linked accounts", ephemeral: true });
|
||||||
|
} else if (row.discordId && row.discordId !== discordID) {
|
||||||
|
return interaction.reply({ content: "This Roblox ID is already linked to another account", ephemeral: true });
|
||||||
} else {
|
} else {
|
||||||
const user = rows[0];
|
await pool.query('UPDATE users SET discordId = ? WHERE robloxId = ?', [discordID, robloxId]);
|
||||||
if (!user.discordId) {
|
|
||||||
await connection.query("UPDATE users SET discordId = ? WHERE robloxId = ?", [discordID, robloxId]);
|
|
||||||
} else if (user.discordId !== discordID) {
|
|
||||||
await connection.query("UPDATE users SET discordId = NULL WHERE discordId = ?", [discordID]);
|
|
||||||
await connection.query("UPDATE users SET discordId = ? WHERE robloxId = ?", [discordID, robloxId]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.release();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
log.error(error);
|
||||||
return interaction.reply({ content: "An error occurred while linking your account", ephemeral: true });
|
return interaction.reply({ content: "An error occurred while linking your account", ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
commands/forceunlink.js
Normal file
14
commands/forceunlink.js
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
const client = global.discord_client
|
||||||
|
const pool = global.db_pool;
|
||||||
|
|
||||||
|
const execute = async (interaction) => {
|
||||||
|
const robloxId = interaction.options.getNumber("roblox-id");
|
||||||
|
const discordID = interaction.options.getUser("discord-id")?.id;
|
||||||
|
if (discordID) await pool.query("UPDATE users SET discordId = NULL WHERE discordId = ?", [discordID]);
|
||||||
|
if (robloxId) await pool.query("UPDATE users SET discordId = NULL WHERE robloxId = ?", [robloxId]);
|
||||||
|
return interaction.reply({ content: "Successfully unlinked accounts (If either were linked)", ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const noop = () => { };
|
||||||
|
|
||||||
|
module.exports = { execute: noop }
|
Loading…
Reference in a new issue