Skip to content

Commit

Permalink
cleanup shit code
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Jan 3, 2025
1 parent 46e82a1 commit 79690ba
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 205 deletions.
99 changes: 39 additions & 60 deletions src/commands/Community/claim-vip.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const roles = require("../../Schemas/vip/vip-roles.js");
const status = require("../../Schemas/vip/vip-status.js");
require("dotenv").config();

var timeout = [];
// TODO: MAKE THIS NOT SO SHITTY

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -28,32 +28,23 @@ module.exports = {
.setRequired(true)
),
async execute(interaction) {
if (!interaction || !interaction.user || !interaction.guild) {
return;
}

const { guild, options, user } = interaction;

const steamId = options.getString("steamid");
const code = options.getString("code");

const perkStatus = await status.findOne({ Claimer: user.id });
const perkSystem = await vip.findOne({ Guild: guild.id, ID: "vip" });

const vipCode = await uses.findOne({ Guild: guild.id, Type: "vip" });
const vipPlusCode = await uses.findOne({
Guild: guild.id,
Type: "vip+",
});
const vipPlusCode = await uses.findOne({ Guild: guild.id, Type: "vip+" });
const contributorCode = await uses.findOne({
Guild: guild.id,
Type: "contributor",
});

const vipRole = await roles.findOne({ Guild: guild.id, Type: "vip" });
const vipPlusRole = await roles.findOne({
Guild: guild.id,
Type: "vip+",
});
const vipPlusRole = await roles.findOne({ Guild: guild.id, Type: "vip+" });
const contributorRole = await roles.findOne({
Guild: guild.id,
Type: "contributor",
Expand All @@ -70,13 +61,6 @@ module.exports = {
.setTimestamp();

try {
if (timeout.includes(user)) {
return await interaction.reply({
content: `You are on a cooldown! Try again in a few seconds.`,
ephemeral: true,
});
}

if (!code || !steamId) {
return await interaction.reply({
content: "Please enter both a code and a SteamID.",
Expand Down Expand Up @@ -109,30 +93,30 @@ module.exports = {

if (!perkStatus) {
if (
code !== vipCode &&
code !== vipPlusCode &&
code !== contributorCode
code !== vipCode.Code &&
code !== vipPlusCode.Code &&
code !== contributorCode.Code
) {
embed.setDescription(`The code you entered is invalid.`);
return await interaction.reply({ embeds: [embed], ephemeral: true });
}

if (vipCode.Uses > 0 && code === vipCode) {
if (vipCode.Uses > 0 && code === vipCode.Code) {
embed.setDescription(`The code you entered has been used already.`);
return await interaction.reply({ embeds: [embed], ephemeral: true });
}
if (vipPlusCode.Uses > 0 && code === vipPlusCode) {
if (vipPlusCode.Uses > 0 && code === vipPlusCode.Code) {
embed.setDescription(`The code you entered has been used already.`);
return await interaction.reply({ embeds: [embed], ephemeral: true });
}
if (contributorCode.Uses > 0 && code === contributorCode) {
if (contributorCode.Uses > 0 && code === contributorCode.Code) {
embed.setDescription(`The code you entered has been used already.`);
return await interaction.reply({ embeds: [embed], ephemeral: true });
}

if (code === vipCode) {
let role = await guild.roles.fetch(vipRole.Role);
let perkType = "vip";
if (code === vipCode.Code) {
const role = await guild.roles.fetch(vipRole.Role);
const perkType = "vip";
await handleClaim(
interaction,
user,
Expand All @@ -143,9 +127,9 @@ module.exports = {
perkType,
role
);
} else if (code === vipPlusCode) {
let role = await guild.roles.fetch(vipPlusRole.Role);
let perkType = "vip+";
} else if (code === vipPlusCode.Code) {
const role = await guild.roles.fetch(vipPlusRole.Role);
const perkType = "vip+";
await handleClaim(
interaction,
user,
Expand All @@ -156,9 +140,9 @@ module.exports = {
perkType,
role
);
} else if (code === contributorCode) {
let role = await guild.roles.fetch(contributorRole.Role);
let perkType = "contributor";
} else if (code === contributorCode.Code) {
const role = await guild.roles.fetch(contributorRole.Role);
const perkType = "contributor";
await handleClaim(
interaction,
user,
Expand All @@ -177,24 +161,24 @@ module.exports = {
}
} else if (perkStatus) {
if (
code !== vipCode &&
code !== vipPlusCode &&
code !== contributorCode
code !== vipCode.Code &&
code !== vipPlusCode.Code &&
code !== contributorCode.Code
) {
return await interaction.reply({
content: `You've attempted to claim perks with a code that is invalid.`,
ephemeral: true,
});
}
if (perkStatus.Type === "vip" && perkStatus.Status === true) {
if (code === vipCode) {
if (code === vipCode.Code) {
await interaction.reply({
content: `You've already claimed those perks. If you want to gift, use the \`/gift\` command.`,
ephemeral: true,
});
} else if (code === vipPlusCode) {
let role = await guild.roles.fetch(vipPlusRole.Role);
let perkType = "vip+";
} else if (code === vipPlusCode.Code) {
const role = await guild.roles.fetch(vipPlusRole.Role);
const perkType = "vip+";
await handleExistingClaim(
interaction,
user,
Expand All @@ -205,10 +189,10 @@ module.exports = {
perkType,
role
);
} else if (code === contributorCode) {
let role = await guild.roles.fetch(contributorRole.Role);
let perkType = "contributor";
await handleEixistingClaim(
} else if (code === contributorCode.Code) {
const role = await guild.roles.fetch(contributorRole.Role);
const perkType = "contributor";
await handleExistingClaim(
interaction,
user,
perkSystem,
Expand All @@ -225,15 +209,15 @@ module.exports = {
});
}
} else if (perkStatus.Type === "vip+" && perkStatus.Status === true) {
if (code === vipCode || code === vipPlusCode) {
if (code === vipCode.Code || code === vipPlusCode.Code) {
await interaction.reply({
content: `You've already claimed those perks. If you want to gift, use the \`/gift\` command.`,
ephemeral: true,
});
} else if (code === contributorCode) {
let role = await guild.roles.fetch(contributorRole.Role);
let perkType = "contributor";
await handleEixistingClaim(
} else if (code === contributorCode.Code) {
const role = await guild.roles.fetch(contributorRole.Role);
const perkType = "contributor";
await handleExistingClaim(
interaction,
user,
perkSystem,
Expand All @@ -254,9 +238,9 @@ module.exports = {
perkStatus.Status === true
) {
if (
code === vipCode ||
code === vipPlusCode ||
code === contributorCode
code === vipCode.Code ||
code === vipPlusCode.Code ||
code === contributorCode.Code
) {
await interaction.reply({
content: `You've already claimed your perks. If you want to gift, use the \`/gift\` command.`,
Expand All @@ -281,11 +265,6 @@ module.exports = {
content: "An error occurred while processing your request.",
ephemeral: true,
});
} finally {
timeout.push(user);
setTimeout(() => {
timeout.shift();
}, 10000);
}
},

Expand Down Expand Up @@ -321,7 +300,7 @@ module.exports = {
);
await user.roles.add(role);
if (perkType === "vip+" || perkType === "contributor") {
let role2 = await guild.roles.fetch(vipRole.Role);
const role2 = await guild.roles.fetch(vipRole.Role);
await user.roles.add(role2);
}
await interaction.reply({ embeds: [embed], ephemeral: true });
Expand Down
126 changes: 63 additions & 63 deletions src/commands/System/set-vip-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,107 +25,107 @@ module.exports = {
.setRequired(false)
),
async execute(interaction) {
const guild = interaction.guild;
const vipCode = interaction.options.getString("code-vip");
const vipPlusCode = interaction.options.getString("code-vip-plus");
const contributorCode = interaction.options.getString("code-contributor");

const data = await schema.findOne({ Guild: guild.id });

if (
!interaction.member.permissions.has(PermissionFlagsBits.Administrator)
) {
return await interaction.reply({
content: "You don't have perms to use this command.",
content: "You don't have permissions to use this command.",
ephemeral: true,
});
}

const { guild } = interaction;
const codeVip = interaction.options.getString("code-vip");
const codeVipPlus = interaction.options.getString("code-vip-plus");
const codeContributor = interaction.options.getString("code-contributor");
const data = await schema.findOne({ Guild: guild.id });

try {
if (!data) {
if (codeVip) {
if (vipCode) {
await schema.create({
Guild: guild.id,
Code: codeVip,
Code: vipCode,
Type: "vip",
Uses: 0,
});
}
if (codeVipPlus) {
if (vipPlusCode) {
await schema.create({
Guild: guild.id,
Code: codeVipPlus,
Code: vipPlusCode,
Type: "vip+",
Uses: 0,
});
}
if (codeContributor) {
if (contributorCode) {
await schema.create({
Guild: guild.id,
Code: codeContributor,
Code: contributorCode,
Type: "contributor",
Uses: 0,
});
} else {
await interaction.reply({
content: `No code has been set.`,
return interaction.reply({
content: "No code has been set.",
ephemeral: true,
});
}
await interaction.reply({
return await interaction.reply({
content: "Codes have been set.",
ephemeral: true,
});
}
if (data) {
if (codeVip) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "vip",
},
{
Code: codeVip,
Uses: 0,
}
);
}
if (codeVipPlus) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "vip+",
},
{
Code: codeVipPlus,
Uses: 0,
}
);
}
if (codeContributor) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "contributor",
},
{
Code: codeContributor,
Uses: 0,
}
);
} else {
await interaction.reply({
content: `No code has been set.`,
ephemeral: true,
});
}
await interaction.reply({
content: `Codes have been updated.`,

if (vipCode) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "vip",
},
{
Code: vipCode,
Uses: 0,
}
);
}
if (vipPlusCode) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "vip+",
},
{
Code: vipPlusCode,
Uses: 0,
}
);
}
if (contributorCode) {
await schema.findOneAndUpdate(
{
Guild: guild.id,
Type: "contributor",
},
{
Code: contributorCode,
Uses: 0,
}
);
} else {
return await interaction.reply({
content: "No code has been set.",
ephemeral: true,
});
}
} catch (err) {
console.error("Error executing command:", err);
await interaction.reply({
return await interaction.reply({
content: "Codes have been updated.",
ephemeral: true,
});
} catch (error) {
console.error("Error executing command:", error);
return await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
Expand Down
Loading

0 comments on commit 79690ba

Please sign in to comment.