Merge pull request #219 from VermiumSifell/dev
Organize and structure plugins
This commit is contained in:
commit
f1633512b2
15 changed files with 101 additions and 63 deletions
|
@ -0,0 +1,5 @@
|
|||
// Encryption algorithm
|
||||
export const algorithm = "aes-256-ctr";
|
||||
|
||||
// Encryption secret (strictly 32 length)
|
||||
export const secretKey = "";
|
|
@ -1,8 +1,12 @@
|
|||
import { url } from "@config/database";
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
import mongoose from "mongoose";
|
||||
import { Snowflake } from "discord.js";
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const apiSchema = new mongoose.Schema(
|
||||
export interface IApi {
|
||||
guildId: Snowflake;
|
||||
url: string;
|
||||
token: { iv: string; content: string };
|
||||
}
|
||||
|
||||
const apiSchema = new Schema<IApi>(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
|
@ -17,14 +24,14 @@ const apiSchema = new mongoose.Schema(
|
|||
},
|
||||
token: {
|
||||
iv: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: "token",
|
||||
},
|
||||
content: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
|
@ -35,4 +42,4 @@ const apiSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model("api", apiSchema);
|
||||
export default model<IApi>("api", apiSchema);
|
||||
|
|
|
@ -1,27 +1,35 @@
|
|||
import mongoose from "mongoose";
|
||||
import { Schema, model } from "mongoose";
|
||||
import { Snowflake } from "discord.js";
|
||||
|
||||
const counterSchema = new mongoose.Schema(
|
||||
export interface ICounter {
|
||||
guildId: Snowflake;
|
||||
channelId: Snowflake;
|
||||
word: string;
|
||||
counter: number;
|
||||
}
|
||||
|
||||
const counterSchema = new Schema<ICounter>(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
channelId: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
index: true,
|
||||
},
|
||||
word: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
counter: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
type: Number,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
|
@ -31,4 +39,4 @@ const counterSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model("counter", counterSchema);
|
||||
export default model<ICounter>("counter", counterSchema);
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
import counter from "./counter";
|
||||
|
||||
export default { counter };
|
|
@ -1,34 +1,43 @@
|
|||
import mongoose from "mongoose";
|
||||
import { Snowflake } from "discord.js";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
const shopRoleSchema = new mongoose.Schema(
|
||||
export interface IShopRole {
|
||||
roleId: Snowflake;
|
||||
userId: Snowflake;
|
||||
guildId: Snowflake;
|
||||
pricePerHour: number;
|
||||
lastPayed: Date;
|
||||
}
|
||||
|
||||
const shopRoleSchema = new Schema<IShopRole>(
|
||||
{
|
||||
roleId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
pricePerHour: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
type: Number,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 5,
|
||||
},
|
||||
lastPayed: {
|
||||
type: mongoose.SchemaTypes.Date,
|
||||
type: Date,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
|
@ -36,4 +45,4 @@ const shopRoleSchema = new mongoose.Schema(
|
|||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model("shopRole", shopRoleSchema);
|
||||
export default model<IShopRole>("shopRole", shopRoleSchema);
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
import mongoose from "mongoose";
|
||||
import { Snowflake } from "discord.js";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
const timeoutSchema = new mongoose.Schema(
|
||||
export interface ITimeout {
|
||||
userId: Snowflake;
|
||||
guildId: Snowflake;
|
||||
timeoutId: string;
|
||||
}
|
||||
|
||||
const timeoutSchema = new Schema<ITimeout>(
|
||||
{
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
type: String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
timeoutId: { type: mongoose.SchemaTypes.String },
|
||||
timeoutId: { type: String },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export default mongoose.model("timeout", timeoutSchema);
|
||||
export default model<ITimeout>("timeout", timeoutSchema);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Dependencies
|
||||
// 3rd party dependencies
|
||||
import { Guild } from "discord.js";
|
||||
|
||||
// Helpers
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import fetchGuild from "../../helpers/fetchGuild";
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import fetchGuild from "@helpers/fetchGuild";
|
||||
|
||||
export default {
|
||||
name: "guildCreate",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Dependencies
|
||||
// 3rd party dependencies
|
||||
import { Guild } from "discord.js";
|
||||
|
||||
// Helpers
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import dropGuild from "../../helpers/dropGuild";
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import dropGuild from "@helpers/dropGuild";
|
||||
|
||||
export default {
|
||||
name: "guildDelete",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Dependencies
|
||||
// 3rd party dependencies
|
||||
import { GuildMember } from "discord.js";
|
||||
|
||||
// Helpers
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import fetchUser from "../../helpers/fetchUser";
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import fetchUser from "@helpers/fetchUser";
|
||||
|
||||
export default {
|
||||
name: "guildMemberAdd",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Dependencies
|
||||
// 3rd party dependencies
|
||||
import { GuildMember } from "discord.js";
|
||||
|
||||
// Helpers
|
||||
import updatePresence from "../../helpers/updatePresence";
|
||||
import dropUser from "../../helpers/dropUser";
|
||||
// Dependencies
|
||||
import updatePresence from "@helpers/updatePresence";
|
||||
import dropUser from "@helpers/dropUser";
|
||||
|
||||
export default {
|
||||
name: "guildMemberRemove",
|
||||
|
|
|
@ -3,7 +3,7 @@ import { CommandInteraction, MessageEmbed } from "discord.js";
|
|||
|
||||
import logger from "@logger";
|
||||
|
||||
import * as embed from "@config/embed";
|
||||
import { errorColor, footerText, footerIcon } from "@config/embed";
|
||||
|
||||
import guildSchema from "@schemas/guild";
|
||||
|
||||
|
@ -49,9 +49,9 @@ export default async (interaction: CommandInteraction) => {
|
|||
.setDescription(
|
||||
`There was an error executing the command: **${currentCommand.data.name}**.`
|
||||
)
|
||||
.setColor(embed.errorColor)
|
||||
.setColor(errorColor)
|
||||
.setTimestamp(new Date())
|
||||
.setFooter({ text: embed.footerText, iconURL: embed.footerIcon }),
|
||||
.setFooter({ text: footerText, iconURL: footerIcon }),
|
||||
],
|
||||
});
|
||||
});
|
|
@ -1,7 +1,8 @@
|
|||
// Dependencies
|
||||
// 3rd party dependencies
|
||||
import { CommandInteraction } from "discord.js";
|
||||
|
||||
import isCommand from "./isCommand";
|
||||
// Dependencies
|
||||
import isCommand from "@root/events/interactionCreate/components/isCommand";
|
||||
|
||||
export default {
|
||||
name: "interactionCreate",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import crypto from "crypto";
|
||||
import config from "../../config.json";
|
||||
|
||||
const algorithm = "aes-256-ctr";
|
||||
import { secretKey, algorithm } from "@config/encryption";
|
||||
|
||||
const iv = crypto.randomBytes(16);
|
||||
|
||||
const encrypt = (text: any) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, config.secretKey, iv);
|
||||
const cipher = crypto.createCipheriv(algorithm, secretKey, iv);
|
||||
|
||||
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||
|
||||
|
@ -18,7 +18,7 @@ const encrypt = (text: any) => {
|
|||
const decrypt = (hash: any) => {
|
||||
const decipher = crypto.createDecipheriv(
|
||||
algorithm,
|
||||
config.secretKey,
|
||||
secretKey,
|
||||
Buffer.from(hash.iv, "hex")
|
||||
);
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@ import logger from "@logger";
|
|||
import { devMode, guildId } from "@config/other";
|
||||
|
||||
export default async (client: Client) => {
|
||||
if (!devMode) {
|
||||
client?.application?.commands?.set([], guildId).then(async () => {
|
||||
logger.verbose(`Removed all guild based commands from ${guildId}`);
|
||||
});
|
||||
}
|
||||
// if (!devMode) {
|
||||
// client?.application?.commands?.set([], guildId).then(async () => {
|
||||
// logger.verbose(`Removed all guild based commands from ${guildId}`);
|
||||
// });
|
||||
// }
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue