♻️ remove all comments

This commit is contained in:
Axel Olausson Holtenäs 2022-04-30 16:59:58 +02:00
parent 4af0cf7250
commit 5e6e8b3823
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA

View file

@ -1,9 +1,7 @@
// Dependencies
import { CommandInteraction } from "discord.js"; import { CommandInteraction } from "discord.js";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import axios from "axios"; import axios from "axios";
// Configurations
import { import {
successColor, successColor,
errorColor, errorColor,
@ -11,19 +9,15 @@ import {
footerIcon, footerIcon,
} from "@config/embed"; } from "@config/embed";
// Handlers
import logger from "@logger"; import logger from "@logger";
import encryption from "@handlers/encryption"; import encryption from "@handlers/encryption";
// Helpers
import pluralize from "@helpers/pluralize"; import pluralize from "@helpers/pluralize";
// Models
import apiSchema from "@schemas/api"; import apiSchema from "@schemas/api";
import fetchUser from "@helpers/fetchUser"; import fetchUser from "@helpers/fetchUser";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
// Function
export default { export default {
meta: { guildOnly: true, ephemeral: true }, meta: { guildOnly: true, ephemeral: true },
@ -40,10 +34,8 @@ export default {
execute: async (interaction: CommandInteraction) => { execute: async (interaction: CommandInteraction) => {
const { options, guild, user, client } = interaction; const { options, guild, user, client } = interaction;
// Get options
const optionAmount = options?.getInteger("amount"); const optionAmount = options?.getInteger("amount");
// If amount is null
if (optionAmount === null) { if (optionAmount === null) {
logger?.verbose(`Amount is null.`); logger?.verbose(`Amount is null.`);
@ -67,17 +59,14 @@ export default {
return logger?.verbose(`Guild is null`); return logger?.verbose(`Guild is null`);
} }
// Get user object
const userDB = await fetchUser(user, guild); const userDB = await fetchUser(user, guild);
if (userDB === null) { if (userDB === null) {
return logger?.verbose(`User is null`); return logger?.verbose(`User is null`);
} }
// Get DM user object
const dmUser = client?.users?.cache?.get(user?.id); const dmUser = client?.users?.cache?.get(user?.id);
// Stop if amount or user credits is below 100
if ((optionAmount || userDB?.credits) < 100) { if ((optionAmount || userDB?.credits) < 100) {
logger?.verbose(`Amount or user credits is below 100.`); logger?.verbose(`Amount or user credits is below 100.`);
@ -103,7 +92,6 @@ export default {
}); });
} }
// Stop if amount or user credits is above 1.000.000
if ((optionAmount || userDB?.credits) > 1000000) { if ((optionAmount || userDB?.credits) > 1000000) {
logger?.verbose(`Amount or user credits is above 1.000.000.`); logger?.verbose(`Amount or user credits is above 1.000.000.`);
@ -130,7 +118,6 @@ export default {
}); });
} }
// Stop if user credits is below amount
if (userDB?.credits < optionAmount) { if (userDB?.credits < optionAmount) {
logger?.verbose(`User credits is below amount.`); logger?.verbose(`User credits is below amount.`);
@ -156,15 +143,12 @@ export default {
}); });
} }
// Generate a unique voucher for the user
const code = uuidv4(); const code = uuidv4();
// Get api object
const apiCredentials = await apiSchema?.findOne({ const apiCredentials = await apiSchema?.findOne({
guildId: guild?.id, guildId: guild?.id,
}); });
// Create a api instance
const api = axios?.create({ const api = axios?.create({
baseURL: apiCredentials?.url, baseURL: apiCredentials?.url,
headers: { headers: {
@ -172,13 +156,10 @@ export default {
}, },
}); });
// Get shop URL
const shopUrl = apiCredentials?.url?.replace("/api", "/store"); const shopUrl = apiCredentials?.url?.replace("/api", "/store");
// Make API request
await api await api
// Make a post request to the API
?.post("vouchers", { ?.post("vouchers", {
uses: 1, uses: 1,
code, code,
@ -186,17 +167,14 @@ export default {
memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`, memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`,
}) })
// If successful
?.then(async () => { ?.then(async () => {
logger?.verbose(`Successfully created voucher.`); logger?.verbose(`Successfully created voucher.`);
// Withdraw amount from user credits
userDB.credits -= optionAmount || userDB?.credits; userDB.credits -= optionAmount || userDB?.credits;
// Save new credits
await userDB await userDB
?.save() ?.save()
// If successful
?.then(async () => { ?.then(async () => {
logger?.verbose(`Successfully saved new credits.`); logger?.verbose(`Successfully saved new credits.`);
@ -239,7 +217,6 @@ export default {
}); });
}) })
// If error occurs
.catch(async (error) => { .catch(async (error) => {
logger?.verbose(`Error saving new credits. - ${error}`); logger?.verbose(`Error saving new credits. - ${error}`);
@ -260,7 +237,6 @@ export default {
}); });
}) })
// If error occurs
.catch(async (error: any) => { .catch(async (error: any) => {
logger?.verbose(`Error creating voucher. - ${error}`); logger?.verbose(`Error creating voucher. - ${error}`);