From cde8914e49ec4731e58a2909d6e623cf42fd893f Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Sun, 10 Apr 2022 20:59:07 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- .../settings/guild/addons/pterodactyl.ts | 18 ++--- src/commands/shop/modules/pterodactyl.ts | 58 +++++++------- src/handlers/encryption.ts | 14 ++-- src/helpers/database/models/apiSchema.ts | 76 +++++++++---------- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/commands/settings/guild/addons/pterodactyl.ts b/src/commands/settings/guild/addons/pterodactyl.ts index c9d8067..0f84340 100644 --- a/src/commands/settings/guild/addons/pterodactyl.ts +++ b/src/commands/settings/guild/addons/pterodactyl.ts @@ -1,15 +1,15 @@ // Dependencies -import { ColorResolvable, CommandInteraction } from 'discord.js'; +import { ColorResolvable, CommandInteraction } from "discord.js"; // Configurations -import config from '../../../../../config.json'; +import config from "../../../../../config.json"; // Handlers -import logger from '../../../../handlers/logger'; +import logger from "../../../../handlers/logger"; // Models -import apiSchema from '../../../../helpers/database/models/apiSchema'; -import encryption from '../../../../handlers/encryption'; +import apiSchema from "../../../../helpers/database/models/apiSchema"; +import encryption from "../../../../handlers/encryption"; // Function export default async (interaction: CommandInteraction) => { @@ -17,8 +17,8 @@ export default async (interaction: CommandInteraction) => { const { options, guild, user } = interaction; // Get options - const url = options?.getString('url'); - const token = encryption.encrypt(options?.getString('token')); + const url = options?.getString("url"); + const token = encryption.encrypt(options?.getString("token")); // Update API credentials await apiSchema @@ -30,9 +30,9 @@ export default async (interaction: CommandInteraction) => { .then(async () => { // Embed object const embed = { - title: ':hammer: Settings - Guild [Pterodactyl]' as string, + title: ":hammer: Settings - Guild [Pterodactyl]" as string, color: config?.colors?.success as ColorResolvable, - description: 'Pterodactyl settings is saved!' as string, + description: "Pterodactyl settings is saved!" as string, timestamp: new Date(), footer: { iconURL: config?.footer?.icon as string, diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts index c4ad2b1..8453862 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/commands/shop/modules/pterodactyl.ts @@ -1,35 +1,35 @@ // Dependencies -import { CommandInteraction, ColorResolvable } from 'discord.js'; -import { v4 as uuidv4 } from 'uuid'; -import axios from 'axios'; +import { CommandInteraction, ColorResolvable } from "discord.js"; +import { v4 as uuidv4 } from "uuid"; +import axios from "axios"; // Configurations -import config from '../../../../config.json'; +import config from "../../../../config.json"; // Handlers -import logger from '../../../handlers/logger'; -import encryption from '../../../handlers/encryption'; +import logger from "../../../handlers/logger"; +import encryption from "../../../handlers/encryption"; // Helpers -import creditNoun from '../../../helpers/creditNoun'; +import creditNoun from "../../../helpers/creditNoun"; // Models -import apiSchema from '../../../helpers/database/models/apiSchema'; -import fetchUser from '../../../helpers/fetchUser'; +import apiSchema from "../../../helpers/database/models/apiSchema"; +import fetchUser from "../../../helpers/fetchUser"; // Function export default async (interaction: CommandInteraction) => { 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) { // Embed object const embed = { - title: ':dollar: Credits [Gift]' as string, - description: 'We could not read your requested amount.' as string, + title: ":dollar: Credits [Gift]" as string, + description: "We could not read your requested amount." as string, color: config?.colors?.error as ColorResolvable, timestamp: new Date(), footer: { @@ -55,13 +55,13 @@ export default async (interaction: CommandInteraction) => { // Stop if amount or user credits is below 100 if ((optionAmount || userDB?.credits) < 100) { const embed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, description: `You **can't** withdraw for __Pterodactyl__ below **100**.` as string, color: config?.colors?.error as ColorResolvable, fields: [ { - name: 'Your balance' as string, + name: "Your balance" 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 if ((optionAmount || userDB?.credits) > 1000000) { const embed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.` as string, color: config?.colors?.error as ColorResolvable, fields: [ { - name: 'Your balance' as string, + name: "Your balance" as string, value: `${creditNoun(userDB?.credits)}` as string, }, ], @@ -99,12 +99,12 @@ export default async (interaction: CommandInteraction) => { // Stop if user credits is below amount if (userDB?.credits < optionAmount) { const embed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, description: `You have **insufficient** credits.` as string, color: config.colors.error as ColorResolvable, fields: [ { - name: 'Your balance' as string, + name: "Your balance" as string, value: `${creditNoun(userDB?.credits)}` as string, }, ], @@ -134,13 +134,13 @@ export default async (interaction: CommandInteraction) => { }); // Get shop URL - const shopUrl = apiCredentials?.url?.replace('/api', '/store'); + const shopUrl = apiCredentials?.url?.replace("/api", "/store"); // Make API request await api // Make a post request to the API - ?.post('vouchers', { + ?.post("vouchers", { uses: 1, code, credits: optionAmount || userDB?.credits, @@ -151,12 +151,12 @@ export default async (interaction: CommandInteraction) => { ?.then(async () => { // Create DM embed object const dmEmbed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, description: `Redeem this voucher [here](${shopUrl})!` as string, 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, inline: true, }, @@ -171,8 +171,8 @@ export default async (interaction: CommandInteraction) => { // Create interaction embed object const interactionEmbed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, - description: 'I have sent you the code in DM!' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, + description: "I have sent you the code in DM!" as string, color: config?.colors?.success as ColorResolvable, timestamp: new Date(), footer: { @@ -207,9 +207,9 @@ export default async (interaction: CommandInteraction) => { .catch(async (e: any) => { logger?.error(e); 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, + "Something went wrong, please try again later." as string, color: config?.colors?.error as ColorResolvable, timestamp: new Date(), footer: { @@ -225,8 +225,8 @@ export default async (interaction: CommandInteraction) => { .catch(async (e) => { logger?.error(e); const embed = { - title: ':shopping_cart: Shop [Pterodactyl]' as string, - description: 'Something went wrong, please try again later.' as string, + title: ":shopping_cart: Shop [Pterodactyl]" as string, + description: "Something went wrong, please try again later." as string, color: config?.colors?.error as ColorResolvable, timestamp: new Date(), footer: { diff --git a/src/handlers/encryption.ts b/src/handlers/encryption.ts index efc9227..2ab38fe 100644 --- a/src/handlers/encryption.ts +++ b/src/handlers/encryption.ts @@ -1,7 +1,7 @@ -import crypto from 'crypto'; -import config from '../../config.json'; +import crypto from "crypto"; +import config from "../../config.json"; -const algorithm = 'aes-256-ctr'; +const algorithm = "aes-256-ctr"; const iv = crypto.randomBytes(16); const encrypt = (text: any) => { @@ -10,8 +10,8 @@ const encrypt = (text: any) => { const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); return { - iv: iv.toString('hex'), - content: encrypted.toString('hex'), + iv: iv.toString("hex"), + content: encrypted.toString("hex"), }; }; @@ -19,11 +19,11 @@ const decrypt = (hash: any) => { const decipher = crypto.createDecipheriv( algorithm, config.secretKey, - Buffer.from(hash.iv, 'hex') + Buffer.from(hash.iv, "hex") ); const decrypted = Buffer.concat([ - decipher.update(Buffer.from(hash.content, 'hex')), + decipher.update(Buffer.from(hash.content, "hex")), decipher.final(), ]); diff --git a/src/helpers/database/models/apiSchema.ts b/src/helpers/database/models/apiSchema.ts index 398a6d2..a388322 100644 --- a/src/helpers/database/models/apiSchema.ts +++ b/src/helpers/database/models/apiSchema.ts @@ -1,38 +1,38 @@ -import mongoose from 'mongoose'; - -const apiSchema = new mongoose.Schema( - { - guildId: { - type: mongoose.SchemaTypes.Decimal128, - required: true, - unique: false, - index: true, - }, - url: { - type: mongoose.SchemaTypes.String, - required: true, - unique: false, - index: true, - default: 'https://localhost/api/', - }, - token: { - iv: { - type: mongoose.SchemaTypes.String, - required: true, - unique: false, - index: true, - default: 'token', - }, - content: { - type: mongoose.SchemaTypes.String, - required: true, - unique: false, - index: true, - default: 'token', - }, - }, - }, - { timestamps: true } -); - -export default mongoose.model('api', apiSchema); +import mongoose from "mongoose"; + +const apiSchema = new mongoose.Schema( + { + guildId: { + type: mongoose.SchemaTypes.Decimal128, + required: true, + unique: false, + index: true, + }, + url: { + type: mongoose.SchemaTypes.String, + required: true, + unique: false, + index: true, + default: "https://localhost/api/", + }, + token: { + iv: { + type: mongoose.SchemaTypes.String, + required: true, + unique: false, + index: true, + default: "token", + }, + content: { + type: mongoose.SchemaTypes.String, + required: true, + unique: false, + index: true, + default: "token", + }, + }, + }, + { timestamps: true } +); + +export default mongoose.model("api", apiSchema);