[CodeFactor] Apply fixes

This commit is contained in:
codefactor-io 2022-04-10 20:59:07 +00:00
parent ce47867be8
commit cde8914e49
No known key found for this signature in database
GPG key ID: B66B2D63282C190F
4 changed files with 83 additions and 83 deletions

View file

@ -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,

View file

@ -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: {

View file

@ -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(),
]);

View file

@ -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);