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";
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
import logger from "@logger";
|
import logger from "@logger";
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
import { url } from "@config/database";
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
await mongoose
|
await mongoose
|
||||||
.connect(url)
|
.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: {
|
guildId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
|
@ -17,14 +24,14 @@ const apiSchema = new mongoose.Schema(
|
||||||
},
|
},
|
||||||
token: {
|
token: {
|
||||||
iv: {
|
iv: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
default: "token",
|
default: "token",
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
|
@ -35,4 +42,4 @@ const apiSchema = new mongoose.Schema(
|
||||||
{ timestamps: true }
|
{ 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: {
|
guildId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
channelId: {
|
channelId: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: true,
|
unique: true,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
word: {
|
word: {
|
||||||
type: mongoose.SchemaTypes.String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
counter: {
|
counter: {
|
||||||
type: mongoose.SchemaTypes.Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
|
@ -31,4 +39,4 @@ const counterSchema = new mongoose.Schema(
|
||||||
{ timestamps: true }
|
{ 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: {
|
roleId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
userId: {
|
userId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
guildId: {
|
guildId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
pricePerHour: {
|
pricePerHour: {
|
||||||
type: mongoose.SchemaTypes.Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
default: 5,
|
default: 5,
|
||||||
},
|
},
|
||||||
lastPayed: {
|
lastPayed: {
|
||||||
type: mongoose.SchemaTypes.Date,
|
type: Date,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
|
@ -36,4 +45,4 @@ const shopRoleSchema = new mongoose.Schema(
|
||||||
{ timestamps: true }
|
{ 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: {
|
userId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
guildId: {
|
guildId: {
|
||||||
type: mongoose.SchemaTypes.Decimal128,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
unique: false,
|
unique: false,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
timeoutId: { type: mongoose.SchemaTypes.String },
|
timeoutId: { type: String },
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ 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";
|
import { Guild } from "discord.js";
|
||||||
|
|
||||||
// Helpers
|
// Dependencies
|
||||||
import updatePresence from "../../helpers/updatePresence";
|
import updatePresence from "@helpers/updatePresence";
|
||||||
import fetchGuild from "../../helpers/fetchGuild";
|
import fetchGuild from "@helpers/fetchGuild";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "guildCreate",
|
name: "guildCreate",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Dependencies
|
// 3rd party dependencies
|
||||||
import { Guild } from "discord.js";
|
import { Guild } from "discord.js";
|
||||||
|
|
||||||
// Helpers
|
// Dependencies
|
||||||
import updatePresence from "../../helpers/updatePresence";
|
import updatePresence from "@helpers/updatePresence";
|
||||||
import dropGuild from "../../helpers/dropGuild";
|
import dropGuild from "@helpers/dropGuild";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "guildDelete",
|
name: "guildDelete",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Dependencies
|
// 3rd party dependencies
|
||||||
import { GuildMember } from "discord.js";
|
import { GuildMember } from "discord.js";
|
||||||
|
|
||||||
// Helpers
|
// Dependencies
|
||||||
import updatePresence from "../../helpers/updatePresence";
|
import updatePresence from "@helpers/updatePresence";
|
||||||
import fetchUser from "../../helpers/fetchUser";
|
import fetchUser from "@helpers/fetchUser";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "guildMemberAdd",
|
name: "guildMemberAdd",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// Dependencies
|
// 3rd party dependencies
|
||||||
import { GuildMember } from "discord.js";
|
import { GuildMember } from "discord.js";
|
||||||
|
|
||||||
// Helpers
|
// Dependencies
|
||||||
import updatePresence from "../../helpers/updatePresence";
|
import updatePresence from "@helpers/updatePresence";
|
||||||
import dropUser from "../../helpers/dropUser";
|
import dropUser from "@helpers/dropUser";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "guildMemberRemove",
|
name: "guildMemberRemove",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { CommandInteraction, MessageEmbed } from "discord.js";
|
||||||
|
|
||||||
import logger from "@logger";
|
import logger from "@logger";
|
||||||
|
|
||||||
import * as embed from "@config/embed";
|
import { errorColor, footerText, footerIcon } from "@config/embed";
|
||||||
|
|
||||||
import guildSchema from "@schemas/guild";
|
import guildSchema from "@schemas/guild";
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@ export default async (interaction: CommandInteraction) => {
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`There was an error executing the command: **${currentCommand.data.name}**.`
|
`There was an error executing the command: **${currentCommand.data.name}**.`
|
||||||
)
|
)
|
||||||
.setColor(embed.errorColor)
|
.setColor(errorColor)
|
||||||
.setTimestamp(new Date())
|
.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 { CommandInteraction } from "discord.js";
|
||||||
|
|
||||||
import isCommand from "./isCommand";
|
// Dependencies
|
||||||
|
import isCommand from "@root/events/interactionCreate/components/isCommand";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "interactionCreate",
|
name: "interactionCreate",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import crypto from "crypto";
|
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 iv = crypto.randomBytes(16);
|
||||||
|
|
||||||
const encrypt = (text: any) => {
|
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()]);
|
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ const encrypt = (text: any) => {
|
||||||
const decrypt = (hash: any) => {
|
const decrypt = (hash: any) => {
|
||||||
const decipher = crypto.createDecipheriv(
|
const decipher = crypto.createDecipheriv(
|
||||||
algorithm,
|
algorithm,
|
||||||
config.secretKey,
|
secretKey,
|
||||||
Buffer.from(hash.iv, "hex")
|
Buffer.from(hash.iv, "hex")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ import logger from "@logger";
|
||||||
import { devMode, guildId } from "@config/other";
|
import { devMode, guildId } from "@config/other";
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client) => {
|
||||||
if (!devMode) {
|
// if (!devMode) {
|
||||||
client?.application?.commands?.set([], guildId).then(async () => {
|
// client?.application?.commands?.set([], guildId).then(async () => {
|
||||||
logger.verbose(`Removed all guild based commands from ${guildId}`);
|
// logger.verbose(`Removed all guild based commands from ${guildId}`);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue