[CodeFactor] Apply fixes
This commit is contained in:
parent
ce47867be8
commit
cde8914e49
4 changed files with 83 additions and 83 deletions
|
@ -1,15 +1,15 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { ColorResolvable, CommandInteraction } from 'discord.js';
|
import { ColorResolvable, CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
// Configurations
|
// Configurations
|
||||||
import config from '../../../../../config.json';
|
import config from "../../../../../config.json";
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
import logger from '../../../../handlers/logger';
|
import logger from "../../../../handlers/logger";
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
import apiSchema from '../../../../helpers/database/models/apiSchema';
|
import apiSchema from "../../../../helpers/database/models/apiSchema";
|
||||||
import encryption from '../../../../handlers/encryption';
|
import encryption from "../../../../handlers/encryption";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default async (interaction: CommandInteraction) => {
|
||||||
|
@ -17,8 +17,8 @@ export default async (interaction: CommandInteraction) => {
|
||||||
const { options, guild, user } = interaction;
|
const { options, guild, user } = interaction;
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
const url = options?.getString('url');
|
const url = options?.getString("url");
|
||||||
const token = encryption.encrypt(options?.getString('token'));
|
const token = encryption.encrypt(options?.getString("token"));
|
||||||
|
|
||||||
// Update API credentials
|
// Update API credentials
|
||||||
await apiSchema
|
await apiSchema
|
||||||
|
@ -30,9 +30,9 @@ export default async (interaction: CommandInteraction) => {
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
// Embed object
|
// Embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':hammer: Settings - Guild [Pterodactyl]' as string,
|
title: ":hammer: Settings - Guild [Pterodactyl]" as string,
|
||||||
color: config?.colors?.success as ColorResolvable,
|
color: config?.colors?.success as ColorResolvable,
|
||||||
description: 'Pterodactyl settings is saved!' as string,
|
description: "Pterodactyl settings is saved!" as string,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
iconURL: config?.footer?.icon as string,
|
iconURL: config?.footer?.icon as string,
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { CommandInteraction, ColorResolvable } from 'discord.js';
|
import { CommandInteraction, ColorResolvable } from "discord.js";
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
|
|
||||||
// Configurations
|
// Configurations
|
||||||
import config from '../../../../config.json';
|
import config from "../../../../config.json";
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
import logger from '../../../handlers/logger';
|
import logger from "../../../handlers/logger";
|
||||||
import encryption from '../../../handlers/encryption';
|
import encryption from "../../../handlers/encryption";
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
import creditNoun from '../../../helpers/creditNoun';
|
import creditNoun from "../../../helpers/creditNoun";
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
import apiSchema from '../../../helpers/database/models/apiSchema';
|
import apiSchema from "../../../helpers/database/models/apiSchema";
|
||||||
import fetchUser from '../../../helpers/fetchUser';
|
import fetchUser from "../../../helpers/fetchUser";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default async (interaction: CommandInteraction) => {
|
||||||
const { options, guild, user, client } = interaction;
|
const { options, guild, user, client } = interaction;
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
const optionAmount = options?.getInteger('amount');
|
const optionAmount = options?.getInteger("amount");
|
||||||
|
|
||||||
// If amount is null
|
// If amount is null
|
||||||
if (optionAmount === null) {
|
if (optionAmount === null) {
|
||||||
// Embed object
|
// Embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':dollar: Credits [Gift]' as string,
|
title: ":dollar: Credits [Gift]" as string,
|
||||||
description: 'We could not read your requested amount.' as string,
|
description: "We could not read your requested amount." as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -55,13 +55,13 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Stop if amount or user credits is below 100
|
// Stop if amount or user credits is below 100
|
||||||
if ((optionAmount || userDB?.credits) < 100) {
|
if ((optionAmount || userDB?.credits) < 100) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description:
|
description:
|
||||||
`You **can't** withdraw for __Pterodactyl__ below **100**.` as string,
|
`You **can't** withdraw for __Pterodactyl__ below **100**.` as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'Your balance' as string,
|
name: "Your balance" as string,
|
||||||
value: `${creditNoun(userDB?.credits)}` as string,
|
value: `${creditNoun(userDB?.credits)}` as string,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -77,13 +77,13 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Stop if amount or user credits is above 1.000.000
|
// Stop if amount or user credits is above 1.000.000
|
||||||
if ((optionAmount || userDB?.credits) > 1000000) {
|
if ((optionAmount || userDB?.credits) > 1000000) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description:
|
description:
|
||||||
`You **can't** withdraw for __Pterodactyl__ above **1.000.000**.` as string,
|
`You **can't** withdraw for __Pterodactyl__ above **1.000.000**.` as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'Your balance' as string,
|
name: "Your balance" as string,
|
||||||
value: `${creditNoun(userDB?.credits)}` as string,
|
value: `${creditNoun(userDB?.credits)}` as string,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -99,12 +99,12 @@ export default async (interaction: CommandInteraction) => {
|
||||||
// Stop if user credits is below amount
|
// Stop if user credits is below amount
|
||||||
if (userDB?.credits < optionAmount) {
|
if (userDB?.credits < optionAmount) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description: `You have **insufficient** credits.` as string,
|
description: `You have **insufficient** credits.` as string,
|
||||||
color: config.colors.error as ColorResolvable,
|
color: config.colors.error as ColorResolvable,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'Your balance' as string,
|
name: "Your balance" as string,
|
||||||
value: `${creditNoun(userDB?.credits)}` as string,
|
value: `${creditNoun(userDB?.credits)}` as string,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -134,13 +134,13 @@ export default async (interaction: CommandInteraction) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get shop URL
|
// Get shop URL
|
||||||
const shopUrl = apiCredentials?.url?.replace('/api', '/store');
|
const shopUrl = apiCredentials?.url?.replace("/api", "/store");
|
||||||
|
|
||||||
// Make API request
|
// Make API request
|
||||||
await api
|
await api
|
||||||
|
|
||||||
// Make a post request to the API
|
// Make a post request to the API
|
||||||
?.post('vouchers', {
|
?.post("vouchers", {
|
||||||
uses: 1,
|
uses: 1,
|
||||||
code,
|
code,
|
||||||
credits: optionAmount || userDB?.credits,
|
credits: optionAmount || userDB?.credits,
|
||||||
|
@ -151,12 +151,12 @@ export default async (interaction: CommandInteraction) => {
|
||||||
?.then(async () => {
|
?.then(async () => {
|
||||||
// Create DM embed object
|
// Create DM embed object
|
||||||
const dmEmbed = {
|
const dmEmbed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description: `Redeem this voucher [here](${shopUrl})!` as string,
|
description: `Redeem this voucher [here](${shopUrl})!` as string,
|
||||||
fields: [
|
fields: [
|
||||||
{ name: 'Code' as string, value: `${code}` as string, inline: true },
|
{ name: "Code" as string, value: `${code}` as string, inline: true },
|
||||||
{
|
{
|
||||||
name: 'Credits' as string,
|
name: "Credits" as string,
|
||||||
value: `${optionAmount || userDB?.credits}` as string,
|
value: `${optionAmount || userDB?.credits}` as string,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
|
@ -171,8 +171,8 @@ export default async (interaction: CommandInteraction) => {
|
||||||
|
|
||||||
// Create interaction embed object
|
// Create interaction embed object
|
||||||
const interactionEmbed = {
|
const interactionEmbed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description: 'I have sent you the code in DM!' as string,
|
description: "I have sent you the code in DM!" as string,
|
||||||
color: config?.colors?.success as ColorResolvable,
|
color: config?.colors?.success as ColorResolvable,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -207,9 +207,9 @@ export default async (interaction: CommandInteraction) => {
|
||||||
.catch(async (e: any) => {
|
.catch(async (e: any) => {
|
||||||
logger?.error(e);
|
logger?.error(e);
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description:
|
description:
|
||||||
'Something went wrong, please try again later.' as string,
|
"Something went wrong, please try again later." as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -225,8 +225,8 @@ export default async (interaction: CommandInteraction) => {
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
logger?.error(e);
|
logger?.error(e);
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ':shopping_cart: Shop [Pterodactyl]' as string,
|
title: ":shopping_cart: Shop [Pterodactyl]" as string,
|
||||||
description: 'Something went wrong, please try again later.' as string,
|
description: "Something went wrong, please try again later." as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import crypto from 'crypto';
|
import crypto from "crypto";
|
||||||
import config from '../../config.json';
|
import config from "../../config.json";
|
||||||
|
|
||||||
const algorithm = 'aes-256-ctr';
|
const algorithm = "aes-256-ctr";
|
||||||
const iv = crypto.randomBytes(16);
|
const iv = crypto.randomBytes(16);
|
||||||
|
|
||||||
const encrypt = (text: any) => {
|
const encrypt = (text: any) => {
|
||||||
|
@ -10,8 +10,8 @@ const encrypt = (text: any) => {
|
||||||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
iv: iv.toString('hex'),
|
iv: iv.toString("hex"),
|
||||||
content: encrypted.toString('hex'),
|
content: encrypted.toString("hex"),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ const decrypt = (hash: any) => {
|
||||||
const decipher = crypto.createDecipheriv(
|
const decipher = crypto.createDecipheriv(
|
||||||
algorithm,
|
algorithm,
|
||||||
config.secretKey,
|
config.secretKey,
|
||||||
Buffer.from(hash.iv, 'hex')
|
Buffer.from(hash.iv, "hex")
|
||||||
);
|
);
|
||||||
|
|
||||||
const decrypted = Buffer.concat([
|
const decrypted = Buffer.concat([
|
||||||
decipher.update(Buffer.from(hash.content, 'hex')),
|
decipher.update(Buffer.from(hash.content, "hex")),
|
||||||
decipher.final(),
|
decipher.final(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import mongoose from 'mongoose';
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
const apiSchema = new mongoose.Schema(
|
const apiSchema = new mongoose.Schema(
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ const apiSchema = new mongoose.Schema(
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
default: 'https://localhost/api/',
|
default: "https://localhost/api/",
|
||||||
},
|
},
|
||||||
token: {
|
token: {
|
||||||
iv: {
|
iv: {
|
||||||
|
@ -21,18 +21,18 @@ const apiSchema = new mongoose.Schema(
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
default: 'token',
|
default: "token",
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: mongoose.SchemaTypes.String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
default: 'token',
|
default: "token",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
export default mongoose.model('api', apiSchema);
|
export default mongoose.model("api", apiSchema);
|
||||||
|
|
Loading…
Add table
Reference in a new issue