Improving TypeScript typing/interfaces.
This commit is contained in:
parent
8537fcbded
commit
f960ef3cec
8 changed files with 21 additions and 33 deletions
|
@ -65,6 +65,7 @@
|
|||
"husky": "8.0.1",
|
||||
"jest": "28.0.0",
|
||||
"lint-staged": "^12.3.7",
|
||||
"nodemon": "^2.0.16",
|
||||
"prettier": "^2.6.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
// 3rd party dependencies
|
||||
import mongoose from "mongoose";
|
||||
|
||||
// Dependencies
|
||||
import logger from "@logger";
|
||||
|
||||
// Configuration
|
||||
import { url } from "@config/database";
|
||||
|
||||
export default async () => {
|
||||
await mongoose.connect(url).then(async (connection) => {
|
||||
logger.info(`Connected to database: ${connection.connection.name}`);
|
||||
});
|
||||
|
||||
mongoose.connection.on("error", async (error) => {
|
||||
logger.error(`${error}`);
|
||||
});
|
||||
|
||||
mongoose.connection.on("warn", async (warning) => {
|
||||
logger.warn(warning);
|
||||
});
|
||||
};
|
|
@ -83,7 +83,7 @@ export default async (interaction: CommandInteraction) => {
|
|||
`Command: ${commandName} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})`
|
||||
);
|
||||
})
|
||||
.catch(async (error: any) => {
|
||||
.catch(async (error: string) => {
|
||||
logger?.error(`${error}`);
|
||||
|
||||
return interaction.editReply({
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
import crypto from "crypto";
|
||||
|
||||
// @ts-ignore
|
||||
import { secretKey, algorithm } from "@config/encryption";
|
||||
|
||||
const iv = crypto.randomBytes(16);
|
||||
|
||||
const encrypt = (text: any): { iv: any; content: any } => {
|
||||
const cipher = crypto.createCipheriv(algorithm, secretKey, iv);
|
||||
interface IEncrypt {
|
||||
iv: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
const encrypt = (text: crypto.BinaryLike): IEncrypt => {
|
||||
const cipher = crypto.createCipheriv(algorithm, secretKey, iv);
|
||||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||
|
||||
return {
|
||||
|
@ -15,7 +20,7 @@ const encrypt = (text: any): { iv: any; content: any } => {
|
|||
};
|
||||
};
|
||||
|
||||
const decrypt = (hash: any) => {
|
||||
const decrypt = (hash: IEncrypt) => {
|
||||
const decipher = crypto.createDecipheriv(
|
||||
algorithm,
|
||||
secretKey,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import logger from "@logger";
|
||||
|
||||
export default function sleep(milliseconds: any) {
|
||||
export default function sleep(milliseconds: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, milliseconds);
|
||||
logger?.silly(`Sleeping for ${milliseconds} milliseconds`);
|
||||
|
|
|
@ -45,8 +45,9 @@ export default {
|
|||
const { options, guild } = interaction;
|
||||
|
||||
// Get options
|
||||
const url = options?.getString("url");
|
||||
const token = encryption.encrypt(options?.getString("token"));
|
||||
const tokenData = options.getString("token");
|
||||
const url = options.getString("url");
|
||||
const token = tokenData && encryption.encrypt(tokenData);
|
||||
|
||||
// Update API credentials
|
||||
await apiSchema
|
||||
|
|
|
@ -147,10 +147,12 @@ export default {
|
|||
guildId: guild?.id,
|
||||
});
|
||||
|
||||
if (!apiCredentials) return;
|
||||
|
||||
const api = axios?.create({
|
||||
baseURL: apiCredentials?.url,
|
||||
baseURL: apiCredentials.url,
|
||||
headers: {
|
||||
Authorization: `Bearer ${encryption.decrypt(apiCredentials?.token)}`,
|
||||
Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -235,7 +237,7 @@ export default {
|
|||
});
|
||||
})
|
||||
|
||||
.catch(async (error: any) => {
|
||||
.catch(async (error) => {
|
||||
logger?.silly(`Error creating voucher. - ${error}`);
|
||||
|
||||
return interaction?.editReply({
|
||||
|
|
3
src/types/common/discord.d.ts
vendored
3
src/types/common/discord.d.ts
vendored
|
@ -1,7 +1,8 @@
|
|||
import { Collection, Client as DJSClient } from "discord.js";
|
||||
|
||||
declare module "discord.js" {
|
||||
export interface Client extends DJSClient {
|
||||
commands: Collection<unknown, any>;
|
||||
commands: Collection;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue