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