From 209df02ccc1a2d598667b25dbd0d305a5b9be593 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 20 May 2022 07:43:38 +0000 Subject: [PATCH 01/75] fix: upgrade @discordjs/builders from 0.12.0 to 0.13.0 Snyk has created this PR to upgrade @discordjs/builders from 0.12.0 to 0.13.0. See this package in npm: https://www.npmjs.com/package/@discordjs/builders See this project in Snyk: https://app.snyk.io/org/zyner/project/4ad0ecd9-b57c-4594-a520-da974699cb93?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ca226..9596c22 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "email": "vermium@zyner.org" }, "dependencies": { - "@discordjs/builders": "^0.12.0", + "@discordjs/builders": "^0.13.0", "@discordjs/rest": "^0.4.0", "axios": "^0.26.0", "chance": "^1.1.8", From 33dc030def6cbec3420d2ea5188ba454b6544f6f Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 20 May 2022 07:43:42 +0000 Subject: [PATCH 02/75] fix: upgrade axios from 0.26.1 to 0.27.2 Snyk has created this PR to upgrade axios from 0.26.1 to 0.27.2. See this package in npm: https://www.npmjs.com/package/axios See this project in Snyk: https://app.snyk.io/org/zyner/project/4ad0ecd9-b57c-4594-a520-da974699cb93?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ca226..6100a44 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "dependencies": { "@discordjs/builders": "^0.12.0", "@discordjs/rest": "^0.4.0", - "axios": "^0.26.0", + "axios": "^0.27.2", "chance": "^1.1.8", "common": "^0.2.5", "crypto": "^1.0.1", From ac7acda21bc9587ca68b685d097724465e2d1558 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 20 May 2022 07:43:45 +0000 Subject: [PATCH 03/75] fix: upgrade discord-api-types from 0.31.2 to 0.32.0 Snyk has created this PR to upgrade discord-api-types from 0.31.2 to 0.32.0. See this package in npm: https://www.npmjs.com/package/discord-api-types See this project in Snyk: https://app.snyk.io/org/zyner/project/4ad0ecd9-b57c-4594-a520-da974699cb93?utm_source=github&utm_medium=referral&page=upgrade-pr --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5ca226..ac3ef1d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "chance": "^1.1.8", "common": "^0.2.5", "crypto": "^1.0.1", - "discord-api-types": "^0.31.0", + "discord-api-types": "^0.32.0", "discord.js": "^13.6.0", "i18next": "^21.6.13", "mongoose": "^6.2.3", From 1ebc2bf5dafa2f48fc9a4b353e805f77b289c299 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 20 May 2022 21:06:14 +0000 Subject: [PATCH 04/75] Update dependency i18n to ^0.15.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38dca3b..76a9b98 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "crypto": "^1.0.1", "discord-api-types": "^0.33.0", "discord.js": "^13.6.0", - "i18n": "^0.14.2", + "i18n": "^0.15.0", "i18next": "^21.6.13", "i18next-async-backend": "^2.0.0", "i18next-fs-backend": "^1.1.4", From 3e40cd9dbe62a528ad908f1a7bf458fde81207c1 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 20 May 2022 21:06:17 +0000 Subject: [PATCH 05/75] Update dependency jest to v28.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 38dca3b..057d7ac 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "eslint-plugin-no-loops": "^0.3.0", "eslint-plugin-prettier": "^4.0.0", "husky": "8.0.1", - "jest": "28.0.0", + "jest": "28.1.0", "lint-staged": "^12.3.7", "prettier": "^2.6.0" }, From d65c8765ea01b6230577c0e316df3245ccf17c18 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sat, 21 May 2022 01:14:44 +0000 Subject: [PATCH 06/75] Update dependency eslint to v8.16.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..bcc7e02 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.15.0", "@typescript-eslint/parser": "^5.15.0", - "eslint": "8.15.0", + "eslint": "8.16.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", From 8537fcbded20d31fda8383f27473727eed77eaf6 Mon Sep 17 00:00:00 2001 From: servous Date: Sat, 28 May 2022 11:59:45 +0200 Subject: [PATCH 07/75] Improved TS typing/interfaces. --- src/handlers/deployCommands.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 8af167e..4ca0923 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -1,17 +1,24 @@ -// Dependencies +// @ts-ignore import { token, clientId } from "@config/discord"; +// @ts-ignore import { devMode, guildId } from "@config/other"; import logger from "../logger"; import { Client } from "@root/types/common/discord"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; +import { SlashCommandBuilder } from "@discordjs/builders"; +import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; export default async (client: Client) => { - const pluginList = [] as string[]; + const pluginList: Array = []; + + interface IPluginData { + builder: SlashCommandBuilder; + } await Promise.all( - client.commands.map(async (pluginData: any) => { + client.commands.map(async (pluginData: IPluginData) => { pluginList.push(pluginData.builder.toJSON()); logger.verbose( `Plugin is ready for deployment: ${pluginData.builder.name}` From f960ef3cec02505a7e9bfcd134c5429ab3e096f7 Mon Sep 17 00:00:00 2001 From: servous Date: Sat, 28 May 2022 12:27:17 +0200 Subject: [PATCH 08/75] Improving TypeScript typing/interfaces. --- package.json | 1 + src/events/index.ts | 22 ------------------- .../interactionCreate/components/isCommand.ts | 2 +- src/handlers/encryption.ts | 11 +++++++--- src/helpers/sleep.ts | 2 +- src/plugins/config/modules/pterodactyl.ts | 5 +++-- src/plugins/shop/modules/pterodactyl.ts | 8 ++++--- src/types/common/discord.d.ts | 3 ++- 8 files changed, 21 insertions(+), 33 deletions(-) delete mode 100644 src/events/index.ts diff --git a/package.json b/package.json index 216f2fb..3acb125 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/events/index.ts b/src/events/index.ts deleted file mode 100644 index b7dd3b6..0000000 --- a/src/events/index.ts +++ /dev/null @@ -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); - }); -}; diff --git a/src/events/interactionCreate/components/isCommand.ts b/src/events/interactionCreate/components/isCommand.ts index 7af8e7e..30edc4c 100644 --- a/src/events/interactionCreate/components/isCommand.ts +++ b/src/events/interactionCreate/components/isCommand.ts @@ -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({ diff --git a/src/handlers/encryption.ts b/src/handlers/encryption.ts index 8e7ea27..cab28ff 100644 --- a/src/handlers/encryption.ts +++ b/src/handlers/encryption.ts @@ -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, diff --git a/src/helpers/sleep.ts b/src/helpers/sleep.ts index 5e53d79..792c81f 100644 --- a/src/helpers/sleep.ts +++ b/src/helpers/sleep.ts @@ -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`); diff --git a/src/plugins/config/modules/pterodactyl.ts b/src/plugins/config/modules/pterodactyl.ts index b7162d6..e6673e1 100644 --- a/src/plugins/config/modules/pterodactyl.ts +++ b/src/plugins/config/modules/pterodactyl.ts @@ -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 diff --git a/src/plugins/shop/modules/pterodactyl.ts b/src/plugins/shop/modules/pterodactyl.ts index f3ef08b..22da19c 100644 --- a/src/plugins/shop/modules/pterodactyl.ts +++ b/src/plugins/shop/modules/pterodactyl.ts @@ -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({ diff --git a/src/types/common/discord.d.ts b/src/types/common/discord.d.ts index 1e4926f..68458e0 100644 --- a/src/types/common/discord.d.ts +++ b/src/types/common/discord.d.ts @@ -1,7 +1,8 @@ import { Collection, Client as DJSClient } from "discord.js"; + declare module "discord.js" { export interface Client extends DJSClient { - commands: Collection; + commands: Collection; } } From 50f070787c95546a22337d564b54077d1f305980 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 12:54:37 +0200 Subject: [PATCH 09/75] =?UTF-8?q?=F0=9F=90=9B=20Default=20embed=20if=20gui?= =?UTF-8?q?ld=20is=20null=20#337?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/getEmbedConfig.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/helpers/getEmbedConfig.ts b/src/helpers/getEmbedConfig.ts index 3532542..df62073 100644 --- a/src/helpers/getEmbedConfig.ts +++ b/src/helpers/getEmbedConfig.ts @@ -1,17 +1,19 @@ import guildSchema from "@schemas/guild"; +import * as embedConfig from "@config/embed"; -import { ColorResolvable, Guild } from "discord.js"; +import { Guild } from "discord.js"; + +export default async (guild: Guild | null) => { + if (guild == null) + return { + ...embedConfig, + }; -export default async (guild: Guild) => { const guildConfig = await guildSchema.findOne({ guildId: guild.id }); if (guildConfig == null) return { - successColor: "#22bb33" as ColorResolvable, - waitColor: "#f0ad4e" as ColorResolvable, - errorColor: "#bb2124" as ColorResolvable, - footerIcon: "https://github.com/ZynerOrg.png", - footerText: "https://github.com/ZynerOrg/xyter", + ...embedConfig, }; return guildConfig.embeds; From 518ec431d8ab329db087da2484b0dfaf64f6ab00 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 12:55:23 +0200 Subject: [PATCH 10/75] =?UTF-8?q?=F0=9F=9A=B8=20more=20logical=20meme=20co?= =?UTF-8?q?mmand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fun/modules/{meme.ts => meme/index.ts} | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) rename src/plugins/fun/modules/{meme.ts => meme/index.ts} (57%) diff --git a/src/plugins/fun/modules/meme.ts b/src/plugins/fun/modules/meme/index.ts similarity index 57% rename from src/plugins/fun/modules/meme.ts rename to src/plugins/fun/modules/meme/index.ts index be62672..4efe8a7 100644 --- a/src/plugins/fun/modules/meme.ts +++ b/src/plugins/fun/modules/meme/index.ts @@ -11,11 +11,12 @@ export default { builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("meme").setDescription("Get a meme from r/memes)"); }, + execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); + const { guild } = interaction; + + const embedConfig = await getEmbedConfig(guild); + await axios .get("https://www.reddit.com/r/memes/random/.json") .then(async (res) => { @@ -23,14 +24,28 @@ export default { const content = response[0].data; const embed = new MessageEmbed() - .setTitle(content.title) + .setAuthor({ + name: content.title, + iconURL: + "https://www.redditinc.com/assets/images/site/reddit-logo.png", + url: `https://reddit.com${content.permalink}`, + }) + .setTitle("[:sweat_smile:] Meme") + .addFields([ + { name: "Author", value: content.author, inline: true }, + { + name: "Votes", + value: `${content.ups}/${content.downs}`, + inline: true, + }, + ]) .setTimestamp(new Date()) .setImage(content.url) .setFooter({ - text: `👍 ${content.ups}︱👎 ${content.downs}\n${footerText}`, - iconURL: footerIcon, + text: embedConfig.footerText, + iconURL: embedConfig.footerIcon, }) - .setColor(successColor); + .setColor(embedConfig.successColor); return interaction.editReply({ embeds: [embed] }); }) From ddc43cf50946590bdad825911e2e83ce2692fc79 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 13:02:35 +0200 Subject: [PATCH 11/75] =?UTF-8?q?=F0=9F=9A=B8=20better=20throw=20new=20Err?= =?UTF-8?q?or=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/interactionCreate/components/isCommand.ts | 9 ++++++--- src/helpers/capitalizeFirstLetter.ts | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/helpers/capitalizeFirstLetter.ts diff --git a/src/events/interactionCreate/components/isCommand.ts b/src/events/interactionCreate/components/isCommand.ts index 30edc4c..91c61dd 100644 --- a/src/events/interactionCreate/components/isCommand.ts +++ b/src/events/interactionCreate/components/isCommand.ts @@ -6,6 +6,7 @@ import logger from "@logger"; import deferReply from "@root/helpers/deferReply"; import getEmbedConfig from "@helpers/getEmbedConfig"; import getCommandMetadata from "@helpers/getCommandMetadata"; +import capitalizeFirstLetter from "@helpers/capitalizeFirstLetter"; export default async (interaction: CommandInteraction) => { if (!interaction.isCommand()) return; @@ -89,10 +90,12 @@ export default async (interaction: CommandInteraction) => { return interaction.editReply({ embeds: [ new MessageEmbed() - .setTitle("Error") - .setDescription( - `There was an error executing the command: **${currentCommand?.data?.name}**.` + .setTitle( + `[:x:] ${capitalizeFirstLetter( + interaction.options.getSubcommand() + )}` ) + .setDescription(`${"``"}${error}${"``"}`) .setColor(errorColor) .setTimestamp(new Date()) .setFooter({ text: footerText, iconURL: footerIcon }), diff --git a/src/helpers/capitalizeFirstLetter.ts b/src/helpers/capitalizeFirstLetter.ts new file mode 100644 index 0000000..1190b36 --- /dev/null +++ b/src/helpers/capitalizeFirstLetter.ts @@ -0,0 +1,3 @@ +export default (text: string): string => { + return text.charAt(0).toUpperCase() + text.slice(1); +}; From 1a6bbd80f24ef1db925e348dbb84c7453e5777fa Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 13:03:02 +0200 Subject: [PATCH 12/75] =?UTF-8?q?=F0=9F=A5=85=20use=20throw=20new=20Error?= =?UTF-8?q?=20instead=20of=20logger.error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/fun/modules/meme/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/fun/modules/meme/index.ts b/src/plugins/fun/modules/meme/index.ts index 4efe8a7..3b6d706 100644 --- a/src/plugins/fun/modules/meme/index.ts +++ b/src/plugins/fun/modules/meme/index.ts @@ -50,7 +50,7 @@ export default { return interaction.editReply({ embeds: [embed] }); }) .catch((error) => { - logger.error(`${error}`); + throw new Error(error.message); }); }, }; From c84191d70f0015282178c0937aadaf94873eb8c6 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 13:17:32 +0200 Subject: [PATCH 13/75] =?UTF-8?q?=F0=9F=8E=A8=20mostly=20typed=20event=20h?= =?UTF-8?q?andler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildCreate/index.ts | 28 ++++++++++---------- src/events/guildDelete/index.ts | 25 ++++++++++-------- src/events/guildMemberAdd/index.ts | 29 +++++++++++---------- src/events/guildMemberRemove/index.ts | 29 +++++++++++---------- src/events/interactionCreate/index.ts | 25 ++++++++++-------- src/events/messageCreate/index.ts | 16 +++++++----- src/events/messageDelete/index.ts | 13 ++++++---- src/events/messageUpdate/index.ts | 31 ++++++++++++---------- src/events/ready/index.ts | 32 ++++++++++++----------- src/handlers/events.ts | 37 --------------------------- src/helpers/listDir/index.ts | 10 ++++++++ src/index.ts | 4 +-- src/interfaces/EventOptions.ts | 3 +++ src/managers/event/index.ts | 24 +++++++++++++++++ 14 files changed, 165 insertions(+), 141 deletions(-) delete mode 100644 src/handlers/events.ts create mode 100644 src/helpers/listDir/index.ts create mode 100644 src/interfaces/EventOptions.ts create mode 100644 src/managers/event/index.ts diff --git a/src/events/guildCreate/index.ts b/src/events/guildCreate/index.ts index 01b70f6..d76b9a2 100644 --- a/src/events/guildCreate/index.ts +++ b/src/events/guildCreate/index.ts @@ -1,20 +1,20 @@ -// 3rd party dependencies import { Guild } from "discord.js"; - -// Dependencies import updatePresence from "@helpers/updatePresence"; import fetchGuild from "@helpers/fetchGuild"; import logger from "@logger"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(guild: Guild) { - const { client } = guild; - - logger?.silly(`Added to guild: ${guild.name} (${guild.id})`); - - await fetchGuild(guild); - await updatePresence(client); - - logger.silly(`guildCreate: ${guild}`); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (guild: Guild) => { + const { client } = guild; + + logger?.silly(`Added to guild: ${guild.name} (${guild.id})`); + + await fetchGuild(guild); + await updatePresence(client); + + logger.silly(`guildCreate: ${guild}`); }; diff --git a/src/events/guildDelete/index.ts b/src/events/guildDelete/index.ts index 123393c..741b69c 100644 --- a/src/events/guildDelete/index.ts +++ b/src/events/guildDelete/index.ts @@ -5,16 +5,19 @@ import { Guild } from "discord.js"; import updatePresence from "@helpers/updatePresence"; import dropGuild from "@helpers/dropGuild"; import logger from "@logger"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(guild: Guild) { - const { client } = guild; - - logger?.silly(`Deleted from guild: ${guild.name} (${guild.id})`); - - await dropGuild(guild); - await updatePresence(client); - - logger.silly(`guildDelete: ${guild}`); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (guild: Guild) => { + const { client } = guild; + + logger?.silly(`Deleted from guild: ${guild.name} (${guild.id})`); + + await dropGuild(guild); + await updatePresence(client); + + logger.silly(`guildDelete: ${guild}`); }; diff --git a/src/events/guildMemberAdd/index.ts b/src/events/guildMemberAdd/index.ts index 9ece541..2cda131 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/events/guildMemberAdd/index.ts @@ -7,18 +7,21 @@ import fetchUser from "@helpers/fetchUser"; import logger from "@logger"; import joinMessage from "../guildMemberAdd/joinMessage"; import audits from "../guildMemberAdd/audits"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(member: GuildMember) { - const { client, user, guild } = member; - - logger?.silly( - `New member: ${user.tag} (${user.id}) added to guild: ${guild.name} (${guild.id})` - ); - - await audits.execute(member); - await joinMessage.execute(member); - await fetchUser(user, guild); - await updatePresence(client); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (member: GuildMember) => { + const { client, user, guild } = member; + + logger?.silly( + `New member: ${user.tag} (${user.id}) added to guild: ${guild.name} (${guild.id})` + ); + + await audits.execute(member); + await joinMessage.execute(member); + await fetchUser(user, guild); + await updatePresence(client); }; diff --git a/src/events/guildMemberRemove/index.ts b/src/events/guildMemberRemove/index.ts index 3d28c31..2cb2d48 100644 --- a/src/events/guildMemberRemove/index.ts +++ b/src/events/guildMemberRemove/index.ts @@ -7,18 +7,21 @@ import dropUser from "@helpers/dropUser"; import logger from "@logger"; import leaveMessage from "./leaveMessage"; import audits from "./audits"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(member: GuildMember) { - const { client, user, guild } = member; - - logger?.silly( - `Removed member: ${user.tag} (${user.id}) from guild: ${guild.name} (${guild.id})` - ); - - await audits.execute(member); - await leaveMessage.execute(member); - await dropUser(user, guild); - await updatePresence(client); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (member: GuildMember) => { + const { client, user, guild } = member; + + logger?.silly( + `Removed member: ${user.tag} (${user.id}) from guild: ${guild.name} (${guild.id})` + ); + + await audits.execute(member); + await leaveMessage.execute(member); + await dropUser(user, guild); + await updatePresence(client); }; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 2848f39..e29deec 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -5,16 +5,19 @@ import { CommandInteraction } from "discord.js"; import isCommand from "@root/events/interactionCreate/components/isCommand"; import logger from "@logger"; import audits from "./audits"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(interaction: CommandInteraction) { - const { guild, id } = interaction; - - logger?.silly( - `New interaction: ${id} in guild: ${guild?.name} (${guild?.id})` - ); - - await audits.execute(interaction); - await isCommand(interaction); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (interaction: CommandInteraction) => { + const { guild, id } = interaction; + + logger?.silly( + `New interaction: ${id} in guild: ${guild?.name} (${guild?.id})` + ); + + await audits.execute(interaction); + await isCommand(interaction); }; diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 004ca71..6eb9744 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -1,10 +1,14 @@ import { Message } from "discord.js"; import modules from "@events/messageCreate/modules"; -export default { - async execute(message: Message) { - await modules.credits.execute(message); - await modules.points.execute(message); - await modules.counters.execute(message); - }, +import { IEventOptions } from "@root/interfaces/EventOptions"; + +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (message: Message) => { + await modules.credits.execute(message); + await modules.points.execute(message); + await modules.counters.execute(message); }; diff --git a/src/events/messageDelete/index.ts b/src/events/messageDelete/index.ts index 77223d2..f2c89c3 100644 --- a/src/events/messageDelete/index.ts +++ b/src/events/messageDelete/index.ts @@ -1,10 +1,13 @@ import { Message } from "discord.js"; import audits from "@events/messageDelete/audits"; import counter from "./modules/counter"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(message: Message) { - await audits.execute(message); - await counter(message); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (message: Message) => { + await audits.execute(message); + await counter(message); }; diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index 9238805..d22272c 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -6,19 +6,22 @@ import logger from "@logger"; import counter from "./modules/counter"; import audits from "./audits"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - async execute(oldMessage: Message, newMessage: Message) { - const { author, guild } = newMessage; - - await audits.execute(oldMessage, newMessage); - - logger?.silly( - `Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` - ); - - if (author?.bot) return logger?.silly(`Message update event fired by bot`); - - await counter(newMessage); - }, +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (oldMessage: Message, newMessage: Message) => { + const { author, guild } = newMessage; + + await audits.execute(oldMessage, newMessage); + + logger?.silly( + `Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` + ); + + if (author?.bot) return logger?.silly(`Message update event fired by bot`); + + await counter(newMessage); }; diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index b312f73..7f5ff67 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -6,20 +6,22 @@ import logger from "@logger"; import updatePresence from "@helpers/updatePresence"; import deployCommands from "@handlers/deployCommands"; import devMode from "@handlers/devMode"; +import { IEventOptions } from "@root/interfaces/EventOptions"; -export default { - once: true, - async execute(client: Client) { - logger.info("Ready!"); - - await updatePresence(client); - await devMode(client); - await deployCommands(client); - - client.guilds?.cache.forEach((guild) => { - logger.silly( - `${client.user?.tag} (${client.user?.id}) is in guild: ${guild.name} (${guild.id}) with member count of ${guild.memberCount}` - ); - }); - }, +export const options: IEventOptions = { + type: "once", +}; + +export const execute = async (client: Client) => { + logger.info("Ready!"); + + await updatePresence(client); + await devMode(client); + await deployCommands(client); + + client.guilds?.cache.forEach((guild) => { + logger.silly( + `${client.user?.tag} (${client.user?.id}) is in guild: ${guild.name} (${guild.id}) with member count of ${guild.memberCount}` + ); + }); }; diff --git a/src/handlers/events.ts b/src/handlers/events.ts deleted file mode 100644 index f7da9c1..0000000 --- a/src/handlers/events.ts +++ /dev/null @@ -1,37 +0,0 @@ -import fs from "fs"; // fs -import { Client } from "discord.js"; // discord.js -import logger from "@logger"; - -export default async (client: Client) => { - fs.readdir("./src/events", async (error, events) => { - if (error) { - return logger.error(`Error reading plugins: ${error}`); - } - - await Promise.all( - events.map(async (eventName, index) => { - const event = await import(`../events/${eventName}`); - - logger.verbose( - `Loaded event ${index + 1}/${events.length}: ${eventName}` - ); - - if (event.once) { - return client.once(eventName, async (...args) => - event.default.execute(...args) - ); - } - - return client.on(eventName, async (...args) => - event.default.execute(...args) - ); - }) - ) - .then(async () => { - logger.info(`Started all ${events.length} events.`); - }) - .catch(async (err) => { - logger.error(`${err}`); - }); - }); -}; diff --git a/src/helpers/listDir/index.ts b/src/helpers/listDir/index.ts new file mode 100644 index 0000000..247fbe0 --- /dev/null +++ b/src/helpers/listDir/index.ts @@ -0,0 +1,10 @@ +import fs from "fs"; +const fsPromises = fs.promises; + +export default async (path: string) => { + try { + return await fsPromises.readdir(path); + } catch (err) { + console.error("Error occurred while reading directory!", err); + } +}; diff --git a/src/index.ts b/src/index.ts index eaef4db..b1b7aca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { Client } from "discord.js"; // discord.js import database from "@database"; import schedules from "@handlers/schedules"; -import events from "@handlers/events"; +import * as eventManager from "@root/managers/event"; import commands from "@handlers/commands"; // Main process that starts all other sub processes @@ -26,7 +26,7 @@ const main = async () => { await commands(client); // Start event handler - await events(client); + await eventManager.register(client); // Authorize with Discord's API await client.login(token); diff --git a/src/interfaces/EventOptions.ts b/src/interfaces/EventOptions.ts new file mode 100644 index 0000000..7634394 --- /dev/null +++ b/src/interfaces/EventOptions.ts @@ -0,0 +1,3 @@ +export interface IEventOptions { + type: "on" | "once"; +} diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts new file mode 100644 index 0000000..6fa8a51 --- /dev/null +++ b/src/managers/event/index.ts @@ -0,0 +1,24 @@ +/* eslint-disable no-loops/no-loops */ +import { Client } from "discord.js"; +import listDir from "@helpers/listDir"; + +export const register = async (client: Client) => { + const eventNames = await listDir("src/events"); + if (!eventNames) return; + + for await (const eventName of eventNames) { + const event = await import(`../../events/${eventName}`); + const eventExecutor = async (...args: any[]) => event.execute(...args); + if (!event.options?.type) return; + + switch (event.options.type) { + case "once": + client.once(eventName, eventExecutor); + break; + + case "on": + client.on(eventName, eventExecutor); + break; + } + } +}; From 9bafd71cc052c08f8de920b6e7bfbd3ad905412c Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 13:24:25 +0200 Subject: [PATCH 14/75] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20reused=20interfac?= =?UTF-8?q?e=20for=20mongoose=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/schemas/api.ts | 3 ++- src/handlers/encryption.ts | 12 ++++-------- src/interfaces/EncryptionData.ts | 4 ++++ tsconfig.json | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 src/interfaces/EncryptionData.ts diff --git a/src/database/schemas/api.ts b/src/database/schemas/api.ts index 12519d2..ef4e817 100644 --- a/src/database/schemas/api.ts +++ b/src/database/schemas/api.ts @@ -1,10 +1,11 @@ import { Snowflake } from "discord.js"; import { model, Schema } from "mongoose"; +import { IEncryptionData } from "@interface/EncryptionData"; export interface IApi { guildId: Snowflake; url: string; - token: { iv: string; content: string }; + token: IEncryptionData; } const apiSchema = new Schema( diff --git a/src/handlers/encryption.ts b/src/handlers/encryption.ts index cab28ff..9e70939 100644 --- a/src/handlers/encryption.ts +++ b/src/handlers/encryption.ts @@ -1,16 +1,12 @@ import crypto from "crypto"; -// @ts-ignore import { secretKey, algorithm } from "@config/encryption"; +import { IEncryptionData } from "@interface/EncryptionData"; + const iv = crypto.randomBytes(16); -interface IEncrypt { - iv: string; - content: string; -} - -const encrypt = (text: crypto.BinaryLike): IEncrypt => { +const encrypt = (text: crypto.BinaryLike): IEncryptionData => { const cipher = crypto.createCipheriv(algorithm, secretKey, iv); const encrypted = Buffer.concat([cipher.update(text), cipher.final()]); @@ -20,7 +16,7 @@ const encrypt = (text: crypto.BinaryLike): IEncrypt => { }; }; -const decrypt = (hash: IEncrypt) => { +const decrypt = (hash: IEncryptionData) => { const decipher = crypto.createDecipheriv( algorithm, secretKey, diff --git a/src/interfaces/EncryptionData.ts b/src/interfaces/EncryptionData.ts new file mode 100644 index 0000000..ac41844 --- /dev/null +++ b/src/interfaces/EncryptionData.ts @@ -0,0 +1,4 @@ +export interface IEncryptionData { + iv: string; + content: string; +} diff --git a/tsconfig.json b/tsconfig.json index 8f7076a..0879e1c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,7 @@ "baseUrl": "./src", "typeRoots": ["/types/common", "./node_modules/@types"], "paths": { - "@interface/*": ["Interfaces/*"], + "@interface/*": ["interfaces/*"], "@root/*": ["*"], "@config/*": ["config/*"], "@events/*": ["events/*"], From ee57233499c8810493e12f7c8a5748e2848a3a33 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 13:25:53 +0200 Subject: [PATCH 15/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20helpe?= =?UTF-8?q?rs=20are=20now=20folders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{capitalizeFirstLetter.ts => capitalizeFirstLetter/index.ts} | 0 src/helpers/{deferReply.ts => deferReply/index.ts} | 0 src/helpers/{dropGuild.ts => dropGuild/index.ts} | 0 src/helpers/{dropUser.ts => dropUser/index.ts} | 0 src/helpers/{embedBuilder.ts => embedBuilder/index.ts} | 0 src/helpers/{fetchGuild.ts => fetchGuild/index.ts} | 0 src/helpers/{fetchUser.ts => fetchUser/index.ts} | 0 .../{getCommandMetadata.ts => getCommandMetadata/index.ts} | 0 src/helpers/{getEmbedConfig.ts => getEmbedConfig/index.ts} | 0 src/helpers/{pluralize.ts => pluralize/index.ts} | 0 src/helpers/{saveUser.ts => saveUser/index.ts} | 0 src/helpers/{sleep.ts => sleep/index.ts} | 0 src/helpers/{updatePresence.ts => updatePresence/index.ts} | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename src/helpers/{capitalizeFirstLetter.ts => capitalizeFirstLetter/index.ts} (100%) rename src/helpers/{deferReply.ts => deferReply/index.ts} (100%) rename src/helpers/{dropGuild.ts => dropGuild/index.ts} (100%) rename src/helpers/{dropUser.ts => dropUser/index.ts} (100%) rename src/helpers/{embedBuilder.ts => embedBuilder/index.ts} (100%) rename src/helpers/{fetchGuild.ts => fetchGuild/index.ts} (100%) rename src/helpers/{fetchUser.ts => fetchUser/index.ts} (100%) rename src/helpers/{getCommandMetadata.ts => getCommandMetadata/index.ts} (100%) rename src/helpers/{getEmbedConfig.ts => getEmbedConfig/index.ts} (100%) rename src/helpers/{pluralize.ts => pluralize/index.ts} (100%) rename src/helpers/{saveUser.ts => saveUser/index.ts} (100%) rename src/helpers/{sleep.ts => sleep/index.ts} (100%) rename src/helpers/{updatePresence.ts => updatePresence/index.ts} (100%) diff --git a/src/helpers/capitalizeFirstLetter.ts b/src/helpers/capitalizeFirstLetter/index.ts similarity index 100% rename from src/helpers/capitalizeFirstLetter.ts rename to src/helpers/capitalizeFirstLetter/index.ts diff --git a/src/helpers/deferReply.ts b/src/helpers/deferReply/index.ts similarity index 100% rename from src/helpers/deferReply.ts rename to src/helpers/deferReply/index.ts diff --git a/src/helpers/dropGuild.ts b/src/helpers/dropGuild/index.ts similarity index 100% rename from src/helpers/dropGuild.ts rename to src/helpers/dropGuild/index.ts diff --git a/src/helpers/dropUser.ts b/src/helpers/dropUser/index.ts similarity index 100% rename from src/helpers/dropUser.ts rename to src/helpers/dropUser/index.ts diff --git a/src/helpers/embedBuilder.ts b/src/helpers/embedBuilder/index.ts similarity index 100% rename from src/helpers/embedBuilder.ts rename to src/helpers/embedBuilder/index.ts diff --git a/src/helpers/fetchGuild.ts b/src/helpers/fetchGuild/index.ts similarity index 100% rename from src/helpers/fetchGuild.ts rename to src/helpers/fetchGuild/index.ts diff --git a/src/helpers/fetchUser.ts b/src/helpers/fetchUser/index.ts similarity index 100% rename from src/helpers/fetchUser.ts rename to src/helpers/fetchUser/index.ts diff --git a/src/helpers/getCommandMetadata.ts b/src/helpers/getCommandMetadata/index.ts similarity index 100% rename from src/helpers/getCommandMetadata.ts rename to src/helpers/getCommandMetadata/index.ts diff --git a/src/helpers/getEmbedConfig.ts b/src/helpers/getEmbedConfig/index.ts similarity index 100% rename from src/helpers/getEmbedConfig.ts rename to src/helpers/getEmbedConfig/index.ts diff --git a/src/helpers/pluralize.ts b/src/helpers/pluralize/index.ts similarity index 100% rename from src/helpers/pluralize.ts rename to src/helpers/pluralize/index.ts diff --git a/src/helpers/saveUser.ts b/src/helpers/saveUser/index.ts similarity index 100% rename from src/helpers/saveUser.ts rename to src/helpers/saveUser/index.ts diff --git a/src/helpers/sleep.ts b/src/helpers/sleep/index.ts similarity index 100% rename from src/helpers/sleep.ts rename to src/helpers/sleep/index.ts diff --git a/src/helpers/updatePresence.ts b/src/helpers/updatePresence/index.ts similarity index 100% rename from src/helpers/updatePresence.ts rename to src/helpers/updatePresence/index.ts From e3e054122e5206a04a0c9f03fdefa2b346f6da61 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 14:32:35 +0200 Subject: [PATCH 16/75] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20replace=20IPlugin?= =?UTF-8?q?Data=20with=20ICommand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/deployCommands.ts | 11 +++-------- src/helpers/getCommandMetadata/index.ts | 14 ++++++++------ src/interfaces/Command.ts | 7 +++++++ 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 src/interfaces/Command.ts diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 4ca0923..7883abd 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -1,24 +1,19 @@ -// @ts-ignore import { token, clientId } from "@config/discord"; -// @ts-ignore import { devMode, guildId } from "@config/other"; import logger from "../logger"; import { Client } from "@root/types/common/discord"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; -import { SlashCommandBuilder } from "@discordjs/builders"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; +import { ICommand } from "@interface/Command"; + export default async (client: Client) => { const pluginList: Array = []; - interface IPluginData { - builder: SlashCommandBuilder; - } - await Promise.all( - client.commands.map(async (pluginData: IPluginData) => { + client.commands.map(async (pluginData: ICommand) => { pluginList.push(pluginData.builder.toJSON()); logger.verbose( `Plugin is ready for deployment: ${pluginData.builder.name}` diff --git a/src/helpers/getCommandMetadata/index.ts b/src/helpers/getCommandMetadata/index.ts index 7894c00..fe7784b 100644 --- a/src/helpers/getCommandMetadata/index.ts +++ b/src/helpers/getCommandMetadata/index.ts @@ -1,12 +1,14 @@ import { CommandInteraction } from "discord.js"; +import { ICommand } from "@interface/Command"; -export default async (interaction: CommandInteraction, currentCommand: any) => { +export default async ( + interaction: CommandInteraction, + currentCommand: ICommand +) => { const subcommand = interaction.options.getSubcommand(); const subcommandGroup = interaction.options.getSubcommandGroup(false); - if (!subcommandGroup) { - return currentCommand.modules[subcommand].metadata; - } - - return currentCommand.modules[subcommandGroup].modules[subcommand].metadata; + return subcommandGroup + ? currentCommand.modules[subcommandGroup].modules[subcommand].metadata + : currentCommand.modules[subcommand].metadata; }; diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts new file mode 100644 index 0000000..34585d9 --- /dev/null +++ b/src/interfaces/Command.ts @@ -0,0 +1,7 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; + +export interface ICommand { + modules: any; + builder: SlashCommandBuilder; + execute: Promise; +} From efd7f245982a2e7a6a767d86c76e18f7234a115a Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 14:43:28 +0200 Subject: [PATCH 17/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20seper?= =?UTF-8?q?ated=20/config=20embeds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/config/modules/embeds.ts | 129 ------------------ .../embeds/components/getValues/index.ts | 38 ++++++ src/plugins/config/modules/embeds/index.ts | 104 ++++++++++++++ 3 files changed, 142 insertions(+), 129 deletions(-) delete mode 100644 src/plugins/config/modules/embeds.ts create mode 100644 src/plugins/config/modules/embeds/components/getValues/index.ts create mode 100644 src/plugins/config/modules/embeds/index.ts diff --git a/src/plugins/config/modules/embeds.ts b/src/plugins/config/modules/embeds.ts deleted file mode 100644 index f4f3a15..0000000 --- a/src/plugins/config/modules/embeds.ts +++ /dev/null @@ -1,129 +0,0 @@ -// Dependencies -import { ColorResolvable, CommandInteraction, Permissions } from "discord.js"; - -//Handlers -import logger from "@logger"; - -// Models -import guildSchema from "@schemas/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import getEmbedConfig from "@helpers/getEmbedConfig"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("embeds") - .setDescription(`Embeds`) - .addStringOption((option) => - option - .setName("success-color") - .setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("wait-color").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("error-color").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("footer-icon").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("footer-text").setDescription("No provided description") - ); - }, - execute: async (interaction: CommandInteraction) => { - // Destructure member - const { guild, options } = interaction; - - if (guild == null) return; - - const embedConfig = await getEmbedConfig(guild); - - if (embedConfig == null) return; - - logger.info(embedConfig); - - // Get options - const successColor = options?.getString("success-color") as ColorResolvable; - const waitColor = options?.getString("wait-color") as ColorResolvable; - const errorColor = options?.getString("error-color") as ColorResolvable; - const footerIcon = options?.getString("footer-icon"); - const footerText = options?.getString("footer-text"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild is null`); - } - - // Modify values - guildDB.embeds.successColor = - successColor !== null ? successColor : guildDB?.embeds?.successColor; - guildDB.embeds.waitColor = - waitColor !== null ? waitColor : guildDB?.embeds?.waitColor; - guildDB.embeds.errorColor = - errorColor !== null ? errorColor : guildDB?.embeds?.errorColor; - guildDB.embeds.footerIcon = - footerIcon !== null ? footerIcon : guildDB?.embeds?.footerIcon; - guildDB.embeds.footerText = - footerText !== null ? footerText : guildDB?.embeds?.footerText; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild saved`); - - return interaction?.editReply({ - embeds: [ - { - title: ":tools: Settings - Guild [Credits]", - description: `Credits settings updated.`, - color: successColor || embedConfig.successColor, - fields: [ - { - name: "🤖 Success Color", - value: `${guildDB?.embeds?.successColor}`, - inline: true, - }, - { - name: "📈 Wait Color", - value: `${guildDB?.embeds?.waitColor}`, - inline: true, - }, - { - name: "📈 Error Color", - value: `${guildDB?.embeds?.errorColor}`, - inline: true, - }, - { - name: "🔨 Footer Icon", - value: `${guildDB?.embeds?.footerIcon}`, - inline: true, - }, - { - name: "⏰ Footer Text", - value: `${guildDB?.embeds?.footerText}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon || embedConfig.footerIcon, - text: footerText || embedConfig.footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/plugins/config/modules/embeds/components/getValues/index.ts b/src/plugins/config/modules/embeds/components/getValues/index.ts new file mode 100644 index 0000000..f068ac4 --- /dev/null +++ b/src/plugins/config/modules/embeds/components/getValues/index.ts @@ -0,0 +1,38 @@ +import { ColorResolvable, CommandInteraction } from "discord.js"; +import guildSchema from "@schemas/guild"; +import getEmbedConfig from "@root/helpers/getEmbedConfig"; + +export default async (interaction: CommandInteraction) => { + const { options, guild } = interaction; + + if (!guild) throw new Error("Guild not found"); + + const embedConfig = await getEmbedConfig(guild); + if (!embedConfig) throw new Error("Embed config not found"); + + // Get new values + const newSuccessColor = options.getString("success-color") as ColorResolvable; + const newWaitColor = options.getString("wait-color") as ColorResolvable; + const newErrorColor = options.getString("error-color") as ColorResolvable; + const newFooterIcon = options.getString("footer-icon"); + const newFooterText = options.getString("footer-text"); + + // Get guild values + const guildData = await guildSchema.findOne({ + guildId: guild.id, + }); + if (!guildData) throw new Error("Guild data not found"); + if (!guildData?.embeds) + throw new Error("Guild embed configuration not found"); + let { successColor, waitColor, errorColor, footerText, footerIcon } = + guildData.embeds; + + // Set new values + successColor = newSuccessColor || successColor; + waitColor = newWaitColor || waitColor; + errorColor = newErrorColor || errorColor; + footerIcon = newFooterIcon || footerIcon; + footerText = newFooterText || footerText; + + return { successColor, waitColor, errorColor, footerText, footerIcon }; +}; diff --git a/src/plugins/config/modules/embeds/index.ts b/src/plugins/config/modules/embeds/index.ts new file mode 100644 index 0000000..32ad931 --- /dev/null +++ b/src/plugins/config/modules/embeds/index.ts @@ -0,0 +1,104 @@ +// Dependencies +import { + ColorResolvable, + CommandInteraction, + MessageEmbed, + Permissions, +} from "discord.js"; + +//Handlers +import logger from "@logger"; + +// Models +import guildSchema from "@schemas/guild"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import getEmbedConfig from "@helpers/getEmbedConfig"; +import getValues from "./components/getValues"; + +// Function +export default { + metadata: { + guildOnly: true, + ephemeral: true, + permissions: [Permissions.FLAGS.MANAGE_GUILD], + }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("embeds") + .setDescription(`Embeds`) + .addStringOption((option) => + option + .setName("success-color") + .setDescription("No provided description") + ) + .addStringOption((option) => + option.setName("wait-color").setDescription("No provided description") + ) + .addStringOption((option) => + option.setName("error-color").setDescription("No provided description") + ) + .addStringOption((option) => + option.setName("footer-icon").setDescription("No provided description") + ) + .addStringOption((option) => + option.setName("footer-text").setDescription("No provided description") + ); + }, + execute: async (interaction: CommandInteraction) => { + const { guild } = interaction; + if (!guild) throw new Error("Guild not found"); + + const { successColor, waitColor, errorColor, footerText, footerIcon } = + await getValues(interaction); + + // Initialize embed object + const embed = new MessageEmbed() + .setTitle("[:tools:] Embeds") + .setFooter({ text: footerText, iconURL: footerIcon }) + .setTimestamp(new Date()); + + // Get guild values + const guildData = await guildSchema.findOne({ + guildId: guild.id, + }); + if (!guildData) throw new Error("Guild data not found"); + + await guildData.save().then(async () => { + embed + .setDescription("Following embed configuration will be used.") + .setColor(successColor) + .addFields([ + { + name: "🟢 Success Color", + value: `${successColor}`, + inline: true, + }, + { + name: "🟡 Wait Color", + value: `${waitColor}`, + inline: true, + }, + { + name: "🔴 Error Color", + value: `${errorColor}`, + inline: true, + }, + { + name: "🖼️ Footer Icon", + value: `${footerIcon}`, + inline: true, + }, + { + name: "📄 Footer Text", + value: `${footerText}`, + inline: true, + }, + ]); + + return interaction.editReply({ + embeds: [embed], + }); + }); + }, +}; From 598bff90c87426985970aba2e427683fa29a1b4d Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 28 May 2022 17:35:00 +0200 Subject: [PATCH 18/75] =?UTF-8?q?=F0=9F=9A=9A=20config=20modules=20are=20n?= =?UTF-8?q?ow=20folders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/{audits.ts => audits/index.ts} | 0 .../modules/{credits.ts => credits/index.ts} | 0 .../modules/{points.ts => points/index.ts} | 0 .../{pterodactyl.ts => pterodactyl/index.ts} | 0 .../config/modules/{shop.ts => shop/index.ts} | 0 .../modules/{welcome.ts => welcome/index.ts} | 58 +++++++++---------- 6 files changed, 29 insertions(+), 29 deletions(-) rename src/plugins/config/modules/{audits.ts => audits/index.ts} (100%) rename src/plugins/config/modules/{credits.ts => credits/index.ts} (100%) rename src/plugins/config/modules/{points.ts => points/index.ts} (100%) rename src/plugins/config/modules/{pterodactyl.ts => pterodactyl/index.ts} (100%) rename src/plugins/config/modules/{shop.ts => shop/index.ts} (100%) rename src/plugins/config/modules/{welcome.ts => welcome/index.ts} (77%) diff --git a/src/plugins/config/modules/audits.ts b/src/plugins/config/modules/audits/index.ts similarity index 100% rename from src/plugins/config/modules/audits.ts rename to src/plugins/config/modules/audits/index.ts diff --git a/src/plugins/config/modules/credits.ts b/src/plugins/config/modules/credits/index.ts similarity index 100% rename from src/plugins/config/modules/credits.ts rename to src/plugins/config/modules/credits/index.ts diff --git a/src/plugins/config/modules/points.ts b/src/plugins/config/modules/points/index.ts similarity index 100% rename from src/plugins/config/modules/points.ts rename to src/plugins/config/modules/points/index.ts diff --git a/src/plugins/config/modules/pterodactyl.ts b/src/plugins/config/modules/pterodactyl/index.ts similarity index 100% rename from src/plugins/config/modules/pterodactyl.ts rename to src/plugins/config/modules/pterodactyl/index.ts diff --git a/src/plugins/config/modules/shop.ts b/src/plugins/config/modules/shop/index.ts similarity index 100% rename from src/plugins/config/modules/shop.ts rename to src/plugins/config/modules/shop/index.ts diff --git a/src/plugins/config/modules/welcome.ts b/src/plugins/config/modules/welcome/index.ts similarity index 77% rename from src/plugins/config/modules/welcome.ts rename to src/plugins/config/modules/welcome/index.ts index 48399c7..bdd962b 100644 --- a/src/plugins/config/modules/welcome.ts +++ b/src/plugins/config/modules/welcome/index.ts @@ -96,39 +96,39 @@ export default { await guildDB?.save()?.then(async () => { logger?.silly(`Guild welcome updated.`); + if (!guildDB?.welcome?.status) { + return interaction?.editReply({ + embeds: [ + { + title: "[:tools:] Welcome", + description: `This module is currently disabled, please enable it to continue.`, + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + } + return interaction?.editReply({ embeds: [ { - title: ":hammer: Settings - Guild [Welcome]", - description: `Welcome settings updated.`, + title: "[:tools:] Welcome", + description: `The following configuration will be used. + + [👋] **Welcome** + + ㅤ**Channel**: <#${guildDB?.welcome?.joinChannel}> + ㅤ**Message**: ${guildDB?.welcome?.joinChannelMessage} + + [🚪] **Leave** + + ㅤ**Channel**: <#${guildDB?.welcome?.leaveChannel}> + ㅤ**Message**: ${guildDB?.welcome?.leaveChannelMessage}`, color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.welcome?.status}`, - inline: true, - }, - { - name: "🌊 Join Channel", - value: `${guildDB?.welcome?.joinChannel}`, - inline: true, - }, - { - name: "🌊 Leave Channel", - value: `${guildDB?.welcome?.leaveChannel}`, - inline: true, - }, - { - name: "📄 Join Channel Message", - value: `${guildDB?.welcome?.joinChannelMessage}`, - inline: true, - }, - { - name: "📄 Leave Channel Message", - value: `${guildDB?.welcome?.leaveChannelMessage}`, - inline: true, - }, - ], timestamp: new Date(), footer: { iconURL: footerIcon, From 2d3d7fe7aa69b1ab1b8c446e52032f4dfc48f718 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 19:06:31 +0200 Subject: [PATCH 19/75] =?UTF-8?q?=F0=9F=9A=A8=20reverted=20from=20absolute?= =?UTF-8?q?=20to=20relative=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ src/database/index.ts | 4 ++-- src/database/schemas/api.ts | 2 +- src/events/guildCreate/index.ts | 8 ++++---- src/events/guildDelete/index.ts | 8 ++++---- src/events/guildMemberAdd/audits.ts | 6 +++--- src/events/guildMemberAdd/index.ts | 8 ++++---- src/events/guildMemberAdd/joinMessage.ts | 4 ++-- src/events/guildMemberRemove/audits.ts | 6 +++--- src/events/guildMemberRemove/index.ts | 8 ++++---- src/events/guildMemberRemove/leaveMessage.ts | 4 ++-- src/events/interactionCreate/audits.ts | 6 +++--- .../interactionCreate/components/isCommand.ts | 10 +++++----- src/events/interactionCreate/index.ts | 6 +++--- src/events/messageCreate/index.ts | 4 ++-- src/events/messageCreate/modules/counters/index.ts | 4 ++-- src/events/messageCreate/modules/credits/index.ts | 8 ++++---- src/events/messageCreate/modules/index.ts | 6 +++--- src/events/messageCreate/modules/points/index.ts | 8 ++++---- src/events/messageDelete/audits.ts | 6 +++--- src/events/messageDelete/index.ts | 4 ++-- src/events/messageDelete/modules/counter.ts | 4 ++-- src/events/messageUpdate/audits.ts | 6 +++--- src/events/messageUpdate/index.ts | 4 ++-- src/events/messageUpdate/modules/counter.ts | 4 ++-- src/events/ready/index.ts | 10 +++++----- src/handlers/commands.ts | 14 +++++--------- src/handlers/deployCommands.ts | 8 ++++---- src/handlers/devMode.ts | 4 ++-- src/handlers/encryption.ts | 4 ++-- src/handlers/schedules/index.ts | 4 ++-- src/helpers/deferReply/index.ts | 2 +- src/helpers/dropGuild/index.ts | 14 +++++++------- src/helpers/dropUser/index.ts | 4 ++-- src/helpers/embedBuilder/index.ts | 2 +- src/helpers/fetchGuild/index.ts | 4 ++-- src/helpers/fetchUser/index.ts | 4 ++-- src/helpers/getCommandMetadata/index.ts | 2 +- src/helpers/getEmbedConfig/index.ts | 4 ++-- src/helpers/pluralize/index.ts | 2 +- src/helpers/saveUser/index.ts | 4 ++-- src/helpers/sleep/index.ts | 2 +- src/helpers/updatePresence/index.ts | 2 +- src/index.ts | 10 +++++----- src/jobs/shopRoles.ts | 8 ++++---- src/managers/event/index.ts | 2 +- src/plugins/config/index.ts | 2 +- src/plugins/config/modules/audits/index.ts | 6 +++--- src/plugins/config/modules/credits/index.ts | 6 +++--- .../modules/embeds/components/getValues/index.ts | 4 ++-- src/plugins/config/modules/embeds/index.ts | 6 +++--- src/plugins/config/modules/index.ts | 14 +++++++------- src/plugins/config/modules/points/index.ts | 6 +++--- src/plugins/config/modules/pterodactyl/index.ts | 8 ++++---- src/plugins/config/modules/shop/index.ts | 6 +++--- src/plugins/config/modules/welcome/index.ts | 6 +++--- src/plugins/counters/index.ts | 4 ++-- src/plugins/counters/modules/index.ts | 2 +- src/plugins/counters/modules/view/index.ts | 4 ++-- src/plugins/credits/index.ts | 4 ++-- src/plugins/credits/modules/balance/index.ts | 6 +++--- src/plugins/credits/modules/gift/index.ts | 8 ++++---- src/plugins/credits/modules/index.ts | 8 ++++---- src/plugins/credits/modules/top/index.ts | 6 +++--- src/plugins/credits/modules/work/index.ts | 10 +++++----- src/plugins/fun/index.ts | 4 ++-- src/plugins/fun/modules/index.ts | 2 +- src/plugins/fun/modules/meme/index.ts | 4 ++-- src/plugins/manage/index.ts | 4 ++-- src/plugins/manage/modules/counters/index.ts | 2 +- .../manage/modules/counters/modules/add/index.ts | 6 +++--- .../manage/modules/counters/modules/index.ts | 4 ++-- .../modules/counters/modules/remove/index.ts | 6 +++--- src/plugins/manage/modules/credits/index.ts | 2 +- .../manage/modules/credits/modules/give/index.ts | 8 ++++---- .../manage/modules/credits/modules/index.ts | 8 ++++---- .../manage/modules/credits/modules/set/index.ts | 6 +++--- .../manage/modules/credits/modules/take/index.ts | 8 ++++---- .../modules/credits/modules/transfer/index.ts | 8 ++++---- src/plugins/manage/modules/index.ts | 4 ++-- src/plugins/profile/index.ts | 4 ++-- src/plugins/profile/modules/index.ts | 2 +- src/plugins/profile/modules/view.ts | 6 +++--- src/plugins/reputation/index.ts | 2 +- src/plugins/reputation/modules/give.ts | 10 +++++----- src/plugins/reputation/modules/index.ts | 2 +- src/plugins/shop/modules/index.ts | 4 ++-- src/plugins/shop/modules/pterodactyl.ts | 12 ++++++------ src/plugins/shop/modules/roles/index.ts | 6 +++--- src/plugins/shop/modules/roles/modules/buy.ts | 12 ++++++------ src/plugins/shop/modules/roles/modules/cancel.ts | 10 +++++----- src/plugins/utility/index.ts | 2 +- src/plugins/utility/modules/about.ts | 4 ++-- src/plugins/utility/modules/avatar.ts | 2 +- src/plugins/utility/modules/index.ts | 8 ++++---- src/plugins/utility/modules/lookup.ts | 4 ++-- src/plugins/utility/modules/stats.ts | 2 +- src/types/common/discord.d.ts | 5 +++-- 98 files changed, 270 insertions(+), 270 deletions(-) diff --git a/.gitignore b/.gitignore index 0ae1541..9f176fb 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ package-lock.json !**/config/index.ts !**/config/example.*.ts +# Build +build/ + # Logs logs diff --git a/src/database/index.ts b/src/database/index.ts index b7dd3b6..9060935 100644 --- a/src/database/index.ts +++ b/src/database/index.ts @@ -2,10 +2,10 @@ import mongoose from "mongoose"; // Dependencies -import logger from "@logger"; +import logger from "../logger"; // Configuration -import { url } from "@config/database"; +import { url } from "../config/database"; export default async () => { await mongoose.connect(url).then(async (connection) => { diff --git a/src/database/schemas/api.ts b/src/database/schemas/api.ts index ef4e817..5a78afd 100644 --- a/src/database/schemas/api.ts +++ b/src/database/schemas/api.ts @@ -1,6 +1,6 @@ import { Snowflake } from "discord.js"; import { model, Schema } from "mongoose"; -import { IEncryptionData } from "@interface/EncryptionData"; +import { IEncryptionData } from "../../interfaces/EncryptionData"; export interface IApi { guildId: Snowflake; diff --git a/src/events/guildCreate/index.ts b/src/events/guildCreate/index.ts index d76b9a2..a309884 100644 --- a/src/events/guildCreate/index.ts +++ b/src/events/guildCreate/index.ts @@ -1,8 +1,8 @@ import { Guild } from "discord.js"; -import updatePresence from "@helpers/updatePresence"; -import fetchGuild from "@helpers/fetchGuild"; -import logger from "@logger"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import updatePresence from "../../helpers/updatePresence"; +import fetchGuild from "../../helpers/fetchGuild"; +import logger from "../../logger"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildDelete/index.ts b/src/events/guildDelete/index.ts index 741b69c..be090b8 100644 --- a/src/events/guildDelete/index.ts +++ b/src/events/guildDelete/index.ts @@ -2,10 +2,10 @@ import { Guild } from "discord.js"; // Dependencies -import updatePresence from "@helpers/updatePresence"; -import dropGuild from "@helpers/dropGuild"; -import logger from "@logger"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import updatePresence from "../../helpers/updatePresence"; +import dropGuild from "../../helpers/dropGuild"; +import logger from "../../logger"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberAdd/audits.ts b/src/events/guildMemberAdd/audits.ts index c47c78e..6e140c6 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/events/guildMemberAdd/audits.ts @@ -1,9 +1,9 @@ -import logger from "@logger"; +import logger from "../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberAdd/index.ts b/src/events/guildMemberAdd/index.ts index 2cda131..0dff9bf 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/events/guildMemberAdd/index.ts @@ -2,12 +2,12 @@ import { GuildMember } from "discord.js"; // Dependencies -import updatePresence from "@helpers/updatePresence"; -import fetchUser from "@helpers/fetchUser"; -import logger from "@logger"; +import updatePresence from "../../helpers/updatePresence"; +import fetchUser from "../../helpers/fetchUser"; +import logger from "../../logger"; import joinMessage from "../guildMemberAdd/joinMessage"; import audits from "../guildMemberAdd/audits"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberAdd/joinMessage.ts b/src/events/guildMemberAdd/joinMessage.ts index bf7aec3..db0a745 100644 --- a/src/events/guildMemberAdd/joinMessage.ts +++ b/src/events/guildMemberAdd/joinMessage.ts @@ -1,8 +1,8 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberRemove/audits.ts b/src/events/guildMemberRemove/audits.ts index 620e52e..9f2c343 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/events/guildMemberRemove/audits.ts @@ -1,9 +1,9 @@ -import logger from "@logger"; +import logger from "../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberRemove/index.ts b/src/events/guildMemberRemove/index.ts index 2cb2d48..502aad4 100644 --- a/src/events/guildMemberRemove/index.ts +++ b/src/events/guildMemberRemove/index.ts @@ -2,12 +2,12 @@ import { GuildMember } from "discord.js"; // Dependencies -import updatePresence from "@helpers/updatePresence"; -import dropUser from "@helpers/dropUser"; -import logger from "@logger"; +import updatePresence from "../../helpers/updatePresence"; +import dropUser from "../../helpers/dropUser"; +import logger from "../../logger"; import leaveMessage from "./leaveMessage"; import audits from "./audits"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberRemove/leaveMessage.ts b/src/events/guildMemberRemove/leaveMessage.ts index efed730..427866b 100644 --- a/src/events/guildMemberRemove/leaveMessage.ts +++ b/src/events/guildMemberRemove/leaveMessage.ts @@ -1,8 +1,8 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/interactionCreate/audits.ts b/src/events/interactionCreate/audits.ts index c6df788..3a311c5 100644 --- a/src/events/interactionCreate/audits.ts +++ b/src/events/interactionCreate/audits.ts @@ -1,9 +1,9 @@ -import logger from "@logger"; +import logger from "../../logger"; import { Interaction, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (interaction: Interaction) => { diff --git a/src/events/interactionCreate/components/isCommand.ts b/src/events/interactionCreate/components/isCommand.ts index 91c61dd..3addf8b 100644 --- a/src/events/interactionCreate/components/isCommand.ts +++ b/src/events/interactionCreate/components/isCommand.ts @@ -1,12 +1,12 @@ // Dependencies import { CommandInteraction, MessageEmbed } from "discord.js"; -import logger from "@logger"; +import logger from "../../../logger"; -import deferReply from "@root/helpers/deferReply"; -import getEmbedConfig from "@helpers/getEmbedConfig"; -import getCommandMetadata from "@helpers/getCommandMetadata"; -import capitalizeFirstLetter from "@helpers/capitalizeFirstLetter"; +import deferReply from "../../../helpers/deferReply"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getCommandMetadata from "../../../helpers/getCommandMetadata"; +import capitalizeFirstLetter from "../../../helpers/capitalizeFirstLetter"; export default async (interaction: CommandInteraction) => { if (!interaction.isCommand()) return; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index e29deec..7e173dc 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -2,10 +2,10 @@ import { CommandInteraction } from "discord.js"; // Dependencies -import isCommand from "@root/events/interactionCreate/components/isCommand"; -import logger from "@logger"; +import isCommand from "../../events/interactionCreate/components/isCommand"; +import logger from "../../logger"; import audits from "./audits"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageCreate/index.ts b/src/events/messageCreate/index.ts index 6eb9744..f5beddf 100644 --- a/src/events/messageCreate/index.ts +++ b/src/events/messageCreate/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; -import modules from "@events/messageCreate/modules"; +import modules from "../../events/messageCreate/modules"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageCreate/modules/counters/index.ts b/src/events/messageCreate/modules/counters/index.ts index a65a4db..882fbc6 100644 --- a/src/events/messageCreate/modules/counters/index.ts +++ b/src/events/messageCreate/modules/counters/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; -import logger from "@logger"; -import counterSchema from "@schemas/counter"; +import logger from "../../../../logger"; +import counterSchema from "../../../../database/schemas/counter"; export default { execute: async (message: Message) => { diff --git a/src/events/messageCreate/modules/credits/index.ts b/src/events/messageCreate/modules/credits/index.ts index 856c308..1058490 100644 --- a/src/events/messageCreate/modules/credits/index.ts +++ b/src/events/messageCreate/modules/credits/index.ts @@ -1,9 +1,9 @@ -import logger from "@logger"; -import timeouts from "@schemas/timeout"; +import logger from "../../../../logger"; +import timeouts from "../../../../database/schemas/timeout"; import { Message } from "discord.js"; -import fetchUser from "@helpers/fetchUser"; -import fetchGuild from "@helpers/fetchGuild"; +import fetchUser from "../../../../helpers/fetchUser"; +import fetchGuild from "../../../../helpers/fetchGuild"; export default { execute: async (message: Message) => { diff --git a/src/events/messageCreate/modules/index.ts b/src/events/messageCreate/modules/index.ts index e2d04fb..aff2dd3 100644 --- a/src/events/messageCreate/modules/index.ts +++ b/src/events/messageCreate/modules/index.ts @@ -1,6 +1,6 @@ -import counters from "@events/messageCreate/modules/counters"; -import credits from "@events/messageCreate/modules/credits"; -import points from "@events/messageCreate/modules/points"; +import counters from "./counters"; +import credits from "./credits"; +import points from "./points"; export default { counters, diff --git a/src/events/messageCreate/modules/points/index.ts b/src/events/messageCreate/modules/points/index.ts index e4d3aa4..12b683a 100644 --- a/src/events/messageCreate/modules/points/index.ts +++ b/src/events/messageCreate/modules/points/index.ts @@ -1,8 +1,8 @@ -import logger from "@logger"; -import timeouts from "@schemas/timeout"; +import logger from "../../../../logger"; +import timeouts from "../../../../database/schemas/timeout"; -import fetchUser from "@helpers/fetchUser"; -import fetchGuild from "@helpers/fetchGuild"; +import fetchUser from "../../../../helpers/fetchUser"; +import fetchGuild from "../../../../helpers/fetchGuild"; import { Message } from "discord.js"; export default { diff --git a/src/events/messageDelete/audits.ts b/src/events/messageDelete/audits.ts index 1f37b59..eb28000 100644 --- a/src/events/messageDelete/audits.ts +++ b/src/events/messageDelete/audits.ts @@ -1,9 +1,9 @@ -import logger from "@logger"; +import logger from "../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (message: Message) => { diff --git a/src/events/messageDelete/index.ts b/src/events/messageDelete/index.ts index f2c89c3..7279add 100644 --- a/src/events/messageDelete/index.ts +++ b/src/events/messageDelete/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; -import audits from "@events/messageDelete/audits"; +import audits from "../../events/messageDelete/audits"; import counter from "./modules/counter"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageDelete/modules/counter.ts b/src/events/messageDelete/modules/counter.ts index 6169b45..e488ae4 100644 --- a/src/events/messageDelete/modules/counter.ts +++ b/src/events/messageDelete/modules/counter.ts @@ -2,8 +2,8 @@ import { Message } from "discord.js"; // Models -import counterSchema from "@schemas/counter"; -import logger from "@logger"; +import counterSchema from "../../../database/schemas/counter"; +import logger from "../../../logger"; export default async (message: Message) => { const { guild, channel, author, content } = message; diff --git a/src/events/messageUpdate/audits.ts b/src/events/messageUpdate/audits.ts index c9bed8a..3438666 100644 --- a/src/events/messageUpdate/audits.ts +++ b/src/events/messageUpdate/audits.ts @@ -1,10 +1,10 @@ /* eslint-disable no-loops/no-loops */ -import logger from "@logger"; +import logger from "../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (oldMessage: Message, newMessage: Message) => { diff --git a/src/events/messageUpdate/index.ts b/src/events/messageUpdate/index.ts index d22272c..263d53e 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/events/messageUpdate/index.ts @@ -1,12 +1,12 @@ // Dependencies import { Message } from "discord.js"; -import logger from "@logger"; +import logger from "../../logger"; // Modules import counter from "./modules/counter"; import audits from "./audits"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageUpdate/modules/counter.ts b/src/events/messageUpdate/modules/counter.ts index 465b00a..8ea7087 100644 --- a/src/events/messageUpdate/modules/counter.ts +++ b/src/events/messageUpdate/modules/counter.ts @@ -2,8 +2,8 @@ import { Message } from "discord.js"; // Models -import counterSchema from "@schemas/counter"; -import logger from "@logger"; +import counterSchema from "../../../database/schemas/counter"; +import logger from "../../../logger"; export default async (message: Message) => { const { guild, channel, author, content } = message; diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 7f5ff67..61ce106 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -1,12 +1,12 @@ // Dependencies import { Client } from "discord.js"; -import logger from "@logger"; +import logger from "../../logger"; // Helpers -import updatePresence from "@helpers/updatePresence"; -import deployCommands from "@handlers/deployCommands"; -import devMode from "@handlers/devMode"; -import { IEventOptions } from "@root/interfaces/EventOptions"; +import updatePresence from "../../helpers/updatePresence"; +import deployCommands from "../../handlers/deployCommands"; +import devMode from "../../handlers/devMode"; +import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { type: "once", diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index 81b1eeb..8b75999 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -1,7 +1,7 @@ import fs from "fs"; // fs -import { Collection } from "discord.js"; // discord.js -import { Client } from "@root/types/common/discord"; -import logger from "@logger"; +import { Collection, Client } from "discord.js"; // discord.js +import logger from "../logger"; +import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { client.commands = new Collection(); @@ -13,13 +13,9 @@ export default async (client: Client) => { await Promise.all( plugins.map(async (pluginName, index) => { - const plugin = await import(`../plugins/${pluginName}`); + const plugin: ICommand = await import(`../plugins/${pluginName}`); - await client.commands.set( - plugin.default.builder.name, - plugin.default, - plugin.default.metadata - ); + await client.commands.set(plugin.builder.name, plugin); logger.verbose( `Loaded plugin ${index + 1}/${plugins.length}: ${pluginName}` diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 7883abd..e0fe066 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -1,13 +1,13 @@ -import { token, clientId } from "@config/discord"; -import { devMode, guildId } from "@config/other"; +import { token, clientId } from "../config/discord"; +import { devMode, guildId } from "../config/other"; import logger from "../logger"; -import { Client } from "@root/types/common/discord"; +import { Client } from "discord.js"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; -import { ICommand } from "@interface/Command"; +import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { const pluginList: Array = []; diff --git a/src/handlers/devMode.ts b/src/handlers/devMode.ts index 53a2cd6..764fbcf 100644 --- a/src/handlers/devMode.ts +++ b/src/handlers/devMode.ts @@ -1,10 +1,10 @@ // Dependencies import { Client } from "discord.js"; -import logger from "@logger"; +import logger from "../logger"; // Configuration -import { devMode, guildId } from "@config/other"; +import { devMode, guildId } from "../config/other"; export default async (client: Client) => { if (!devMode) { diff --git a/src/handlers/encryption.ts b/src/handlers/encryption.ts index 9e70939..de5a7b9 100644 --- a/src/handlers/encryption.ts +++ b/src/handlers/encryption.ts @@ -1,8 +1,8 @@ import crypto from "crypto"; -import { secretKey, algorithm } from "@config/encryption"; +import { secretKey, algorithm } from "../config/encryption"; -import { IEncryptionData } from "@interface/EncryptionData"; +import { IEncryptionData } from "../interfaces/EncryptionData"; const iv = crypto.randomBytes(16); diff --git a/src/handlers/schedules/index.ts b/src/handlers/schedules/index.ts index 20ed685..c6a1cef 100644 --- a/src/handlers/schedules/index.ts +++ b/src/handlers/schedules/index.ts @@ -2,10 +2,10 @@ import { Client } from "discord.js"; import schedule from "node-schedule"; -import logger from "@logger"; +import logger from "../../logger"; // Jobs -import shopRoles from "@jobs/shopRoles"; +import shopRoles from "../../jobs/shopRoles"; export default async (client: Client) => { const expression = "*/5 * * * *"; diff --git a/src/helpers/deferReply/index.ts b/src/helpers/deferReply/index.ts index feec1a7..45d95ed 100644 --- a/src/helpers/deferReply/index.ts +++ b/src/helpers/deferReply/index.ts @@ -1,5 +1,5 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../helpers/getEmbedConfig"; export default async (interaction: CommandInteraction, ephemeral: boolean) => { if (interaction.guild == null) return; diff --git a/src/helpers/dropGuild/index.ts b/src/helpers/dropGuild/index.ts index d69d09b..e0d8356 100644 --- a/src/helpers/dropGuild/index.ts +++ b/src/helpers/dropGuild/index.ts @@ -1,11 +1,11 @@ -import guildSchema from "@schemas/guild"; -import userSchema from "@schemas/user"; -import apiSchema from "@schemas/api"; -import counterSchema from "@schemas/counter"; -import shopRoleSchema from "@schemas/shopRole"; -import timeoutSchema from "@schemas/timeout"; +import guildSchema from "../../database/schemas/guild"; +import userSchema from "../../database/schemas/user"; +import apiSchema from "../../database/schemas/api"; +import counterSchema from "../../database/schemas/counter"; +import shopRoleSchema from "../../database/schemas/shopRole"; +import timeoutSchema from "../../database/schemas/timeout"; -import logger from "@logger"; +import logger from "../../logger"; import { Guild } from "discord.js"; diff --git a/src/helpers/dropUser/index.ts b/src/helpers/dropUser/index.ts index 8306285..976cd6c 100644 --- a/src/helpers/dropUser/index.ts +++ b/src/helpers/dropUser/index.ts @@ -1,6 +1,6 @@ -import userSchema from "@schemas/user"; +import userSchema from "../../database/schemas/user"; -import logger from "@logger"; +import logger from "../../logger"; import { Guild, User } from "discord.js"; diff --git a/src/helpers/embedBuilder/index.ts b/src/helpers/embedBuilder/index.ts index 8d15d90..d93cc5c 100644 --- a/src/helpers/embedBuilder/index.ts +++ b/src/helpers/embedBuilder/index.ts @@ -1,4 +1,4 @@ -import { footerText, footerIcon } from "@config/embed"; +import { footerText, footerIcon } from "../../config/embed"; import { MessageEmbed } from "discord.js"; export default new MessageEmbed() diff --git a/src/helpers/fetchGuild/index.ts b/src/helpers/fetchGuild/index.ts index 4c8f107..bf4aff5 100644 --- a/src/helpers/fetchGuild/index.ts +++ b/src/helpers/fetchGuild/index.ts @@ -2,10 +2,10 @@ import { Guild } from "discord.js"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../database/schemas/guild"; // Handlers -import logger from "@logger"; +import logger from "../../logger"; // Function export default async (guild: Guild) => { diff --git a/src/helpers/fetchUser/index.ts b/src/helpers/fetchUser/index.ts index 96386ef..19b9f1f 100644 --- a/src/helpers/fetchUser/index.ts +++ b/src/helpers/fetchUser/index.ts @@ -2,10 +2,10 @@ import { Guild, User } from "discord.js"; // Models -import userSchema from "@schemas/user"; +import userSchema from "../../database/schemas/user"; // Handlers -import logger from "@logger"; +import logger from "../../logger"; // Function export default async (user: User, guild: Guild) => { diff --git a/src/helpers/getCommandMetadata/index.ts b/src/helpers/getCommandMetadata/index.ts index fe7784b..71940d2 100644 --- a/src/helpers/getCommandMetadata/index.ts +++ b/src/helpers/getCommandMetadata/index.ts @@ -1,5 +1,5 @@ import { CommandInteraction } from "discord.js"; -import { ICommand } from "@interface/Command"; +import { ICommand } from "../../interfaces/Command"; export default async ( interaction: CommandInteraction, diff --git a/src/helpers/getEmbedConfig/index.ts b/src/helpers/getEmbedConfig/index.ts index df62073..a52cbe5 100644 --- a/src/helpers/getEmbedConfig/index.ts +++ b/src/helpers/getEmbedConfig/index.ts @@ -1,5 +1,5 @@ -import guildSchema from "@schemas/guild"; -import * as embedConfig from "@config/embed"; +import guildSchema from "../../database/schemas/guild"; +import * as embedConfig from "../../config/embed"; import { Guild } from "discord.js"; diff --git a/src/helpers/pluralize/index.ts b/src/helpers/pluralize/index.ts index 3c5d55f..d6e266d 100644 --- a/src/helpers/pluralize/index.ts +++ b/src/helpers/pluralize/index.ts @@ -1,4 +1,4 @@ -import logger from "@root/logger"; +import logger from "../../logger"; export default (count: number, noun: string, suffix?: string): string => { const result = `${count} ${noun}${count !== 1 ? suffix || "s" : ""}`; diff --git a/src/helpers/saveUser/index.ts b/src/helpers/saveUser/index.ts index 8feb92e..2608bd4 100644 --- a/src/helpers/saveUser/index.ts +++ b/src/helpers/saveUser/index.ts @@ -1,5 +1,5 @@ -import sleep from "@helpers/sleep"; -import logger from "@logger"; +import sleep from "../../helpers/sleep"; +import logger from "../../logger"; import Chance from "chance"; export default async function saveUser(data: any, data2: any) { diff --git a/src/helpers/sleep/index.ts b/src/helpers/sleep/index.ts index 792c81f..d69f15b 100644 --- a/src/helpers/sleep/index.ts +++ b/src/helpers/sleep/index.ts @@ -1,4 +1,4 @@ -import logger from "@logger"; +import logger from "../../logger"; export default function sleep(milliseconds: number) { return new Promise((resolve) => { diff --git a/src/helpers/updatePresence/index.ts b/src/helpers/updatePresence/index.ts index 7f23885..3add873 100644 --- a/src/helpers/updatePresence/index.ts +++ b/src/helpers/updatePresence/index.ts @@ -1,6 +1,6 @@ // Dependencies import { Client } from "discord.js"; -import logger from "@logger"; +import logger from "../../logger"; // Function export default async (client: Client) => { diff --git a/src/index.ts b/src/index.ts index b1b7aca..cad389c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ import "tsconfig-paths/register"; // Allows using tsconfig.json paths during runtime -import { token, intents } from "@config/discord"; +import { token, intents } from "./config/discord"; import { Client } from "discord.js"; // discord.js -import database from "@database"; -import schedules from "@handlers/schedules"; -import * as eventManager from "@root/managers/event"; -import commands from "@handlers/commands"; +import database from "./database"; +import schedules from "./handlers/schedules"; +import * as eventManager from "./managers/event"; +import commands from "./handlers/commands"; // Main process that starts all other sub processes const main = async () => { diff --git a/src/jobs/shopRoles.ts b/src/jobs/shopRoles.ts index b42a3f5..76ea653 100644 --- a/src/jobs/shopRoles.ts +++ b/src/jobs/shopRoles.ts @@ -1,12 +1,12 @@ // Dependencies import { Client } from "discord.js"; -import logger from "@logger"; +import logger from "../logger"; // Schemas -import userSchema from "@schemas/user"; -import shopRoleSchema from "@schemas/shopRole"; -import guildSchema from "@schemas/guild"; +import userSchema from "../database/schemas/user"; +import shopRoleSchema from "../database/schemas/shopRole"; +import guildSchema from "../database/schemas/guild"; export default async (client: Client) => { const roles = await shopRoleSchema.find(); diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 6fa8a51..be51927 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -1,6 +1,6 @@ /* eslint-disable no-loops/no-loops */ import { Client } from "discord.js"; -import listDir from "@helpers/listDir"; +import listDir from "../../helpers/listDir"; export const register = async (client: Client) => { const eventNames = await listDir("src/events"); diff --git a/src/plugins/config/index.ts b/src/plugins/config/index.ts index 9cf1ab4..0b82732 100644 --- a/src/plugins/config/index.ts +++ b/src/plugins/config/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "@logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/plugins/config/modules/audits/index.ts b/src/plugins/config/modules/audits/index.ts index 817c990..0ea9a17 100644 --- a/src/plugins/config/modules/audits/index.ts +++ b/src/plugins/config/modules/audits/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/plugins/config/modules/credits/index.ts b/src/plugins/config/modules/credits/index.ts index 3e20851..8ec5998 100644 --- a/src/plugins/config/modules/credits/index.ts +++ b/src/plugins/config/modules/credits/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; //Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/config/modules/embeds/components/getValues/index.ts b/src/plugins/config/modules/embeds/components/getValues/index.ts index f068ac4..d511a52 100644 --- a/src/plugins/config/modules/embeds/components/getValues/index.ts +++ b/src/plugins/config/modules/embeds/components/getValues/index.ts @@ -1,6 +1,6 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; -import guildSchema from "@schemas/guild"; -import getEmbedConfig from "@root/helpers/getEmbedConfig"; +import guildSchema from "../../../../../../database/schemas/guild"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; export default async (interaction: CommandInteraction) => { const { options, guild } = interaction; diff --git a/src/plugins/config/modules/embeds/index.ts b/src/plugins/config/modules/embeds/index.ts index 32ad931..94f1db8 100644 --- a/src/plugins/config/modules/embeds/index.ts +++ b/src/plugins/config/modules/embeds/index.ts @@ -7,12 +7,12 @@ import { } from "discord.js"; //Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import getValues from "./components/getValues"; // Function diff --git a/src/plugins/config/modules/index.ts b/src/plugins/config/modules/index.ts index e14701a..09a9f5a 100644 --- a/src/plugins/config/modules/index.ts +++ b/src/plugins/config/modules/index.ts @@ -1,9 +1,9 @@ -import audits from "@plugins/config/modules/audits"; -import credits from "@plugins/config/modules/credits"; -import points from "@plugins/config/modules/points"; -import pterodactyl from "@plugins/config/modules/pterodactyl"; -import shop from "@plugins/config/modules/shop"; -import welcome from "@plugins/config/modules/welcome"; -import embeds from "@plugins/config/modules/embeds"; +import audits from "./audits"; +import credits from "./credits"; +import points from "./points"; +import pterodactyl from "./pterodactyl"; +import shop from "./shop"; +import welcome from "./welcome"; +import embeds from "./embeds"; export default { audits, credits, points, pterodactyl, shop, welcome, embeds }; diff --git a/src/plugins/config/modules/points/index.ts b/src/plugins/config/modules/points/index.ts index a7e24a2..0693916 100644 --- a/src/plugins/config/modules/points/index.ts +++ b/src/plugins/config/modules/points/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/config/modules/pterodactyl/index.ts b/src/plugins/config/modules/pterodactyl/index.ts index e6673e1..52e65b0 100644 --- a/src/plugins/config/modules/pterodactyl/index.ts +++ b/src/plugins/config/modules/pterodactyl/index.ts @@ -2,14 +2,14 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import apiSchema from "@schemas/api"; -import encryption from "@handlers/encryption"; +import apiSchema from "../../../../database/schemas/api"; +import encryption from "../../../../handlers/encryption"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/config/modules/shop/index.ts b/src/plugins/config/modules/shop/index.ts index e9f4d9f..a775385 100644 --- a/src/plugins/config/modules/shop/index.ts +++ b/src/plugins/config/modules/shop/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/config/modules/welcome/index.ts b/src/plugins/config/modules/welcome/index.ts index bdd962b..e6d5e9b 100644 --- a/src/plugins/config/modules/welcome/index.ts +++ b/src/plugins/config/modules/welcome/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/plugins/counters/index.ts b/src/plugins/counters/index.ts index ca3fc56..57ec908 100644 --- a/src/plugins/counters/index.ts +++ b/src/plugins/counters/index.ts @@ -1,8 +1,8 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; -import logger from "@logger"; +import logger from "../../logger"; -import modules from "@plugins/counters/modules"; +import modules from "../../plugins/counters/modules"; export default { modules, diff --git a/src/plugins/counters/modules/index.ts b/src/plugins/counters/modules/index.ts index 8c5ea76..dc539f8 100644 --- a/src/plugins/counters/modules/index.ts +++ b/src/plugins/counters/modules/index.ts @@ -1,3 +1,3 @@ -import view from "@plugins/counters/modules/view"; +import view from "./view"; export default { view }; diff --git a/src/plugins/counters/modules/view/index.ts b/src/plugins/counters/modules/view/index.ts index d672f0d..b509dd5 100644 --- a/src/plugins/counters/modules/view/index.ts +++ b/src/plugins/counters/modules/view/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; -import counterSchema from "@schemas/counter"; +import counterSchema from "../../../../database/schemas/counter"; export default { metadata: { guildOnly: true, ephemeral: false }, diff --git a/src/plugins/credits/index.ts b/src/plugins/credits/index.ts index 5e8033f..1e1860f 100644 --- a/src/plugins/credits/index.ts +++ b/src/plugins/credits/index.ts @@ -1,8 +1,8 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "@logger"; +import logger from "../../logger"; -import modules from "@plugins/credits/modules"; +import modules from "../../plugins/credits/modules"; export default { modules, diff --git a/src/plugins/credits/modules/balance/index.ts b/src/plugins/credits/modules/balance/index.ts index 60ee17e..2387d57 100644 --- a/src/plugins/credits/modules/balance/index.ts +++ b/src/plugins/credits/modules/balance/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "@logger"; +import logger from "../../../../logger"; -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../helpers/fetchUser"; export default { metadata: { guildOnly: true, ephemeral: true }, diff --git a/src/plugins/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts index 0325ab0..61f4309 100644 --- a/src/plugins/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -2,16 +2,16 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Helpers -import saveUser from "@helpers/saveUser"; +import saveUser from "../../../../helpers/saveUser"; // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/credits/modules/index.ts b/src/plugins/credits/modules/index.ts index 9b144f2..20edcaf 100644 --- a/src/plugins/credits/modules/index.ts +++ b/src/plugins/credits/modules/index.ts @@ -1,6 +1,6 @@ -import balance from "@plugins/credits/modules/balance"; -import gift from "@plugins/credits/modules/gift"; -import top from "@plugins/credits/modules/top"; -import work from "@plugins/credits/modules/work"; +import balance from "./balance"; +import gift from "./gift"; +import top from "./top"; +import work from "./work"; export default { balance, gift, top, work }; diff --git a/src/plugins/credits/modules/top/index.ts b/src/plugins/credits/modules/top/index.ts index 747f1bc..0aaa2f8 100644 --- a/src/plugins/credits/modules/top/index.ts +++ b/src/plugins/credits/modules/top/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "@logger"; +import logger from "../../../../logger"; -import userSchema, { IUser } from "@schemas/user"; +import userSchema, { IUser } from "../../../../database/schemas/user"; export default { metadata: { guildOnly: true, ephemeral: false }, diff --git a/src/plugins/credits/modules/work/index.ts b/src/plugins/credits/modules/work/index.ts index 1cde8cb..7f29629 100644 --- a/src/plugins/credits/modules/work/index.ts +++ b/src/plugins/credits/modules/work/index.ts @@ -4,17 +4,17 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import Chance from "chance"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; // Models -import timeoutSchema from "@schemas/timeout"; +import timeoutSchema from "../../../../database/schemas/timeout"; // Helpers -import fetchUser from "@helpers/fetchUser"; -import fetchGuild from "@helpers/fetchGuild"; +import fetchUser from "../../../../helpers/fetchUser"; +import fetchGuild from "../../../../helpers/fetchGuild"; export default { metadata: { guildOnly: true, ephemeral: true }, diff --git a/src/plugins/fun/index.ts b/src/plugins/fun/index.ts index 9ba8e81..687c036 100644 --- a/src/plugins/fun/index.ts +++ b/src/plugins/fun/index.ts @@ -1,8 +1,8 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "@logger"; +import logger from "../../logger"; -import modules from "@plugins/fun/modules"; +import modules from "../../plugins/fun/modules"; export default { modules, diff --git a/src/plugins/fun/modules/index.ts b/src/plugins/fun/modules/index.ts index 2b59097..53aeddc 100644 --- a/src/plugins/fun/modules/index.ts +++ b/src/plugins/fun/modules/index.ts @@ -1,4 +1,4 @@ -import meme from "@plugins/fun/modules/meme"; +import meme from "./meme"; export default { meme, diff --git a/src/plugins/fun/modules/meme/index.ts b/src/plugins/fun/modules/meme/index.ts index 3b6d706..9134223 100644 --- a/src/plugins/fun/modules/meme/index.ts +++ b/src/plugins/fun/modules/meme/index.ts @@ -1,9 +1,9 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import axios from "axios"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "@logger"; +import logger from "../../../../logger"; export default { metadata: { guildOnly: false, ephemeral: false }, diff --git a/src/plugins/manage/index.ts b/src/plugins/manage/index.ts index 993ba9f..7f51c88 100644 --- a/src/plugins/manage/index.ts +++ b/src/plugins/manage/index.ts @@ -3,8 +3,8 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Groups -import modules from "@plugins/manage/modules"; -import logger from "@logger"; +import modules from "../../plugins/manage/modules"; +import logger from "../../logger"; // Function export default { diff --git a/src/plugins/manage/modules/counters/index.ts b/src/plugins/manage/modules/counters/index.ts index 3fb9d3e..d5c351c 100644 --- a/src/plugins/manage/modules/counters/index.ts +++ b/src/plugins/manage/modules/counters/index.ts @@ -2,7 +2,7 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "@logger"; +import logger from "../../../../logger"; // Modules import modules from "./modules"; diff --git a/src/plugins/manage/modules/counters/modules/add/index.ts b/src/plugins/manage/modules/counters/modules/add/index.ts index b4c6e99..cdefbb8 100644 --- a/src/plugins/manage/modules/counters/modules/add/index.ts +++ b/src/plugins/manage/modules/counters/modules/add/index.ts @@ -4,12 +4,12 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; -import logger from "@logger"; +import logger from "../../../../../../logger"; // Models -import counterSchema from "@schemas/counter"; +import counterSchema from "../../../../../../database/schemas/counter"; // Function export default { diff --git a/src/plugins/manage/modules/counters/modules/index.ts b/src/plugins/manage/modules/counters/modules/index.ts index 2f55183..bc9da9c 100644 --- a/src/plugins/manage/modules/counters/modules/index.ts +++ b/src/plugins/manage/modules/counters/modules/index.ts @@ -1,4 +1,4 @@ -import add from "@plugins/manage/modules/counters/modules/add"; -import remove from "@plugins/manage/modules/counters/modules/remove"; +import add from "./add"; +import remove from "./remove"; export default { add, remove }; diff --git a/src/plugins/manage/modules/counters/modules/remove/index.ts b/src/plugins/manage/modules/counters/modules/remove/index.ts index 8a61687..295f2b0 100644 --- a/src/plugins/manage/modules/counters/modules/remove/index.ts +++ b/src/plugins/manage/modules/counters/modules/remove/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../../../logger"; // Models -import counterSchema from "@schemas/counter"; +import counterSchema from "../../../../../../database/schemas/counter"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/plugins/manage/modules/credits/index.ts b/src/plugins/manage/modules/credits/index.ts index a12cf11..11e4563 100644 --- a/src/plugins/manage/modules/credits/index.ts +++ b/src/plugins/manage/modules/credits/index.ts @@ -1,6 +1,6 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; -import logger from "@logger"; +import logger from "../../../../logger"; import modules from "./modules"; diff --git a/src/plugins/manage/modules/credits/modules/give/index.ts b/src/plugins/manage/modules/credits/modules/give/index.ts index cec0376..ebbc762 100644 --- a/src/plugins/manage/modules/credits/modules/give/index.ts +++ b/src/plugins/manage/modules/credits/modules/give/index.ts @@ -3,16 +3,16 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../../../logger"; // Helpers -import pluralize from "@helpers/pluralize"; +import pluralize from "../../../../../../helpers/pluralize"; // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../../../helpers/fetchUser"; // Function export default { diff --git a/src/plugins/manage/modules/credits/modules/index.ts b/src/plugins/manage/modules/credits/modules/index.ts index 1dd2f3d..ede5ae7 100644 --- a/src/plugins/manage/modules/credits/modules/index.ts +++ b/src/plugins/manage/modules/credits/modules/index.ts @@ -1,6 +1,6 @@ -import give from "@plugins/manage/modules/credits/modules/give"; -import set from "@plugins/manage/modules/credits/modules/set"; -import take from "@plugins/manage/modules/credits/modules/take"; -import transfer from "@plugins/manage/modules/credits/modules/transfer"; +import give from "./give"; +import set from "./set"; +import take from "./take"; +import transfer from "./transfer"; export default { give, set, take, transfer }; diff --git a/src/plugins/manage/modules/credits/modules/set/index.ts b/src/plugins/manage/modules/credits/modules/set/index.ts index a7d86a2..a8e1771 100644 --- a/src/plugins/manage/modules/credits/modules/set/index.ts +++ b/src/plugins/manage/modules/credits/modules/set/index.ts @@ -2,15 +2,15 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../../../logger"; // Helpers // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/manage/modules/credits/modules/take/index.ts b/src/plugins/manage/modules/credits/modules/take/index.ts index 9c823b9..5cf794a 100644 --- a/src/plugins/manage/modules/credits/modules/take/index.ts +++ b/src/plugins/manage/modules/credits/modules/take/index.ts @@ -2,16 +2,16 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../../../logger"; // Helpers -import pluralize from "@helpers/pluralize"; +import pluralize from "../../../../../../helpers/pluralize"; // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/manage/modules/credits/modules/transfer/index.ts b/src/plugins/manage/modules/credits/modules/transfer/index.ts index 19de23a..d65667b 100644 --- a/src/plugins/manage/modules/credits/modules/transfer/index.ts +++ b/src/plugins/manage/modules/credits/modules/transfer/index.ts @@ -2,16 +2,16 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "@logger"; +import logger from "../../../../../../logger"; // Helpers -import saveUser from "@helpers/saveUser"; +import saveUser from "../../../../../../helpers/saveUser"; // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/manage/modules/index.ts b/src/plugins/manage/modules/index.ts index 61797b1..e9b808b 100644 --- a/src/plugins/manage/modules/index.ts +++ b/src/plugins/manage/modules/index.ts @@ -1,4 +1,4 @@ -import counters from "@plugins/manage/modules/counters"; -import credits from "@plugins/manage/modules/credits"; +import counters from "./counters"; +import credits from "./credits"; export default { counters, credits }; diff --git a/src/plugins/profile/index.ts b/src/plugins/profile/index.ts index d37ad1b..bb3c5b3 100644 --- a/src/plugins/profile/index.ts +++ b/src/plugins/profile/index.ts @@ -3,10 +3,10 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Modules -import modules from "@plugins/profile/modules"; +import modules from "../../plugins/profile/modules"; // Handlers -import logger from "@logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/plugins/profile/modules/index.ts b/src/plugins/profile/modules/index.ts index 1dc8e1b..dc539f8 100644 --- a/src/plugins/profile/modules/index.ts +++ b/src/plugins/profile/modules/index.ts @@ -1,3 +1,3 @@ -import view from "@plugins/profile/modules/view"; +import view from "./view"; export default { view }; diff --git a/src/plugins/profile/modules/view.ts b/src/plugins/profile/modules/view.ts index c6704a3..5a59fd3 100644 --- a/src/plugins/profile/modules/view.ts +++ b/src/plugins/profile/modules/view.ts @@ -2,12 +2,12 @@ import { CommandInteraction } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; // Models -import fetchUser from "@helpers/fetchUser"; +import fetchUser from "../../../helpers/fetchUser"; -import logger from "@logger"; +import logger from "../../../logger"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/reputation/index.ts b/src/plugins/reputation/index.ts index f5237ab..a027d7e 100644 --- a/src/plugins/reputation/index.ts +++ b/src/plugins/reputation/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "@logger"; +import logger from "../../logger"; // Function export default { diff --git a/src/plugins/reputation/modules/give.ts b/src/plugins/reputation/modules/give.ts index 949f9c9..c55e909 100644 --- a/src/plugins/reputation/modules/give.ts +++ b/src/plugins/reputation/modules/give.ts @@ -2,16 +2,16 @@ import { CommandInteraction } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; -import { timeout } from "@config/reputation"; +import { timeout } from "../../../config/reputation"; // Handlers -import logger from "@logger"; +import logger from "../../../logger"; // Models -import timeoutSchema from "@schemas/timeout"; -import fetchUser from "@helpers/fetchUser"; +import timeoutSchema from "../../../database/schemas/timeout"; +import fetchUser from "../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/reputation/modules/index.ts b/src/plugins/reputation/modules/index.ts index f6746fd..e891cf0 100644 --- a/src/plugins/reputation/modules/index.ts +++ b/src/plugins/reputation/modules/index.ts @@ -1,3 +1,3 @@ -import give from "@plugins/reputation/modules/give"; +import give from "./give"; export default { give }; diff --git a/src/plugins/shop/modules/index.ts b/src/plugins/shop/modules/index.ts index c356cae..e39fb66 100644 --- a/src/plugins/shop/modules/index.ts +++ b/src/plugins/shop/modules/index.ts @@ -1,4 +1,4 @@ -import pterodactyl from "@plugins/shop/modules/pterodactyl"; -import roles from "@plugins/shop/modules/roles"; +import pterodactyl from "./pterodactyl"; +import roles from "./roles"; export default { pterodactyl, roles }; diff --git a/src/plugins/shop/modules/pterodactyl.ts b/src/plugins/shop/modules/pterodactyl.ts index 22da19c..daa698d 100644 --- a/src/plugins/shop/modules/pterodactyl.ts +++ b/src/plugins/shop/modules/pterodactyl.ts @@ -2,15 +2,15 @@ import { CommandInteraction } from "discord.js"; import { v4 as uuidv4 } from "uuid"; import axios from "axios"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; -import logger from "@logger"; -import encryption from "@handlers/encryption"; +import logger from "../../../logger"; +import encryption from "../../../handlers/encryption"; -import pluralize from "@helpers/pluralize"; +import pluralize from "../../../helpers/pluralize"; -import apiSchema from "@schemas/api"; -import fetchUser from "@helpers/fetchUser"; +import apiSchema from "../../../database/schemas/api"; +import fetchUser from "../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; export default { diff --git a/src/plugins/shop/modules/roles/index.ts b/src/plugins/shop/modules/roles/index.ts index 33ece41..a4ffb2a 100644 --- a/src/plugins/shop/modules/roles/index.ts +++ b/src/plugins/shop/modules/roles/index.ts @@ -3,14 +3,14 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Handlers -import logger from "@logger"; +import logger from "../../../../logger"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Modules import modules from "./modules"; -import guildSchema from "@schemas/guild"; +import guildSchema from "../../../../database/schemas/guild"; // Function export default { diff --git a/src/plugins/shop/modules/roles/modules/buy.ts b/src/plugins/shop/modules/roles/modules/buy.ts index 4e4528d..b92ba7a 100644 --- a/src/plugins/shop/modules/roles/modules/buy.ts +++ b/src/plugins/shop/modules/roles/modules/buy.ts @@ -6,17 +6,17 @@ import { } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "@schemas/shopRole"; -import guildSchema from "@schemas/guild"; +import shopRolesSchema from "../../../../../database/schemas/shopRole"; +import guildSchema from "../../../../../database/schemas/guild"; -import logger from "@logger"; +import logger from "../../../../../logger"; // Helpers -import pluralize from "@helpers/pluralize"; -import fetchUser from "@helpers/fetchUser"; +import pluralize from "../../../../../helpers/pluralize"; +import fetchUser from "../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/shop/modules/roles/modules/cancel.ts b/src/plugins/shop/modules/roles/modules/cancel.ts index 546dbc7..cf16d95 100644 --- a/src/plugins/shop/modules/roles/modules/cancel.ts +++ b/src/plugins/shop/modules/roles/modules/cancel.ts @@ -2,16 +2,16 @@ import { CommandInteraction, GuildMemberRoleManager } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "@schemas/shopRole"; +import shopRolesSchema from "../../../../../database/schemas/shopRole"; -import logger from "@logger"; +import logger from "../../../../../logger"; // Helpers -import pluralize from "@helpers/pluralize"; -import fetchUser from "@helpers/fetchUser"; +import pluralize from "../../../../../helpers/pluralize"; +import fetchUser from "../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/utility/index.ts b/src/plugins/utility/index.ts index 6dc6fff..b831189 100644 --- a/src/plugins/utility/index.ts +++ b/src/plugins/utility/index.ts @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Modules -import modules from "@plugins/utility/modules"; +import modules from "../../plugins/utility/modules"; // Handlers import logger from "../../logger"; diff --git a/src/plugins/utility/modules/about.ts b/src/plugins/utility/modules/about.ts index 8011d51..18eca4c 100644 --- a/src/plugins/utility/modules/about.ts +++ b/src/plugins/utility/modules/about.ts @@ -2,9 +2,9 @@ import { CommandInteraction } from "discord.js"; // Configurations -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; -import { hosterName, hosterUrl } from "@config/other"; +import { hosterName, hosterUrl } from "../../../config/other"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/utility/modules/avatar.ts b/src/plugins/utility/modules/avatar.ts index b060be3..57110cf 100644 --- a/src/plugins/utility/modules/avatar.ts +++ b/src/plugins/utility/modules/avatar.ts @@ -1,4 +1,4 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; diff --git a/src/plugins/utility/modules/index.ts b/src/plugins/utility/modules/index.ts index 80c5a64..cd69316 100644 --- a/src/plugins/utility/modules/index.ts +++ b/src/plugins/utility/modules/index.ts @@ -1,7 +1,7 @@ -import avatar from "@plugins/utility/modules/avatar"; -import about from "@plugins/utility/modules/about"; -import lookup from "@plugins/utility/modules/lookup"; -import stats from "@plugins/utility/modules/stats"; +import avatar from "./avatar"; +import about from "./about"; +import lookup from "./lookup"; +import stats from "./stats"; export default { avatar, diff --git a/src/plugins/utility/modules/lookup.ts b/src/plugins/utility/modules/lookup.ts index 241b7ce..a5825f9 100644 --- a/src/plugins/utility/modules/lookup.ts +++ b/src/plugins/utility/modules/lookup.ts @@ -1,11 +1,11 @@ import axios from "axios"; import { CommandInteraction } from "discord.js"; -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import embedBuilder from "@root/helpers/embedBuilder"; +import embedBuilder from "../../../helpers/embedBuilder"; export default { metadata: { guildOnly: false, ephemeral: false }, diff --git a/src/plugins/utility/modules/stats.ts b/src/plugins/utility/modules/stats.ts index a7f44a0..805b948 100644 --- a/src/plugins/utility/modules/stats.ts +++ b/src/plugins/utility/modules/stats.ts @@ -1,4 +1,4 @@ -import getEmbedConfig from "@helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; diff --git a/src/types/common/discord.d.ts b/src/types/common/discord.d.ts index 68458e0..e83d22f 100644 --- a/src/types/common/discord.d.ts +++ b/src/types/common/discord.d.ts @@ -1,8 +1,9 @@ -import { Collection, Client as DJSClient } from "discord.js"; +import { Collection } from "discord.js"; +import ICommand from "../interfaces/Command"; declare module "discord.js" { export interface Client extends DJSClient { - commands: Collection; + commands: Collection; } } From 880ad789c98d230481be3606ae90beb451def7ee Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 19:35:42 +0200 Subject: [PATCH 20/75] =?UTF-8?q?=F0=9F=9A=91=20plugins=20now=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/commands.ts | 2 +- src/helpers/getCommandMetadata/index.ts | 4 +- src/interfaces/Command.ts | 2 +- src/managers/event/index.ts | 2 +- src/plugins/config/index.ts | 83 ++++++--------- src/plugins/counters/index.ts | 25 ++--- src/plugins/credits/index.ts | 56 +++++----- src/plugins/fun/index.ts | 26 +++-- src/plugins/manage/index.ts | 40 +++---- src/plugins/manage/modules/counters/index.ts | 52 +++++----- src/plugins/manage/modules/credits/index.ts | 57 ++++------ src/plugins/manage/modules/index.ts | 4 +- src/plugins/profile/index.ts | 27 +++-- src/plugins/reputation/index.ts | 28 ++--- src/plugins/shop/index.ts | 37 ++++--- src/plugins/shop/modules/index.ts | 2 +- src/plugins/shop/modules/roles/index.ts | 103 +++++++++---------- src/plugins/utility/index.ts | 48 +++++---- 18 files changed, 267 insertions(+), 331 deletions(-) diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts index 8b75999..1df02fe 100644 --- a/src/handlers/commands.ts +++ b/src/handlers/commands.ts @@ -6,7 +6,7 @@ import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { client.commands = new Collection(); - fs.readdir("./src/plugins", async (error, plugins) => { + fs.readdir("plugins", async (error, plugins) => { if (error) { return logger.error(`Error reading plugins: ${error}`); } diff --git a/src/helpers/getCommandMetadata/index.ts b/src/helpers/getCommandMetadata/index.ts index 71940d2..647eb75 100644 --- a/src/helpers/getCommandMetadata/index.ts +++ b/src/helpers/getCommandMetadata/index.ts @@ -9,6 +9,6 @@ export default async ( const subcommandGroup = interaction.options.getSubcommandGroup(false); return subcommandGroup - ? currentCommand.modules[subcommandGroup].modules[subcommand].metadata - : currentCommand.modules[subcommand].metadata; + ? currentCommand.moduleData[subcommandGroup].moduleData[subcommand].metadata + : currentCommand.moduleData[subcommand].metadata; }; diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index 34585d9..f8a895a 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -1,7 +1,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; export interface ICommand { - modules: any; builder: SlashCommandBuilder; + moduleData: any; execute: Promise; } diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index be51927..8a3a506 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -3,7 +3,7 @@ import { Client } from "discord.js"; import listDir from "../../helpers/listDir"; export const register = async (client: Client) => { - const eventNames = await listDir("src/events"); + const eventNames = await listDir("events"); if (!eventNames) return; for await (const eventName of eventNames) { diff --git a/src/plugins/config/index.ts b/src/plugins/config/index.ts index 0b82732..4110d5c 100644 --- a/src/plugins/config/index.ts +++ b/src/plugins/config/index.ts @@ -8,57 +8,36 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const builder = new SlashCommandBuilder() + .setName("config") + .setDescription("Manage guild configurations.") + + .addSubcommand(modules.pterodactyl.builder) + .addSubcommand(modules.credits.builder) + .addSubcommand(modules.points.builder) + .addSubcommand(modules.welcome.builder) + .addSubcommand(modules.audits.builder) + .addSubcommand(modules.shop.builder) + .addSubcommand(modules.embeds.builder); + +export const moduleData = modules; + // Function -export default { - modules, - - builder: new SlashCommandBuilder() - .setName("config") - .setDescription("Manage guild configurations.") - - .addSubcommand(modules.pterodactyl.builder) - .addSubcommand(modules.credits.builder) - .addSubcommand(modules.points.builder) - .addSubcommand(modules.welcome.builder) - .addSubcommand(modules.audits.builder) - .addSubcommand(modules.shop.builder) - .addSubcommand(modules.embeds.builder), - - async execute(interaction: CommandInteraction) { - // Destructure member - const { options } = interaction; - - switch (options?.getSubcommand()) { - case "pterodactyl": - logger?.silly(`Subcommand is pterodactyl`); - - return modules.pterodactyl.execute(interaction); - case "credits": - logger?.silly(`Subcommand is credits`); - - return modules.credits.execute(interaction); - case "points": - logger?.silly(`Subcommand is points`); - - return modules.points.execute(interaction); - case "welcome": - logger?.silly(`Subcommand is welcome`); - - return modules.welcome.execute(interaction); - case "audits": - logger?.silly(`Subcommand is audits`); - - return modules.audits.execute(interaction); - case "shop": - logger?.silly(`Subcommand is shop`); - - return modules.shop.execute(interaction); - case "embeds": - logger?.silly(`Subcommand is shop`); - - return modules.embeds.execute(interaction); - default: - logger?.silly(`Subcommand is not found`); - } - }, +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options?.getSubcommand()) { + case "pterodactyl": + return modules.pterodactyl.execute(interaction); + case "credits": + return modules.credits.execute(interaction); + case "points": + return modules.points.execute(interaction); + case "welcome": + return modules.welcome.execute(interaction); + case "audits": + return modules.audits.execute(interaction); + case "shop": + return modules.shop.execute(interaction); + case "embeds": + return modules.embeds.execute(interaction); + } }; diff --git a/src/plugins/counters/index.ts b/src/plugins/counters/index.ts index 57ec908..df23d0b 100644 --- a/src/plugins/counters/index.ts +++ b/src/plugins/counters/index.ts @@ -4,23 +4,16 @@ import logger from "../../logger"; import modules from "../../plugins/counters/modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("counters") + .setDescription("View guild counters") - builder: new SlashCommandBuilder() - .setName("counters") - .setDescription("View guild counters") + .addSubcommand(modules.view.builder); - .addSubcommand(modules.view.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; - - if (options.getSubcommand() === "view") { - logger.silly(`Executing view subcommand`); - return modules.view.execute(interaction); - } - - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - }, +export const execute = async (interaction: CommandInteraction) => { + if (interaction.options.getSubcommand() === "view") { + await modules.view.execute(interaction); + } }; diff --git a/src/plugins/credits/index.ts b/src/plugins/credits/index.ts index 1e1860f..02c03a5 100644 --- a/src/plugins/credits/index.ts +++ b/src/plugins/credits/index.ts @@ -2,38 +2,36 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; import logger from "../../logger"; -import modules from "../../plugins/credits/modules"; +import modules from "./modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("credits") + .setDescription("Manage your credits.") - builder: new SlashCommandBuilder() - .setName("credits") - .setDescription("Manage your credits.") + .addSubcommand(modules.balance.builder) + .addSubcommand(modules.gift.builder) + .addSubcommand(modules.top.builder) + .addSubcommand(modules.work.builder); - .addSubcommand(modules.balance.builder) - .addSubcommand(modules.gift.builder) - .addSubcommand(modules.top.builder) - .addSubcommand(modules.work.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - switch (options.getSubcommand()) { - case "balance": - await modules.balance.execute(interaction); - break; - case "gift": - await modules.gift.execute(interaction); - break; - case "top": - await modules.top.execute(interaction); - break; - case "work": - await modules.work.execute(interaction); - break; - default: - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + switch (options.getSubcommand()) { + case "balance": + await modules.balance.execute(interaction); + break; + case "gift": + await modules.gift.execute(interaction); + break; + case "top": + await modules.top.execute(interaction); + break; + case "work": + await modules.work.execute(interaction); + break; + default: + logger.silly(`Unknown subcommand ${options.getSubcommand()}`); + } }; diff --git a/src/plugins/fun/index.ts b/src/plugins/fun/index.ts index 687c036..758814c 100644 --- a/src/plugins/fun/index.ts +++ b/src/plugins/fun/index.ts @@ -4,22 +4,20 @@ import logger from "../../logger"; import modules from "../../plugins/fun/modules"; -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("fun") + .setDescription("Fun commands.") - builder: new SlashCommandBuilder() - .setName("fun") - .setDescription("Fun commands.") + .addSubcommand(modules.meme.builder); - .addSubcommand(modules.meme.builder), +export const moduleData = modules; - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options.getSubcommand() === "meme") { - await modules.meme.execute(interaction); - } else { - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + if (options.getSubcommand() === "meme") { + await modules.meme.execute(interaction); + } else { + logger.silly(`Unknown subcommand ${options.getSubcommand()}`); + } }; diff --git a/src/plugins/manage/index.ts b/src/plugins/manage/index.ts index 7f51c88..a54f2e2 100644 --- a/src/plugins/manage/index.ts +++ b/src/plugins/manage/index.ts @@ -6,32 +6,24 @@ import { CommandInteraction } from "discord.js"; import modules from "../../plugins/manage/modules"; import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("manage") + .setDescription("Manage the bot.") + .addSubcommandGroup(modules.counters.builder) + .addSubcommandGroup(modules.credits.builder); - builder: new SlashCommandBuilder() - .setName("manage") - .setDescription("Manage the bot.") - .addSubcommandGroup(modules.counters.builder) - .addSubcommandGroup(modules.credits.builder), +export const execute = async (interaction: CommandInteraction) => { + // Destructure + const { options } = interaction; - async execute(interaction: CommandInteraction) { - // Destructure - const { options } = interaction; + if (options?.getSubcommandGroup() === "credits") { + return modules.credits.execute(interaction); + } - if (options?.getSubcommandGroup() === "credits") { - logger?.silly(`Subcommand group is credits`); - - return modules.credits.execute(interaction); - } - - if (options?.getSubcommandGroup() === "counters") { - logger?.silly(`Subcommand group is counters`); - - return modules.counters.execute(interaction); - } - - logger?.silly(`Subcommand group is not credits or counters`); - }, + if (options?.getSubcommandGroup() === "counters") { + return modules.counters.execute(interaction); + } }; diff --git a/src/plugins/manage/modules/counters/index.ts b/src/plugins/manage/modules/counters/index.ts index d5c351c..36d6cd9 100644 --- a/src/plugins/manage/modules/counters/index.ts +++ b/src/plugins/manage/modules/counters/index.ts @@ -8,32 +8,30 @@ import logger from "../../../../logger"; import modules from "./modules"; // Function -export default { - modules, +export const moduleData = modules; - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("counters") - .setDescription("Manage guild counters.") - .addSubcommand(modules.add.builder) - .addSubcommand(modules.remove.builder); - }, - - execute: async (interaction: CommandInteraction) => { - const { options } = interaction; - - if (options?.getSubcommand() === "add") { - logger?.silly(`Executing create subcommand`); - - return modules.add.execute(interaction); - } - - if (options?.getSubcommand() === "remove") { - logger?.silly(`Executing delete subcommand`); - - return modules.remove.execute(interaction); - } - - logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`); - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("counters") + .setDescription("Manage guild counters.") + .addSubcommand(modules.add.builder) + .addSubcommand(modules.remove.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; + + if (options?.getSubcommand() === "add") { + logger?.silly(`Executing create subcommand`); + + return modules.add.execute(interaction); + } + + if (options?.getSubcommand() === "remove") { + logger?.silly(`Executing delete subcommand`); + + return modules.remove.execute(interaction); + } + + logger?.silly(`Unknown subcommand ${options?.getSubcommand()}`); }; diff --git a/src/plugins/manage/modules/credits/index.ts b/src/plugins/manage/modules/credits/index.ts index 11e4563..cd6819b 100644 --- a/src/plugins/manage/modules/credits/index.ts +++ b/src/plugins/manage/modules/credits/index.ts @@ -4,40 +4,27 @@ import logger from "../../../../logger"; import modules from "./modules"; -export default { - modules, +export const moduleData = modules; - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("credits") - .setDescription("Manage the credits of a user.") - .addSubcommand(modules.give.builder) - .addSubcommand(modules.set.builder) - .addSubcommand(modules.take.builder) - .addSubcommand(modules.transfer.builder); - }, - execute: async (interaction: CommandInteraction) => { - const { options } = interaction; - - switch (options.getSubcommand()) { - case "give": - logger.silly(`Executing give subcommand`); - - return modules.give.execute(interaction); - case "set": - logger.silly(`Executing set subcommand`); - - return modules.set.execute(interaction); - case "take": - logger.silly(`Executing take subcommand`); - - return modules.take.execute(interaction); - case "transfer": - logger.silly(`Executing transfer subcommand`); - - return modules.transfer.execute(interaction); - default: - logger.silly(`Unknown subcommand ${options.getSubcommand()}`); - } - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("credits") + .setDescription("Manage the credits of a user.") + .addSubcommand(modules.give.builder) + .addSubcommand(modules.set.builder) + .addSubcommand(modules.take.builder) + .addSubcommand(modules.transfer.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options.getSubcommand()) { + case "give": + return modules.give.execute(interaction); + case "set": + return modules.set.execute(interaction); + case "take": + return modules.take.execute(interaction); + case "transfer": + return modules.transfer.execute(interaction); + } }; diff --git a/src/plugins/manage/modules/index.ts b/src/plugins/manage/modules/index.ts index e9b808b..c55982f 100644 --- a/src/plugins/manage/modules/index.ts +++ b/src/plugins/manage/modules/index.ts @@ -1,4 +1,4 @@ -import counters from "./counters"; -import credits from "./credits"; +import * as counters from "./counters"; +import * as credits from "./credits"; export default { counters, credits }; diff --git a/src/plugins/profile/index.ts b/src/plugins/profile/index.ts index bb3c5b3..808c9e7 100644 --- a/src/plugins/profile/index.ts +++ b/src/plugins/profile/index.ts @@ -8,23 +8,22 @@ import modules from "../../plugins/profile/modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("profile") + .setDescription("Check a profile.") + .addSubcommand(modules.view.builder); - builder: new SlashCommandBuilder() - .setName("profile") - .setDescription("Check a profile.") - .addSubcommand(modules.view.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options?.getSubcommand() === "view") { - logger?.silly(`Executing view subcommand`); + if (options?.getSubcommand() === "view") { + logger?.silly(`Executing view subcommand`); - return modules.view.execute(interaction); - } + return modules.view.execute(interaction); + } - logger?.silly(`No subcommand found`); - }, + logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/reputation/index.ts b/src/plugins/reputation/index.ts index a027d7e..b0812d4 100644 --- a/src/plugins/reputation/index.ts +++ b/src/plugins/reputation/index.ts @@ -8,22 +8,22 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, - builder: new SlashCommandBuilder() - .setName("reputation") - .setDescription("Manage reputation.") - .addSubcommand(modules.give.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const builder = new SlashCommandBuilder() + .setName("reputation") + .setDescription("Manage reputation.") + .addSubcommand(modules.give.builder); - if (options?.getSubcommand() === "give") { - logger?.silly(`Executing give subcommand`); +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - await modules.give.execute(interaction); - } + if (options?.getSubcommand() === "give") { + logger?.silly(`Executing give subcommand`); - logger?.silly(`No subcommand found`); - }, + await modules.give.execute(interaction); + } + + logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/shop/index.ts b/src/plugins/shop/index.ts index 330306e..2ef6f65 100644 --- a/src/plugins/shop/index.ts +++ b/src/plugins/shop/index.ts @@ -8,30 +8,29 @@ import modules from "./modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("shop") + .setDescription("Shop for credits and custom roles.") + .addSubcommand(modules.pterodactyl.builder) + .addSubcommandGroup(modules.roles.builder); - builder: new SlashCommandBuilder() - .setName("shop") - .setDescription("Shop for credits and custom roles.") - .addSubcommand(modules.pterodactyl.builder) - .addSubcommandGroup(modules.roles.builder), - async execute(interaction: CommandInteraction) { - const { options } = interaction; +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - if (options?.getSubcommand() === "pterodactyl") { - logger.silly(`Executing pterodactyl subcommand`); + if (options?.getSubcommand() === "pterodactyl") { + logger.silly(`Executing pterodactyl subcommand`); - return modules.pterodactyl.execute(interaction); - } + return modules.pterodactyl.execute(interaction); + } - if (options?.getSubcommandGroup() === "roles") { - logger?.silly(`Subcommand group is roles`); + if (options?.getSubcommandGroup() === "roles") { + logger?.silly(`Subcommand group is roles`); - return modules.roles.execute(interaction); - } + return modules.roles.execute(interaction); + } - logger?.silly(`No subcommand found.`); - }, + logger?.silly(`No subcommand found.`); }; diff --git a/src/plugins/shop/modules/index.ts b/src/plugins/shop/modules/index.ts index e39fb66..d191ec6 100644 --- a/src/plugins/shop/modules/index.ts +++ b/src/plugins/shop/modules/index.ts @@ -1,4 +1,4 @@ import pterodactyl from "./pterodactyl"; -import roles from "./roles"; +import * as roles from "./roles"; export default { pterodactyl, roles }; diff --git a/src/plugins/shop/modules/roles/index.ts b/src/plugins/shop/modules/roles/index.ts index a4ffb2a..bdec977 100644 --- a/src/plugins/shop/modules/roles/index.ts +++ b/src/plugins/shop/modules/roles/index.ts @@ -12,59 +12,54 @@ import modules from "./modules"; import guildSchema from "../../../../database/schemas/guild"; +export const moduleData = modules; + // Function -export default { - modules, - - builder: (group: SlashCommandSubcommandGroupBuilder) => { - return group - .setName("roles") - .setDescription("Shop for custom roles.") - .addSubcommand(modules.buy.builder) - .addSubcommand(modules.cancel.builder); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { errorColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - const { options, guild } = interaction; - - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) return; - - if (!guildDB.shop.roles.status) { - logger.silly(`Shop roles disabled.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":dollar: Shop - Roles", - description: "This server has disabled shop roles.", - color: errorColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - - if (options?.getSubcommand() === "buy") { - logger.silly(`Executing buy subcommand`); - - await modules.buy.execute(interaction); - } - - if (options?.getSubcommand() === "cancel") { - logger.silly(`Executing cancel subcommand`); - - await modules.cancel.execute(interaction); - } - }, +export const builder = (group: SlashCommandSubcommandGroupBuilder) => { + return group + .setName("roles") + .setDescription("Shop for custom roles.") + .addSubcommand(modules.buy.builder) + .addSubcommand(modules.cancel.builder); +}; + +export const execute = async (interaction: CommandInteraction) => { + if (interaction.guild == null) return; + const { errorColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + const { options, guild } = interaction; + + const guildDB = await guildSchema?.findOne({ + guildId: guild?.id, + }); + + if (guildDB === null) return; + + if (!guildDB.shop.roles.status) { + logger.silly(`Shop roles disabled.`); + + return interaction?.editReply({ + embeds: [ + { + title: ":dollar: Shop - Roles", + description: "This server has disabled shop roles.", + color: errorColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + } + + if (options?.getSubcommand() === "buy") { + await modules.buy.execute(interaction); + } + + if (options?.getSubcommand() === "cancel") { + await modules.cancel.execute(interaction); + } }; diff --git a/src/plugins/utility/index.ts b/src/plugins/utility/index.ts index b831189..4849a3b 100644 --- a/src/plugins/utility/index.ts +++ b/src/plugins/utility/index.ts @@ -8,33 +8,31 @@ import modules from "../../plugins/utility/modules"; // Handlers import logger from "../../logger"; +export const moduleData = modules; + // Function -export default { - modules, +export const builder = new SlashCommandBuilder() + .setName("utility") + .setDescription("Common utility.") - builder: new SlashCommandBuilder() - .setName("utility") - .setDescription("Common utility.") + .addSubcommand(modules.lookup.builder) + .addSubcommand(modules.about.builder) + .addSubcommand(modules.stats.builder) + .addSubcommand(modules.avatar.builder); - .addSubcommand(modules.lookup.builder) - .addSubcommand(modules.about.builder) - .addSubcommand(modules.stats.builder) - .addSubcommand(modules.avatar.builder), +export const execute = async (interaction: CommandInteraction) => { + const { options } = interaction; - async execute(interaction: CommandInteraction) { - const { options } = interaction; - - switch (options.getSubcommand()) { - case "lookup": - return modules.lookup.execute(interaction); - case "about": - return modules.about.execute(interaction); - case "stats": - return modules.stats.execute(interaction); - case "avatar": - return modules.avatar.execute(interaction); - default: - logger.error(`Unknown subcommand ${options.getSubcommand()}`); - } - }, + switch (options.getSubcommand()) { + case "lookup": + return modules.lookup.execute(interaction); + case "about": + return modules.about.execute(interaction); + case "stats": + return modules.stats.execute(interaction); + case "avatar": + return modules.avatar.execute(interaction); + default: + logger.error(`Unknown subcommand ${options.getSubcommand()}`); + } }; From 75c9fdf43881e8332968b75e198df867ef07a124 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 19:56:35 +0200 Subject: [PATCH 21/75] =?UTF-8?q?=F0=9F=91=94=20Changed=20to=20transaction?= =?UTF-8?q?s=20#297?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/saveUser/index.ts | 43 --------- src/helpers/sleep/index.ts | 8 -- src/plugins/credits/modules/gift/index.ts | 87 +++++++++++-------- .../modules/credits/modules/transfer/index.ts | 73 +++++++++++----- 4 files changed, 101 insertions(+), 110 deletions(-) delete mode 100644 src/helpers/saveUser/index.ts delete mode 100644 src/helpers/sleep/index.ts diff --git a/src/helpers/saveUser/index.ts b/src/helpers/saveUser/index.ts deleted file mode 100644 index 2608bd4..0000000 --- a/src/helpers/saveUser/index.ts +++ /dev/null @@ -1,43 +0,0 @@ -import sleep from "../../helpers/sleep"; -import logger from "../../logger"; -import Chance from "chance"; - -export default async function saveUser(data: any, data2: any) { - process.nextTick( - async () => { - // Chance module - const chance = new Chance(); - - await sleep( - chance.integer({ - min: 0, - max: 1, - }) * - 10 + - 1 * 100 - ); // 100 - 1000 random Number generator - data.save((_: any) => - _ - ? logger?.error( - `ERROR Occurred while saving data (saveUser) \n${"=".repeat( - 50 - )}\n${`${_}\n${"=".repeat(50)}`}` - ) - : logger?.silly(`Saved user: ${data.id} (saveUser)`) - ); - if (data2) { - data2.save((_: any) => - _ - ? logger?.error( - `ERROR Occurred while saving data (saveUser) \n${"=".repeat( - 50 - )}\n${`${_}\n${"=".repeat(50)}`}` - ) - : logger?.silly(`Saved user: ${data2.id} (saveUser)`) - ); - } - }, - data, - data2 - ); -} diff --git a/src/helpers/sleep/index.ts b/src/helpers/sleep/index.ts deleted file mode 100644 index d69f15b..0000000 --- a/src/helpers/sleep/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import logger from "../../logger"; - -export default function sleep(milliseconds: number) { - return new Promise((resolve) => { - setTimeout(resolve, milliseconds); - logger?.silly(`Sleeping for ${milliseconds} milliseconds`); - }); -} diff --git a/src/plugins/credits/modules/gift/index.ts b/src/plugins/credits/modules/gift/index.ts index 61f4309..9873c02 100644 --- a/src/plugins/credits/modules/gift/index.ts +++ b/src/plugins/credits/modules/gift/index.ts @@ -7,8 +7,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Handlers import logger from "../../../../logger"; -// Helpers -import saveUser from "../../../../helpers/saveUser"; +import mongoose from "mongoose"; // Models import fetchUser from "../../../../helpers/fetchUser"; @@ -184,53 +183,69 @@ export default { }); } - // Withdraw amount from fromUserDB - fromUserDB.credits -= optionAmount; + const session = await mongoose.startSession(); - // Deposit amount to toUserDB - toUserDB.credits += optionAmount; + session.startTransaction(); - // Save users - await saveUser(fromUserDB, toUserDB).then(async () => { - // Get DM user object - const dmUser = client.users.cache.get(optionUser.id); + try { + // Withdraw amount from fromUserDB + fromUserDB.credits -= optionAmount; - if (dmUser == null) return; + // Deposit amount to toUserDB + toUserDB.credits += optionAmount; - // Send DM to user - await dmUser - .send({ - embeds: [ - embed - .setDescription( - `${ - user.tag - } has gifted you ${optionAmount} credits with reason: ${ - optionReason || "unspecified" - }` - ) - .setColor(successColor), - ], - }) - .catch(async (error) => - logger.error(`[Gift] Error sending DM to user: ${error}`) - ); + await fromUserDB.save(); - logger.silly( - `[Gift] Successfully gifted ${optionAmount} credits to ${optionUser.tag}` - ); + await toUserDB.save(); + + await session.commitTransaction(); + } catch (error) { + await session.abortTransaction(); + session.endSession(); + logger.error(`${error}`); return interaction.editReply({ embeds: [ embed .setDescription( - `Successfully gifted ${optionAmount} credits to ${ - optionUser.tag - } with reason: ${optionReason || "unspecified"}` + "An error occurred while trying to gift credits. Please try again." ) - .setColor(successColor), + .setColor(errorColor), ], }); + } finally { + // ending the session + session.endSession(); + } + + // Get DM user object + const dmUser = client.users.cache.get(optionUser.id); + + if (!dmUser) throw new Error("User not found"); + + // Send DM to user + await dmUser.send({ + embeds: [ + embed + .setDescription( + `${user.tag} has gifted you ${optionAmount} credits with reason: ${ + optionReason || "unspecified" + }` + ) + .setColor(successColor), + ], + }); + + return interaction.editReply({ + embeds: [ + embed + .setDescription( + `Successfully gifted ${optionAmount} credits to ${ + optionUser.tag + } with reason: ${optionReason || "unspecified"}` + ) + .setColor(successColor), + ], }); }, }; diff --git a/src/plugins/manage/modules/credits/modules/transfer/index.ts b/src/plugins/manage/modules/credits/modules/transfer/index.ts index d65667b..011e603 100644 --- a/src/plugins/manage/modules/credits/modules/transfer/index.ts +++ b/src/plugins/manage/modules/credits/modules/transfer/index.ts @@ -1,15 +1,14 @@ // Dependencies import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; +import mongoose from "mongoose"; + // Configurations import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; // Handlers import logger from "../../../../../../logger"; -// Helpers -import saveUser from "../../../../../../helpers/saveUser"; - // Models import fetchUser from "../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; @@ -193,38 +192,66 @@ export default { }); } - // Withdraw amount from fromUser - fromUser.credits -= optionAmount; + const session = await mongoose.startSession(); - // Deposit amount to toUser - toUser.credits += optionAmount; + session.startTransaction(); - // Save users - await saveUser(fromUser, toUser)?.then(async () => { - logger?.silly(`Saved users`); + try { + // Withdraw amount from fromUserDB + fromUser.credits -= optionAmount; - return interaction?.editReply({ + // Deposit amount to toUserDB + toUser.credits += optionAmount; + + await fromUser.save(); + + await toUser.save(); + + await session.commitTransaction(); + } catch (error) { + await session.abortTransaction(); + session.endSession(); + logger.error(`${error}`); + + return interaction.editReply({ embeds: [ new MessageEmbed() .setTitle("[:toolbox:] Manage - Credits (Transfer)") - .setDescription(`Transferred ${optionAmount} credits.`) - .addFields( - { - name: `${optionFromUser?.username} Balance`, - value: `${fromUser?.credits}`, - inline: true, - }, - { - name: `${optionToUser?.username} Balance`, - value: `${toUser?.credits}`, - inline: true, - } + .setDescription( + "An error occurred while trying to gift credits. Please try again." ) + .setColor(errorColor) .setTimestamp(new Date()) .setColor(successColor) .setFooter({ text: footerText, iconURL: footerIcon }), ], }); + } finally { + // ending the session + session.endSession(); + } + + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:toolbox:] Manage - Credits (Transfer)") + .setDescription(`Transferred ${optionAmount} credits.`) + .addFields( + { + name: `${optionFromUser?.username} Balance`, + value: `${fromUser?.credits}`, + inline: true, + }, + { + name: `${optionToUser?.username} Balance`, + value: `${toUser?.credits}`, + inline: true, + } + ) + .setTimestamp(new Date()) + .setColor(successColor) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], }); }, }; From 5623136fcd9f79fc5670777d3608cc5f7da9df73 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 20:24:24 +0200 Subject: [PATCH 22/75] =?UTF-8?q?=E2=9C=A8=20Manual=20code=20drops=20#341?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/manage/modules/credits/index.ts | 5 +- .../modules/credits/modules/drop/index.ts | 126 ++++++++++++++++++ .../manage/modules/credits/modules/index.ts | 3 +- 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/plugins/manage/modules/credits/modules/drop/index.ts diff --git a/src/plugins/manage/modules/credits/index.ts b/src/plugins/manage/modules/credits/index.ts index cd6819b..5e215ec 100644 --- a/src/plugins/manage/modules/credits/index.ts +++ b/src/plugins/manage/modules/credits/index.ts @@ -13,7 +13,8 @@ export const builder = (group: SlashCommandSubcommandGroupBuilder) => { .addSubcommand(modules.give.builder) .addSubcommand(modules.set.builder) .addSubcommand(modules.take.builder) - .addSubcommand(modules.transfer.builder); + .addSubcommand(modules.transfer.builder) + .addSubcommand(modules.drop.builder); }; export const execute = async (interaction: CommandInteraction) => { @@ -26,5 +27,7 @@ export const execute = async (interaction: CommandInteraction) => { return modules.take.execute(interaction); case "transfer": return modules.transfer.execute(interaction); + case "drop": + return modules.drop.execute(interaction); } }; diff --git a/src/plugins/manage/modules/credits/modules/drop/index.ts b/src/plugins/manage/modules/credits/modules/drop/index.ts new file mode 100644 index 0000000..d5129ea --- /dev/null +++ b/src/plugins/manage/modules/credits/modules/drop/index.ts @@ -0,0 +1,126 @@ +// Dependencies +import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { v4 as uuidv4 } from "uuid"; +import axios from "axios"; +import apiSchema from "../../../../../../database/schemas/api"; +import encryption from "../../../../../../handlers/encryption"; + +// Configurations +import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; + +// Handlers +import logger from "../../../../../../logger"; + +// Helpers +import pluralize from "../../../../../../helpers/pluralize"; + +// Models +import fetchUser from "../../../../../../helpers/fetchUser"; + +// Function +export default { + metadata: { + guildOnly: true, + ephemeral: true, + permissions: [Permissions.FLAGS.MANAGE_GUILD], + }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("drop") + .setDescription("Drop some credits for specified amount of users.") + .addIntegerOption((option) => + option + .setName("uses") + .setDescription("How many users should be able to use this.") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("credit") + .setDescription(`How much credits provided per use.`) + .setRequired(true) + ) + .addChannelOption((option) => + option + .setName("channel") + .setDescription("The channel to send the message to.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + if (interaction.guild == null) return; + const { errorColor, successColor, footerText, footerIcon } = + await getEmbedConfig(interaction.guild); // Destructure + const { guild, options } = interaction; + + const uses = options?.getInteger("uses"); + const creditAmount = options?.getInteger("credit"); + const channel = options?.getChannel("channel"); + + if (!uses) throw new Error("Amount of uses is required."); + if (!creditAmount) throw new Error("Amount of credits is required."); + if (!channel) throw new Error("Channel is required."); + + const embed = new MessageEmbed() + .setTitle("[:toolbox:] Drop") + .setFooter({ text: footerText, iconURL: footerIcon }); + + const code = uuidv4(); + + const apiCredentials = await apiSchema?.findOne({ + guildId: guild?.id, + }); + + if (!apiCredentials) return; + + const api = axios?.create({ + baseURL: apiCredentials.url, + headers: { + Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`, + }, + }); + + const shopUrl = apiCredentials?.url?.replace("/api", "/store"); + + await api + .post("vouchers", { + uses, + code, + credits: creditAmount, + memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`, + }) + .then(async () => { + await interaction.editReply({ + embeds: [ + embed + .setColor(successColor) + .setDescription(`Successfully crated code: ${code}`), + ], + }); + + const discordChannel = guild.channels.cache.get(channel.id); + + if (!discordChannel) return; + + if (discordChannel.type !== "GUILD_TEXT") return; + + discordChannel.send({ + embeds: [ + new MessageEmbed() + .setTitle("[:parachute:] Code Drop!") + .addFields([ + { name: "Code", value: `${code}`, inline: true }, + { name: "Amount", value: `${creditAmount}`, inline: true }, + { name: "Uses", value: `${uses}`, inline: true }, + ]) + .setDescription( + `${interaction.user} dropped a voucher! You can use the code [here](${shopUrl})!` + ) + .setColor(successColor), + ], + }); + }); + }, +}; diff --git a/src/plugins/manage/modules/credits/modules/index.ts b/src/plugins/manage/modules/credits/modules/index.ts index ede5ae7..07b72e6 100644 --- a/src/plugins/manage/modules/credits/modules/index.ts +++ b/src/plugins/manage/modules/credits/modules/index.ts @@ -2,5 +2,6 @@ import give from "./give"; import set from "./set"; import take from "./take"; import transfer from "./transfer"; +import drop from "./drop"; -export default { give, set, take, transfer }; +export default { give, set, take, transfer, drop }; From 0fe4e32fb9a627fc6584f6c7047f49829d55f332 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 20:45:03 +0200 Subject: [PATCH 23/75] =?UTF-8?q?=F0=9F=9A=B8=20Author=20is=20now=20an=20l?= =?UTF-8?q?ink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/fun/modules/meme/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/plugins/fun/modules/meme/index.ts b/src/plugins/fun/modules/meme/index.ts index 9134223..c168557 100644 --- a/src/plugins/fun/modules/meme/index.ts +++ b/src/plugins/fun/modules/meme/index.ts @@ -3,7 +3,6 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import axios from "axios"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "../../../../logger"; export default { metadata: { guildOnly: false, ephemeral: false }, @@ -32,7 +31,11 @@ export default { }) .setTitle("[:sweat_smile:] Meme") .addFields([ - { name: "Author", value: content.author, inline: true }, + { + name: "Author", + value: `[${content.author}](https://reddit.com/user/${content.author})`, + inline: true, + }, { name: "Votes", value: `${content.ups}/${content.downs}`, From 825ff53878b93e05b78307bf06fefd0572a9d247 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 21:33:37 +0200 Subject: [PATCH 24/75] =?UTF-8?q?=F0=9F=9A=9A=20plugins=20are=20now=20coma?= =?UTF-8?q?mnds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{plugins => commands}/config/index.ts | 0 .../config/modules/audits/index.ts | 0 .../config/modules/credits/index.ts | 0 .../embeds/components/getValues/index.ts | 0 .../config/modules/embeds/index.ts | 0 .../config/modules/index.ts | 0 .../config/modules/points/index.ts | 0 .../config/modules/pterodactyl/index.ts | 0 .../config/modules/shop/index.ts | 0 .../config/modules/welcome/index.ts | 0 src/{plugins => commands}/counters/index.ts | 2 +- .../counters/modules/index.ts | 0 .../counters/modules/view/index.ts | 0 src/{plugins => commands}/credits/index.ts | 0 .../credits/modules/balance/index.ts | 0 .../credits/modules/gift/index.ts | 0 .../credits/modules/index.ts | 0 .../credits/modules/top/index.ts | 0 .../credits/modules/work/index.ts | 0 src/{plugins => commands}/fun/index.ts | 2 +- .../fun/modules/index.ts | 0 .../fun/modules/meme/index.ts | 0 src/{plugins => commands}/manage/index.ts | 2 +- .../manage/modules/counters/index.ts | 0 .../modules/counters/modules/add/index.ts | 0 .../manage/modules/counters/modules/index.ts | 0 .../modules/counters/modules/remove/index.ts | 0 .../manage/modules/credits/index.ts | 0 .../modules/credits/modules/drop/index.ts | 0 .../modules/credits/modules/give/index.ts | 0 .../manage/modules/credits/modules/index.ts | 0 .../modules/credits/modules/set/index.ts | 0 .../modules/credits/modules/take/index.ts | 0 .../modules/credits/modules/transfer/index.ts | 0 .../manage/modules/index.ts | 0 src/{plugins => commands}/profile/index.ts | 2 +- .../profile/modules/index.ts | 0 .../profile/modules/view.ts | 0 src/{plugins => commands}/reputation/index.ts | 0 .../reputation/modules/give.ts | 0 .../reputation/modules/index.ts | 0 src/{plugins => commands}/shop/index.ts | 0 .../shop/modules/index.ts | 0 .../shop/modules/pterodactyl.ts | 0 .../shop/modules/roles/index.ts | 0 .../shop/modules/roles/modules/buy.ts | 0 .../shop/modules/roles/modules/cancel.ts | 0 .../shop/modules/roles/modules/index.ts | 0 src/{plugins => commands}/utility/index.ts | 2 +- .../utility/modules/about.ts | 0 .../utility/modules/avatar.ts | 0 .../utility/modules/index.ts | 0 .../utility/modules/lookup.ts | 0 .../utility/modules/stats.ts | 0 src/config/example.other.ts | 3 ++ src/handlers/commands.ts | 32 ------------------- src/handlers/deployCommands.ts | 27 ++++++++-------- src/index.ts | 4 +-- src/logger/index.ts | 4 ++- src/managers/command/index.ts | 30 +++++++++++++++++ 60 files changed, 56 insertions(+), 54 deletions(-) rename src/{plugins => commands}/config/index.ts (100%) rename src/{plugins => commands}/config/modules/audits/index.ts (100%) rename src/{plugins => commands}/config/modules/credits/index.ts (100%) rename src/{plugins => commands}/config/modules/embeds/components/getValues/index.ts (100%) rename src/{plugins => commands}/config/modules/embeds/index.ts (100%) rename src/{plugins => commands}/config/modules/index.ts (100%) rename src/{plugins => commands}/config/modules/points/index.ts (100%) rename src/{plugins => commands}/config/modules/pterodactyl/index.ts (100%) rename src/{plugins => commands}/config/modules/shop/index.ts (100%) rename src/{plugins => commands}/config/modules/welcome/index.ts (100%) rename src/{plugins => commands}/counters/index.ts (90%) rename src/{plugins => commands}/counters/modules/index.ts (100%) rename src/{plugins => commands}/counters/modules/view/index.ts (100%) rename src/{plugins => commands}/credits/index.ts (100%) rename src/{plugins => commands}/credits/modules/balance/index.ts (100%) rename src/{plugins => commands}/credits/modules/gift/index.ts (100%) rename src/{plugins => commands}/credits/modules/index.ts (100%) rename src/{plugins => commands}/credits/modules/top/index.ts (100%) rename src/{plugins => commands}/credits/modules/work/index.ts (100%) rename src/{plugins => commands}/fun/index.ts (92%) rename src/{plugins => commands}/fun/modules/index.ts (100%) rename src/{plugins => commands}/fun/modules/meme/index.ts (100%) rename src/{plugins => commands}/manage/index.ts (93%) rename src/{plugins => commands}/manage/modules/counters/index.ts (100%) rename src/{plugins => commands}/manage/modules/counters/modules/add/index.ts (100%) rename src/{plugins => commands}/manage/modules/counters/modules/index.ts (100%) rename src/{plugins => commands}/manage/modules/counters/modules/remove/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/drop/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/give/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/set/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/take/index.ts (100%) rename src/{plugins => commands}/manage/modules/credits/modules/transfer/index.ts (100%) rename src/{plugins => commands}/manage/modules/index.ts (100%) rename src/{plugins => commands}/profile/index.ts (92%) rename src/{plugins => commands}/profile/modules/index.ts (100%) rename src/{plugins => commands}/profile/modules/view.ts (100%) rename src/{plugins => commands}/reputation/index.ts (100%) rename src/{plugins => commands}/reputation/modules/give.ts (100%) rename src/{plugins => commands}/reputation/modules/index.ts (100%) rename src/{plugins => commands}/shop/index.ts (100%) rename src/{plugins => commands}/shop/modules/index.ts (100%) rename src/{plugins => commands}/shop/modules/pterodactyl.ts (100%) rename src/{plugins => commands}/shop/modules/roles/index.ts (100%) rename src/{plugins => commands}/shop/modules/roles/modules/buy.ts (100%) rename src/{plugins => commands}/shop/modules/roles/modules/cancel.ts (100%) rename src/{plugins => commands}/shop/modules/roles/modules/index.ts (100%) rename src/{plugins => commands}/utility/index.ts (94%) rename src/{plugins => commands}/utility/modules/about.ts (100%) rename src/{plugins => commands}/utility/modules/avatar.ts (100%) rename src/{plugins => commands}/utility/modules/index.ts (100%) rename src/{plugins => commands}/utility/modules/lookup.ts (100%) rename src/{plugins => commands}/utility/modules/stats.ts (100%) delete mode 100644 src/handlers/commands.ts create mode 100644 src/managers/command/index.ts diff --git a/src/plugins/config/index.ts b/src/commands/config/index.ts similarity index 100% rename from src/plugins/config/index.ts rename to src/commands/config/index.ts diff --git a/src/plugins/config/modules/audits/index.ts b/src/commands/config/modules/audits/index.ts similarity index 100% rename from src/plugins/config/modules/audits/index.ts rename to src/commands/config/modules/audits/index.ts diff --git a/src/plugins/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts similarity index 100% rename from src/plugins/config/modules/credits/index.ts rename to src/commands/config/modules/credits/index.ts diff --git a/src/plugins/config/modules/embeds/components/getValues/index.ts b/src/commands/config/modules/embeds/components/getValues/index.ts similarity index 100% rename from src/plugins/config/modules/embeds/components/getValues/index.ts rename to src/commands/config/modules/embeds/components/getValues/index.ts diff --git a/src/plugins/config/modules/embeds/index.ts b/src/commands/config/modules/embeds/index.ts similarity index 100% rename from src/plugins/config/modules/embeds/index.ts rename to src/commands/config/modules/embeds/index.ts diff --git a/src/plugins/config/modules/index.ts b/src/commands/config/modules/index.ts similarity index 100% rename from src/plugins/config/modules/index.ts rename to src/commands/config/modules/index.ts diff --git a/src/plugins/config/modules/points/index.ts b/src/commands/config/modules/points/index.ts similarity index 100% rename from src/plugins/config/modules/points/index.ts rename to src/commands/config/modules/points/index.ts diff --git a/src/plugins/config/modules/pterodactyl/index.ts b/src/commands/config/modules/pterodactyl/index.ts similarity index 100% rename from src/plugins/config/modules/pterodactyl/index.ts rename to src/commands/config/modules/pterodactyl/index.ts diff --git a/src/plugins/config/modules/shop/index.ts b/src/commands/config/modules/shop/index.ts similarity index 100% rename from src/plugins/config/modules/shop/index.ts rename to src/commands/config/modules/shop/index.ts diff --git a/src/plugins/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts similarity index 100% rename from src/plugins/config/modules/welcome/index.ts rename to src/commands/config/modules/welcome/index.ts diff --git a/src/plugins/counters/index.ts b/src/commands/counters/index.ts similarity index 90% rename from src/plugins/counters/index.ts rename to src/commands/counters/index.ts index df23d0b..da17e90 100644 --- a/src/plugins/counters/index.ts +++ b/src/commands/counters/index.ts @@ -2,7 +2,7 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; import logger from "../../logger"; -import modules from "../../plugins/counters/modules"; +import modules from "../../commands/counters/modules"; export const builder = new SlashCommandBuilder() .setName("counters") diff --git a/src/plugins/counters/modules/index.ts b/src/commands/counters/modules/index.ts similarity index 100% rename from src/plugins/counters/modules/index.ts rename to src/commands/counters/modules/index.ts diff --git a/src/plugins/counters/modules/view/index.ts b/src/commands/counters/modules/view/index.ts similarity index 100% rename from src/plugins/counters/modules/view/index.ts rename to src/commands/counters/modules/view/index.ts diff --git a/src/plugins/credits/index.ts b/src/commands/credits/index.ts similarity index 100% rename from src/plugins/credits/index.ts rename to src/commands/credits/index.ts diff --git a/src/plugins/credits/modules/balance/index.ts b/src/commands/credits/modules/balance/index.ts similarity index 100% rename from src/plugins/credits/modules/balance/index.ts rename to src/commands/credits/modules/balance/index.ts diff --git a/src/plugins/credits/modules/gift/index.ts b/src/commands/credits/modules/gift/index.ts similarity index 100% rename from src/plugins/credits/modules/gift/index.ts rename to src/commands/credits/modules/gift/index.ts diff --git a/src/plugins/credits/modules/index.ts b/src/commands/credits/modules/index.ts similarity index 100% rename from src/plugins/credits/modules/index.ts rename to src/commands/credits/modules/index.ts diff --git a/src/plugins/credits/modules/top/index.ts b/src/commands/credits/modules/top/index.ts similarity index 100% rename from src/plugins/credits/modules/top/index.ts rename to src/commands/credits/modules/top/index.ts diff --git a/src/plugins/credits/modules/work/index.ts b/src/commands/credits/modules/work/index.ts similarity index 100% rename from src/plugins/credits/modules/work/index.ts rename to src/commands/credits/modules/work/index.ts diff --git a/src/plugins/fun/index.ts b/src/commands/fun/index.ts similarity index 92% rename from src/plugins/fun/index.ts rename to src/commands/fun/index.ts index 758814c..5c71cd2 100644 --- a/src/plugins/fun/index.ts +++ b/src/commands/fun/index.ts @@ -2,7 +2,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; import logger from "../../logger"; -import modules from "../../plugins/fun/modules"; +import modules from "../../commands/fun/modules"; export const builder = new SlashCommandBuilder() .setName("fun") diff --git a/src/plugins/fun/modules/index.ts b/src/commands/fun/modules/index.ts similarity index 100% rename from src/plugins/fun/modules/index.ts rename to src/commands/fun/modules/index.ts diff --git a/src/plugins/fun/modules/meme/index.ts b/src/commands/fun/modules/meme/index.ts similarity index 100% rename from src/plugins/fun/modules/meme/index.ts rename to src/commands/fun/modules/meme/index.ts diff --git a/src/plugins/manage/index.ts b/src/commands/manage/index.ts similarity index 93% rename from src/plugins/manage/index.ts rename to src/commands/manage/index.ts index a54f2e2..14b5f6c 100644 --- a/src/plugins/manage/index.ts +++ b/src/commands/manage/index.ts @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Groups -import modules from "../../plugins/manage/modules"; +import modules from "../../commands/manage/modules"; import logger from "../../logger"; export const moduleData = modules; diff --git a/src/plugins/manage/modules/counters/index.ts b/src/commands/manage/modules/counters/index.ts similarity index 100% rename from src/plugins/manage/modules/counters/index.ts rename to src/commands/manage/modules/counters/index.ts diff --git a/src/plugins/manage/modules/counters/modules/add/index.ts b/src/commands/manage/modules/counters/modules/add/index.ts similarity index 100% rename from src/plugins/manage/modules/counters/modules/add/index.ts rename to src/commands/manage/modules/counters/modules/add/index.ts diff --git a/src/plugins/manage/modules/counters/modules/index.ts b/src/commands/manage/modules/counters/modules/index.ts similarity index 100% rename from src/plugins/manage/modules/counters/modules/index.ts rename to src/commands/manage/modules/counters/modules/index.ts diff --git a/src/plugins/manage/modules/counters/modules/remove/index.ts b/src/commands/manage/modules/counters/modules/remove/index.ts similarity index 100% rename from src/plugins/manage/modules/counters/modules/remove/index.ts rename to src/commands/manage/modules/counters/modules/remove/index.ts diff --git a/src/plugins/manage/modules/credits/index.ts b/src/commands/manage/modules/credits/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/index.ts rename to src/commands/manage/modules/credits/index.ts diff --git a/src/plugins/manage/modules/credits/modules/drop/index.ts b/src/commands/manage/modules/credits/modules/drop/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/drop/index.ts rename to src/commands/manage/modules/credits/modules/drop/index.ts diff --git a/src/plugins/manage/modules/credits/modules/give/index.ts b/src/commands/manage/modules/credits/modules/give/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/give/index.ts rename to src/commands/manage/modules/credits/modules/give/index.ts diff --git a/src/plugins/manage/modules/credits/modules/index.ts b/src/commands/manage/modules/credits/modules/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/index.ts rename to src/commands/manage/modules/credits/modules/index.ts diff --git a/src/plugins/manage/modules/credits/modules/set/index.ts b/src/commands/manage/modules/credits/modules/set/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/set/index.ts rename to src/commands/manage/modules/credits/modules/set/index.ts diff --git a/src/plugins/manage/modules/credits/modules/take/index.ts b/src/commands/manage/modules/credits/modules/take/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/take/index.ts rename to src/commands/manage/modules/credits/modules/take/index.ts diff --git a/src/plugins/manage/modules/credits/modules/transfer/index.ts b/src/commands/manage/modules/credits/modules/transfer/index.ts similarity index 100% rename from src/plugins/manage/modules/credits/modules/transfer/index.ts rename to src/commands/manage/modules/credits/modules/transfer/index.ts diff --git a/src/plugins/manage/modules/index.ts b/src/commands/manage/modules/index.ts similarity index 100% rename from src/plugins/manage/modules/index.ts rename to src/commands/manage/modules/index.ts diff --git a/src/plugins/profile/index.ts b/src/commands/profile/index.ts similarity index 92% rename from src/plugins/profile/index.ts rename to src/commands/profile/index.ts index 808c9e7..2039179 100644 --- a/src/plugins/profile/index.ts +++ b/src/commands/profile/index.ts @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Modules -import modules from "../../plugins/profile/modules"; +import modules from "../../commands/profile/modules"; // Handlers import logger from "../../logger"; diff --git a/src/plugins/profile/modules/index.ts b/src/commands/profile/modules/index.ts similarity index 100% rename from src/plugins/profile/modules/index.ts rename to src/commands/profile/modules/index.ts diff --git a/src/plugins/profile/modules/view.ts b/src/commands/profile/modules/view.ts similarity index 100% rename from src/plugins/profile/modules/view.ts rename to src/commands/profile/modules/view.ts diff --git a/src/plugins/reputation/index.ts b/src/commands/reputation/index.ts similarity index 100% rename from src/plugins/reputation/index.ts rename to src/commands/reputation/index.ts diff --git a/src/plugins/reputation/modules/give.ts b/src/commands/reputation/modules/give.ts similarity index 100% rename from src/plugins/reputation/modules/give.ts rename to src/commands/reputation/modules/give.ts diff --git a/src/plugins/reputation/modules/index.ts b/src/commands/reputation/modules/index.ts similarity index 100% rename from src/plugins/reputation/modules/index.ts rename to src/commands/reputation/modules/index.ts diff --git a/src/plugins/shop/index.ts b/src/commands/shop/index.ts similarity index 100% rename from src/plugins/shop/index.ts rename to src/commands/shop/index.ts diff --git a/src/plugins/shop/modules/index.ts b/src/commands/shop/modules/index.ts similarity index 100% rename from src/plugins/shop/modules/index.ts rename to src/commands/shop/modules/index.ts diff --git a/src/plugins/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts similarity index 100% rename from src/plugins/shop/modules/pterodactyl.ts rename to src/commands/shop/modules/pterodactyl.ts diff --git a/src/plugins/shop/modules/roles/index.ts b/src/commands/shop/modules/roles/index.ts similarity index 100% rename from src/plugins/shop/modules/roles/index.ts rename to src/commands/shop/modules/roles/index.ts diff --git a/src/plugins/shop/modules/roles/modules/buy.ts b/src/commands/shop/modules/roles/modules/buy.ts similarity index 100% rename from src/plugins/shop/modules/roles/modules/buy.ts rename to src/commands/shop/modules/roles/modules/buy.ts diff --git a/src/plugins/shop/modules/roles/modules/cancel.ts b/src/commands/shop/modules/roles/modules/cancel.ts similarity index 100% rename from src/plugins/shop/modules/roles/modules/cancel.ts rename to src/commands/shop/modules/roles/modules/cancel.ts diff --git a/src/plugins/shop/modules/roles/modules/index.ts b/src/commands/shop/modules/roles/modules/index.ts similarity index 100% rename from src/plugins/shop/modules/roles/modules/index.ts rename to src/commands/shop/modules/roles/modules/index.ts diff --git a/src/plugins/utility/index.ts b/src/commands/utility/index.ts similarity index 94% rename from src/plugins/utility/index.ts rename to src/commands/utility/index.ts index 4849a3b..6fb52db 100644 --- a/src/plugins/utility/index.ts +++ b/src/commands/utility/index.ts @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Modules -import modules from "../../plugins/utility/modules"; +import modules from "../../commands/utility/modules"; // Handlers import logger from "../../logger"; diff --git a/src/plugins/utility/modules/about.ts b/src/commands/utility/modules/about.ts similarity index 100% rename from src/plugins/utility/modules/about.ts rename to src/commands/utility/modules/about.ts diff --git a/src/plugins/utility/modules/avatar.ts b/src/commands/utility/modules/avatar.ts similarity index 100% rename from src/plugins/utility/modules/avatar.ts rename to src/commands/utility/modules/avatar.ts diff --git a/src/plugins/utility/modules/index.ts b/src/commands/utility/modules/index.ts similarity index 100% rename from src/plugins/utility/modules/index.ts rename to src/commands/utility/modules/index.ts diff --git a/src/plugins/utility/modules/lookup.ts b/src/commands/utility/modules/lookup.ts similarity index 100% rename from src/plugins/utility/modules/lookup.ts rename to src/commands/utility/modules/lookup.ts diff --git a/src/plugins/utility/modules/stats.ts b/src/commands/utility/modules/stats.ts similarity index 100% rename from src/plugins/utility/modules/stats.ts rename to src/commands/utility/modules/stats.ts diff --git a/src/config/example.other.ts b/src/config/example.other.ts index 3a86a51..1695d42 100644 --- a/src/config/example.other.ts +++ b/src/config/example.other.ts @@ -9,3 +9,6 @@ export const hosterName = "someone"; // Hoster Url export const hosterUrl = "scheme://domain.tld"; + +// Winston log level +export const logLevel = "info"; diff --git a/src/handlers/commands.ts b/src/handlers/commands.ts deleted file mode 100644 index 1df02fe..0000000 --- a/src/handlers/commands.ts +++ /dev/null @@ -1,32 +0,0 @@ -import fs from "fs"; // fs -import { Collection, Client } from "discord.js"; // discord.js -import logger from "../logger"; -import { ICommand } from "../interfaces/Command"; - -export default async (client: Client) => { - client.commands = new Collection(); - - fs.readdir("plugins", async (error, plugins) => { - if (error) { - return logger.error(`Error reading plugins: ${error}`); - } - - await Promise.all( - plugins.map(async (pluginName, index) => { - const plugin: ICommand = await import(`../plugins/${pluginName}`); - - await client.commands.set(plugin.builder.name, plugin); - - logger.verbose( - `Loaded plugin ${index + 1}/${plugins.length}: ${pluginName}` - ); - }) - ) - .then(async () => { - logger.info(`Started all ${plugins.length} plugins.`); - }) - .catch(async (err) => { - logger.error(`${err}`); - }); - }); -}; diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index e0fe066..97c1786 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -2,7 +2,7 @@ import { token, clientId } from "../config/discord"; import { devMode, guildId } from "../config/other"; import logger from "../logger"; -import { Client } from "discord.js"; +import { ApplicationCommandDataResolvable, Client } from "discord.js"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; @@ -10,18 +10,19 @@ import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { - const pluginList: Array = []; + const commandList: Array = []; + + logger.info("Gathering command list"); await Promise.all( - client.commands.map(async (pluginData: ICommand) => { - pluginList.push(pluginData.builder.toJSON()); - logger.verbose( - `Plugin is ready for deployment: ${pluginData.builder.name}` - ); + client.commands.map(async (commandData: ICommand) => { + commandList.push(commandData.builder.toJSON()); + + logger.verbose(`${commandData.builder.name} pushed to list`); }) ) .then(async () => { - logger.info("All plugins are ready to be deployed."); + logger.info(`Finished gathering command list.`); }) .catch(async (error) => { logger.error(`${error}`); @@ -31,10 +32,10 @@ export default async (client: Client) => { await rest .put(Routes.applicationCommands(clientId), { - body: pluginList, + body: commandList, }) .then(async () => { - logger.info(`Successfully deployed plugins to Discord's API`); + logger.info(`Finished updating command list.`); }) .catch(async (error) => { logger.error(`${error}`); @@ -43,11 +44,9 @@ export default async (client: Client) => { if (devMode) { await rest .put(Routes.applicationGuildCommands(clientId, guildId), { - body: pluginList, + body: commandList, }) - .then(async () => - logger.info(`Successfully deployed guild plugins to Discord's API`) - ) + .then(async () => logger.info(`Finished updating guild command list.`)) .catch(async (error) => { logger.error(`${error}`); }); diff --git a/src/index.ts b/src/index.ts index cad389c..31e3e40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,7 @@ import { Client } from "discord.js"; // discord.js import database from "./database"; import schedules from "./handlers/schedules"; import * as eventManager from "./managers/event"; -import commands from "./handlers/commands"; +import * as commandManager from "./managers/command"; // Main process that starts all other sub processes const main = async () => { @@ -23,7 +23,7 @@ const main = async () => { await schedules(client); // Start command handler - await commands(client); + await commandManager.register(client); // Start event handler await eventManager.register(client); diff --git a/src/logger/index.ts b/src/logger/index.ts index ae96924..1ffbceb 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -1,10 +1,12 @@ import winston from "winston"; import "winston-daily-rotate-file"; +import { logLevel } from "../config/other"; + const { combine, timestamp, printf, colorize, align, json } = winston.format; export default winston.createLogger({ - level: process.env.LOG_LEVEL || "silly", + level: logLevel || "info", transports: [ new winston.transports.DailyRotateFile({ filename: "logs/combined-%DATE%.log", diff --git a/src/managers/command/index.ts b/src/managers/command/index.ts new file mode 100644 index 0000000..3cf3316 --- /dev/null +++ b/src/managers/command/index.ts @@ -0,0 +1,30 @@ +import fs from "fs"; // fs +import { Collection, Client } from "discord.js"; // discord.js +import logger from "../../logger"; +import { ICommand } from "../../interfaces/Command"; +import listDir from "../../helpers/listDir"; + +export const register = async (client: Client) => { + client.commands = new Collection(); + + const commandNames = await listDir("commands"); + if (!commandNames) return; + + logger.info(`Loading ${commandNames.length} commands`); + + await Promise.all( + commandNames.map(async (commandName, index) => { + const command: ICommand = await import(`../../commands/${commandName}`); + + client.commands.set(command.builder.name, command); + + logger.verbose(`${command.builder.name} loaded`); + }) + ) + .then(async () => { + logger.info(`Finished loading commands.`); + }) + .catch(async (err) => { + logger.error(`${err}`); + }); +}; From 5bcfafd0ed4ffcd325fa88051c96f12149946df8 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 29 May 2022 21:48:12 +0200 Subject: [PATCH 25/75] =?UTF-8?q?=F0=9F=93=88=20add=20total=20users=20to?= =?UTF-8?q?=20default=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/ready/index.ts | 8 +------- src/handlers/deployCommands.ts | 2 +- src/helpers/updatePresence/index.ts | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/events/ready/index.ts b/src/events/ready/index.ts index 61ce106..bd1e060 100644 --- a/src/events/ready/index.ts +++ b/src/events/ready/index.ts @@ -13,15 +13,9 @@ export const options: IEventOptions = { }; export const execute = async (client: Client) => { - logger.info("Ready!"); + logger.info("Discord's API client is ready!"); await updatePresence(client); await devMode(client); await deployCommands(client); - - client.guilds?.cache.forEach((guild) => { - logger.silly( - `${client.user?.tag} (${client.user?.id}) is in guild: ${guild.name} (${guild.id}) with member count of ${guild.memberCount}` - ); - }); }; diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 97c1786..2123da7 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -2,7 +2,7 @@ import { token, clientId } from "../config/discord"; import { devMode, guildId } from "../config/other"; import logger from "../logger"; -import { ApplicationCommandDataResolvable, Client } from "discord.js"; +import { Client } from "discord.js"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; diff --git a/src/helpers/updatePresence/index.ts b/src/helpers/updatePresence/index.ts index 3add873..a8c4a35 100644 --- a/src/helpers/updatePresence/index.ts +++ b/src/helpers/updatePresence/index.ts @@ -4,11 +4,20 @@ import logger from "../../logger"; // Function export default async (client: Client) => { - const status = `${client?.guilds?.cache?.size} guilds.`; + if (!client?.user) throw new Error("Client's user is undefined."); - client?.user?.setPresence({ - activities: [{ type: "WATCHING", name: status }], + const { guilds } = client; + + const memberCount = guilds.cache.reduce((a, g) => a + g.memberCount, 0); + + const guildCount = guilds.cache.size; + + const status = `${memberCount} users in ${guildCount} guilds.`; + + client.user.setPresence({ + activities: [{ type: "LISTENING", name: status }], status: "online", }); - logger?.debug(`Updated client presence to: ${status}`); + + logger.info(`Client's presence is set to "${status}"`); }; From 2dffdfcb5b91848c6a37d02a3f082b9d670bb6a5 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:29:06 +0200 Subject: [PATCH 26/75] =?UTF-8?q?=F0=9F=9A=9A=20schedule=20handler=20is=20?= =?UTF-8?q?now=20a=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/schedules/index.ts | 24 ------------------------ src/index.ts | 4 ++-- src/interfaces/Job.ts | 8 ++++++++ src/jobs/shopRoles.ts | 30 +++++------------------------- src/managers/schedule/index.ts | 29 +++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 51 deletions(-) delete mode 100644 src/handlers/schedules/index.ts create mode 100644 src/interfaces/Job.ts create mode 100644 src/managers/schedule/index.ts diff --git a/src/handlers/schedules/index.ts b/src/handlers/schedules/index.ts deleted file mode 100644 index c6a1cef..0000000 --- a/src/handlers/schedules/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Dependencies -import { Client } from "discord.js"; -import schedule from "node-schedule"; - -import logger from "../../logger"; - -// Jobs -import shopRoles from "../../jobs/shopRoles"; - -export default async (client: Client) => { - const expression = "*/5 * * * *"; - - schedule.scheduleJob(expression, async () => { - logger.info("Running jobs."); - - await shopRoles(client) - .then(() => { - logger.info("Shop roles job finished."); - }) - .catch((err) => { - logger.error(`Shop roles job failed: ${err}`); - }); - }); -}; diff --git a/src/index.ts b/src/index.ts index 31e3e40..c6179e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { token, intents } from "./config/discord"; import { Client } from "discord.js"; // discord.js import database from "./database"; -import schedules from "./handlers/schedules"; +import * as scheduleManager from "./managers/schedule"; import * as eventManager from "./managers/event"; import * as commandManager from "./managers/command"; @@ -20,7 +20,7 @@ const main = async () => { await database(); // Start schedule manager - await schedules(client); + await scheduleManager.start(client); // Start command handler await commandManager.register(client); diff --git a/src/interfaces/Job.ts b/src/interfaces/Job.ts new file mode 100644 index 0000000..d58dbf8 --- /dev/null +++ b/src/interfaces/Job.ts @@ -0,0 +1,8 @@ +import { Client } from "discord.js"; + +export interface IJob { + options: { + schedule: string; + }; + execute: (client: Client) => Promise; +} diff --git a/src/jobs/shopRoles.ts b/src/jobs/shopRoles.ts index 76ea653..c059672 100644 --- a/src/jobs/shopRoles.ts +++ b/src/jobs/shopRoles.ts @@ -8,53 +8,43 @@ import userSchema from "../database/schemas/user"; import shopRoleSchema from "../database/schemas/shopRole"; import guildSchema from "../database/schemas/guild"; -export default async (client: Client) => { - const roles = await shopRoleSchema.find(); +export const options = { + schedule: "*/1 * * * * *", +}; +export const execute = async (client: Client) => { + const roles = await shopRoleSchema.find(); await Promise.all( roles.map(async (role) => { const { guildId, userId, roleId } = role; - const lastPayment = new Date(role.lastPayed); - const nextPayment = new Date( lastPayment.setHours(lastPayment.getHours() + 1) ); - if (new Date() < nextPayment) { logger.silly(`Shop role ${roleId} is not due for payment.`); } - const guildData = await guildSchema.findOne({ guildId }); - if (!guildData) { logger.error(`Guild ${guildId} not found.`); return; } - if (!userId) { logger.error(`User ID not found for shop role ${roleId}.`); return; } - const userData = await userSchema.findOne({ guildId, userId }); - if (!userData) { logger.error(`User ${userId} not found for shop role ${roleId}.`); return; } - const rGuild = client?.guilds?.cache?.get(guildId); - const rMember = await rGuild?.members?.fetch(userId); - if (!rMember) { logger.error(`Member ${userId} not found for shop role ${roleId}.`); return; } - const rRole = rMember.roles.cache.get(roleId); - if (!rMember || !rRole) { logger.error(`Member ${userId} not found for shop role ${roleId}.`); await shopRoleSchema @@ -76,36 +66,27 @@ export default async (client: Client) => { }); return; } - if (new Date() > nextPayment) { logger.silly( `Shop role ${roleId} is due for payment. Withdrawing credits from user ${userId}.` ); - const { pricePerHour } = guildData.shop.roles; - if (userData.credits < pricePerHour) { logger.error( `User ${userId} does not have enough credits to pay for shop role ${roleId}.` ); - if (!rMember) { logger.error(`Member ${userId} not found for shop role ${roleId}.`); return; } - rMember.roles.remove(roleId); - return; } - userData.credits -= pricePerHour; - await userData .save() .then(async () => { role.lastPayed = new Date(); - await role .save() .then(async () => { @@ -117,7 +98,6 @@ export default async (client: Client) => { err ); }); - logger.silly( `Shop role ${roleId} has been paid for. Keeping role ${roleId} for user ${userId}.` ); diff --git a/src/managers/schedule/index.ts b/src/managers/schedule/index.ts new file mode 100644 index 0000000..84e77af --- /dev/null +++ b/src/managers/schedule/index.ts @@ -0,0 +1,29 @@ +import logger from "../../logger"; +import { Client } from "discord.js"; + +import { IJob } from "../../interfaces/Job"; + +import listDir from "../../helpers/listDir"; + +import schedule from "node-schedule"; + +export const start = async (client: Client) => { + logger.info("Starting schedule manager..."); + + const jobNames = await listDir("jobs"); + if (!jobNames) return logger.info("No jobs found"); + + await Promise.all( + jobNames.map(async (jobName, index) => { + const job: IJob = await import(`../../jobs/shopRoles`); + + schedule.scheduleJob(job.options.schedule, async () => { + logger.info(`Executed job ${jobName}!`); + await job.execute(client); + }); + }) + ).then(async () => { + const list = schedule.scheduledJobs; + logger.silly(list); + }); +}; From e6af84f702fff16306088318dded8959674b40af Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:31:34 +0200 Subject: [PATCH 27/75] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20added=20event=20t?= =?UTF-8?q?ype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/Event.ts | 6 ++++++ src/managers/event/index.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/interfaces/Event.ts diff --git a/src/interfaces/Event.ts b/src/interfaces/Event.ts new file mode 100644 index 0000000..8a22171 --- /dev/null +++ b/src/interfaces/Event.ts @@ -0,0 +1,6 @@ +import { IEventOptions } from "./EventOptions"; + +export interface IEvent { + options: IEventOptions; + execute: (...args: any[]) => Promise; +} diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 8a3a506..537f730 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -1,13 +1,14 @@ /* eslint-disable no-loops/no-loops */ import { Client } from "discord.js"; import listDir from "../../helpers/listDir"; +import { IEvent } from "../../interfaces/Event"; export const register = async (client: Client) => { const eventNames = await listDir("events"); if (!eventNames) return; for await (const eventName of eventNames) { - const event = await import(`../../events/${eventName}`); + const event: IEvent = await import(`../../events/${eventName}`); const eventExecutor = async (...args: any[]) => event.execute(...args); if (!event.options?.type) return; From 92b0f6baefe42e06836cf7057f13126d4d42aea5 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:34:10 +0200 Subject: [PATCH 28/75] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Event=20type=20an?= =?UTF-8?q?y=20is=20now=20Promise?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/Event.ts | 2 +- src/managers/command/index.ts | 2 +- src/managers/event/index.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/interfaces/Event.ts b/src/interfaces/Event.ts index 8a22171..c411a9f 100644 --- a/src/interfaces/Event.ts +++ b/src/interfaces/Event.ts @@ -2,5 +2,5 @@ import { IEventOptions } from "./EventOptions"; export interface IEvent { options: IEventOptions; - execute: (...args: any[]) => Promise; + execute: (...args: Promise[]) => Promise; } diff --git a/src/managers/command/index.ts b/src/managers/command/index.ts index 3cf3316..ece1712 100644 --- a/src/managers/command/index.ts +++ b/src/managers/command/index.ts @@ -13,7 +13,7 @@ export const register = async (client: Client) => { logger.info(`Loading ${commandNames.length} commands`); await Promise.all( - commandNames.map(async (commandName, index) => { + commandNames.map(async (commandName) => { const command: ICommand = await import(`../../commands/${commandName}`); client.commands.set(command.builder.name, command); diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 537f730..9718b12 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -9,7 +9,8 @@ export const register = async (client: Client) => { for await (const eventName of eventNames) { const event: IEvent = await import(`../../events/${eventName}`); - const eventExecutor = async (...args: any[]) => event.execute(...args); + const eventExecutor = async (...args: Promise[]) => + event.execute(...args); if (!event.options?.type) return; switch (event.options.type) { From 7fd9b6fc73a837a9505fb3d31cda5a08ac63c42c Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:39:52 +0200 Subject: [PATCH 29/75] =?UTF-8?q?=F0=9F=8E=A8=20move=20database=20connecto?= =?UTF-8?q?r=20to=20manager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/config/modules/audits/index.ts | 2 +- src/commands/config/modules/credits/index.ts | 2 +- .../modules/embeds/components/getValues/index.ts | 2 +- src/commands/config/modules/embeds/index.ts | 2 +- src/commands/config/modules/points/index.ts | 2 +- src/commands/config/modules/pterodactyl/index.ts | 2 +- src/commands/config/modules/shop/index.ts | 2 +- src/commands/config/modules/welcome/index.ts | 2 +- src/commands/counters/modules/view/index.ts | 2 +- src/commands/credits/modules/top/index.ts | 2 +- src/commands/credits/modules/work/index.ts | 2 +- .../manage/modules/counters/modules/add/index.ts | 2 +- .../manage/modules/counters/modules/remove/index.ts | 2 +- .../manage/modules/credits/modules/drop/index.ts | 2 +- src/commands/reputation/modules/give.ts | 2 +- src/commands/shop/modules/pterodactyl.ts | 2 +- src/commands/shop/modules/roles/index.ts | 2 +- src/commands/shop/modules/roles/modules/buy.ts | 4 ++-- src/commands/shop/modules/roles/modules/cancel.ts | 2 +- src/events/guildMemberAdd/audits.ts | 2 +- src/events/guildMemberAdd/joinMessage.ts | 2 +- src/events/guildMemberRemove/audits.ts | 2 +- src/events/guildMemberRemove/leaveMessage.ts | 2 +- src/events/interactionCreate/audits.ts | 2 +- src/events/messageCreate/modules/counters/index.ts | 2 +- src/events/messageCreate/modules/credits/index.ts | 2 +- src/events/messageCreate/modules/points/index.ts | 2 +- src/events/messageDelete/audits.ts | 2 +- src/events/messageDelete/modules/counter.ts | 2 +- src/events/messageUpdate/audits.ts | 2 +- src/events/messageUpdate/modules/counter.ts | 2 +- src/helpers/dropGuild/index.ts | 12 ++++++------ src/helpers/dropUser/index.ts | 2 +- src/helpers/fetchGuild/index.ts | 2 +- src/helpers/fetchUser/index.ts | 2 +- src/helpers/getEmbedConfig/index.ts | 2 +- src/index.ts | 12 +++--------- src/jobs/shopRoles.ts | 6 +++--- src/{ => managers}/database/index.ts | 6 +++--- src/{database/schemas => models}/api.ts | 2 +- src/{database/schemas => models}/counter.ts | 0 src/{database/schemas => models}/guild.ts | 0 src/{database/schemas => models}/shopRole.ts | 0 src/{database/schemas => models}/timeout.ts | 0 src/{database/schemas => models}/user.ts | 0 45 files changed, 52 insertions(+), 58 deletions(-) rename src/{ => managers}/database/index.ts (78%) rename src/{database/schemas => models}/api.ts (92%) rename src/{database/schemas => models}/counter.ts (100%) rename src/{database/schemas => models}/guild.ts (100%) rename src/{database/schemas => models}/shopRole.ts (100%) rename src/{database/schemas => models}/timeout.ts (100%) rename src/{database/schemas => models}/user.ts (100%) diff --git a/src/commands/config/modules/audits/index.ts b/src/commands/config/modules/audits/index.ts index 0ea9a17..6d85a15 100644 --- a/src/commands/config/modules/audits/index.ts +++ b/src/commands/config/modules/audits/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/commands/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts index 8ec5998..20df392 100644 --- a/src/commands/config/modules/credits/index.ts +++ b/src/commands/config/modules/credits/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/commands/config/modules/embeds/components/getValues/index.ts b/src/commands/config/modules/embeds/components/getValues/index.ts index d511a52..38702e2 100644 --- a/src/commands/config/modules/embeds/components/getValues/index.ts +++ b/src/commands/config/modules/embeds/components/getValues/index.ts @@ -1,5 +1,5 @@ import { ColorResolvable, CommandInteraction } from "discord.js"; -import guildSchema from "../../../../../../database/schemas/guild"; +import guildSchema from "../../../../../../models/guild"; import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; export default async (interaction: CommandInteraction) => { diff --git a/src/commands/config/modules/embeds/index.ts b/src/commands/config/modules/embeds/index.ts index 94f1db8..218bb26 100644 --- a/src/commands/config/modules/embeds/index.ts +++ b/src/commands/config/modules/embeds/index.ts @@ -10,7 +10,7 @@ import { import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import getValues from "./components/getValues"; diff --git a/src/commands/config/modules/points/index.ts b/src/commands/config/modules/points/index.ts index 0693916..6683df7 100644 --- a/src/commands/config/modules/points/index.ts +++ b/src/commands/config/modules/points/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/commands/config/modules/pterodactyl/index.ts b/src/commands/config/modules/pterodactyl/index.ts index 52e65b0..c73189a 100644 --- a/src/commands/config/modules/pterodactyl/index.ts +++ b/src/commands/config/modules/pterodactyl/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import apiSchema from "../../../../database/schemas/api"; +import apiSchema from "../../../../models/api"; import encryption from "../../../../handlers/encryption"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; diff --git a/src/commands/config/modules/shop/index.ts b/src/commands/config/modules/shop/index.ts index a775385..fc4f467 100644 --- a/src/commands/config/modules/shop/index.ts +++ b/src/commands/config/modules/shop/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/commands/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts index e6d5e9b..8405aeb 100644 --- a/src/commands/config/modules/welcome/index.ts +++ b/src/commands/config/modules/welcome/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/commands/counters/modules/view/index.ts b/src/commands/counters/modules/view/index.ts index b509dd5..6c3196f 100644 --- a/src/commands/counters/modules/view/index.ts +++ b/src/commands/counters/modules/view/index.ts @@ -4,7 +4,7 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; -import counterSchema from "../../../../database/schemas/counter"; +import counterSchema from "../../../../models/counter"; export default { metadata: { guildOnly: true, ephemeral: false }, diff --git a/src/commands/credits/modules/top/index.ts b/src/commands/credits/modules/top/index.ts index 0aaa2f8..78539c4 100644 --- a/src/commands/credits/modules/top/index.ts +++ b/src/commands/credits/modules/top/index.ts @@ -4,7 +4,7 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import logger from "../../../../logger"; -import userSchema, { IUser } from "../../../../database/schemas/user"; +import userSchema, { IUser } from "../../../../models/user"; export default { metadata: { guildOnly: true, ephemeral: false }, diff --git a/src/commands/credits/modules/work/index.ts b/src/commands/credits/modules/work/index.ts index 7f29629..ba1a08e 100644 --- a/src/commands/credits/modules/work/index.ts +++ b/src/commands/credits/modules/work/index.ts @@ -10,7 +10,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; import logger from "../../../../logger"; // Models -import timeoutSchema from "../../../../database/schemas/timeout"; +import timeoutSchema from "../../../../models/timeout"; // Helpers import fetchUser from "../../../../helpers/fetchUser"; diff --git a/src/commands/manage/modules/counters/modules/add/index.ts b/src/commands/manage/modules/counters/modules/add/index.ts index cdefbb8..5d7ea53 100644 --- a/src/commands/manage/modules/counters/modules/add/index.ts +++ b/src/commands/manage/modules/counters/modules/add/index.ts @@ -9,7 +9,7 @@ import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; import logger from "../../../../../../logger"; // Models -import counterSchema from "../../../../../../database/schemas/counter"; +import counterSchema from "../../../../../../models/counter"; // Function export default { diff --git a/src/commands/manage/modules/counters/modules/remove/index.ts b/src/commands/manage/modules/counters/modules/remove/index.ts index 295f2b0..c265f0b 100644 --- a/src/commands/manage/modules/counters/modules/remove/index.ts +++ b/src/commands/manage/modules/counters/modules/remove/index.ts @@ -8,7 +8,7 @@ import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; import logger from "../../../../../../logger"; // Models -import counterSchema from "../../../../../../database/schemas/counter"; +import counterSchema from "../../../../../../models/counter"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; diff --git a/src/commands/manage/modules/credits/modules/drop/index.ts b/src/commands/manage/modules/credits/modules/drop/index.ts index d5129ea..7141c9a 100644 --- a/src/commands/manage/modules/credits/modules/drop/index.ts +++ b/src/commands/manage/modules/credits/modules/drop/index.ts @@ -3,7 +3,7 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { v4 as uuidv4 } from "uuid"; import axios from "axios"; -import apiSchema from "../../../../../../database/schemas/api"; +import apiSchema from "../../../../../../models/api"; import encryption from "../../../../../../handlers/encryption"; // Configurations diff --git a/src/commands/reputation/modules/give.ts b/src/commands/reputation/modules/give.ts index c55e909..8e7d980 100644 --- a/src/commands/reputation/modules/give.ts +++ b/src/commands/reputation/modules/give.ts @@ -10,7 +10,7 @@ import { timeout } from "../../../config/reputation"; import logger from "../../../logger"; // Models -import timeoutSchema from "../../../database/schemas/timeout"; +import timeoutSchema from "../../../models/timeout"; import fetchUser from "../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/commands/shop/modules/pterodactyl.ts index daa698d..207774c 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/commands/shop/modules/pterodactyl.ts @@ -9,7 +9,7 @@ import encryption from "../../../handlers/encryption"; import pluralize from "../../../helpers/pluralize"; -import apiSchema from "../../../database/schemas/api"; +import apiSchema from "../../../models/api"; import fetchUser from "../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; diff --git a/src/commands/shop/modules/roles/index.ts b/src/commands/shop/modules/roles/index.ts index bdec977..7d6cb90 100644 --- a/src/commands/shop/modules/roles/index.ts +++ b/src/commands/shop/modules/roles/index.ts @@ -10,7 +10,7 @@ import getEmbedConfig from "../../../../helpers/getEmbedConfig"; // Modules import modules from "./modules"; -import guildSchema from "../../../../database/schemas/guild"; +import guildSchema from "../../../../models/guild"; export const moduleData = modules; diff --git a/src/commands/shop/modules/roles/modules/buy.ts b/src/commands/shop/modules/roles/modules/buy.ts index b92ba7a..3d8ff54 100644 --- a/src/commands/shop/modules/roles/modules/buy.ts +++ b/src/commands/shop/modules/roles/modules/buy.ts @@ -9,8 +9,8 @@ import { import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "../../../../../database/schemas/shopRole"; -import guildSchema from "../../../../../database/schemas/guild"; +import shopRolesSchema from "../../../../../models/shopRole"; +import guildSchema from "../../../../../models/guild"; import logger from "../../../../../logger"; diff --git a/src/commands/shop/modules/roles/modules/cancel.ts b/src/commands/shop/modules/roles/modules/cancel.ts index cf16d95..d8b4314 100644 --- a/src/commands/shop/modules/roles/modules/cancel.ts +++ b/src/commands/shop/modules/roles/modules/cancel.ts @@ -5,7 +5,7 @@ import { CommandInteraction, GuildMemberRoleManager } from "discord.js"; import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "../../../../../database/schemas/shopRole"; +import shopRolesSchema from "../../../../../models/shopRole"; import logger from "../../../../../logger"; diff --git a/src/events/guildMemberAdd/audits.ts b/src/events/guildMemberAdd/audits.ts index 6e140c6..5134b14 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/events/guildMemberAdd/audits.ts @@ -1,7 +1,7 @@ import logger from "../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/guildMemberAdd/joinMessage.ts b/src/events/guildMemberAdd/joinMessage.ts index db0a745..4ffc3d4 100644 --- a/src/events/guildMemberAdd/joinMessage.ts +++ b/src/events/guildMemberAdd/joinMessage.ts @@ -1,6 +1,6 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/guildMemberRemove/audits.ts b/src/events/guildMemberRemove/audits.ts index 9f2c343..6d1e828 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/events/guildMemberRemove/audits.ts @@ -1,7 +1,7 @@ import logger from "../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/guildMemberRemove/leaveMessage.ts b/src/events/guildMemberRemove/leaveMessage.ts index 427866b..5d3a36e 100644 --- a/src/events/guildMemberRemove/leaveMessage.ts +++ b/src/events/guildMemberRemove/leaveMessage.ts @@ -1,6 +1,6 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/interactionCreate/audits.ts b/src/events/interactionCreate/audits.ts index 3a311c5..3f68219 100644 --- a/src/events/interactionCreate/audits.ts +++ b/src/events/interactionCreate/audits.ts @@ -1,7 +1,7 @@ import logger from "../../logger"; import { Interaction, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/messageCreate/modules/counters/index.ts b/src/events/messageCreate/modules/counters/index.ts index 882fbc6..9dcfca5 100644 --- a/src/events/messageCreate/modules/counters/index.ts +++ b/src/events/messageCreate/modules/counters/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; import logger from "../../../../logger"; -import counterSchema from "../../../../database/schemas/counter"; +import counterSchema from "../../../../models/counter"; export default { execute: async (message: Message) => { diff --git a/src/events/messageCreate/modules/credits/index.ts b/src/events/messageCreate/modules/credits/index.ts index 1058490..ce96c4a 100644 --- a/src/events/messageCreate/modules/credits/index.ts +++ b/src/events/messageCreate/modules/credits/index.ts @@ -1,5 +1,5 @@ import logger from "../../../../logger"; -import timeouts from "../../../../database/schemas/timeout"; +import timeouts from "../../../../models/timeout"; import { Message } from "discord.js"; import fetchUser from "../../../../helpers/fetchUser"; diff --git a/src/events/messageCreate/modules/points/index.ts b/src/events/messageCreate/modules/points/index.ts index 12b683a..9a8acd7 100644 --- a/src/events/messageCreate/modules/points/index.ts +++ b/src/events/messageCreate/modules/points/index.ts @@ -1,5 +1,5 @@ import logger from "../../../../logger"; -import timeouts from "../../../../database/schemas/timeout"; +import timeouts from "../../../../models/timeout"; import fetchUser from "../../../../helpers/fetchUser"; import fetchGuild from "../../../../helpers/fetchGuild"; diff --git a/src/events/messageDelete/audits.ts b/src/events/messageDelete/audits.ts index eb28000..0b8698e 100644 --- a/src/events/messageDelete/audits.ts +++ b/src/events/messageDelete/audits.ts @@ -1,7 +1,7 @@ import logger from "../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/messageDelete/modules/counter.ts b/src/events/messageDelete/modules/counter.ts index e488ae4..7fa9e46 100644 --- a/src/events/messageDelete/modules/counter.ts +++ b/src/events/messageDelete/modules/counter.ts @@ -2,7 +2,7 @@ import { Message } from "discord.js"; // Models -import counterSchema from "../../../database/schemas/counter"; +import counterSchema from "../../../models/counter"; import logger from "../../../logger"; export default async (message: Message) => { diff --git a/src/events/messageUpdate/audits.ts b/src/events/messageUpdate/audits.ts index 3438666..db75a84 100644 --- a/src/events/messageUpdate/audits.ts +++ b/src/events/messageUpdate/audits.ts @@ -2,7 +2,7 @@ import logger from "../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import getEmbedConfig from "../../helpers/getEmbedConfig"; diff --git a/src/events/messageUpdate/modules/counter.ts b/src/events/messageUpdate/modules/counter.ts index 8ea7087..9a79118 100644 --- a/src/events/messageUpdate/modules/counter.ts +++ b/src/events/messageUpdate/modules/counter.ts @@ -2,7 +2,7 @@ import { Message } from "discord.js"; // Models -import counterSchema from "../../../database/schemas/counter"; +import counterSchema from "../../../models/counter"; import logger from "../../../logger"; export default async (message: Message) => { diff --git a/src/helpers/dropGuild/index.ts b/src/helpers/dropGuild/index.ts index e0d8356..0c0e2ab 100644 --- a/src/helpers/dropGuild/index.ts +++ b/src/helpers/dropGuild/index.ts @@ -1,9 +1,9 @@ -import guildSchema from "../../database/schemas/guild"; -import userSchema from "../../database/schemas/user"; -import apiSchema from "../../database/schemas/api"; -import counterSchema from "../../database/schemas/counter"; -import shopRoleSchema from "../../database/schemas/shopRole"; -import timeoutSchema from "../../database/schemas/timeout"; +import guildSchema from "../../models/guild"; +import userSchema from "../../models/user"; +import apiSchema from "../../models/api"; +import counterSchema from "../../models/counter"; +import shopRoleSchema from "../../models/shopRole"; +import timeoutSchema from "../../models/timeout"; import logger from "../../logger"; diff --git a/src/helpers/dropUser/index.ts b/src/helpers/dropUser/index.ts index 976cd6c..3093048 100644 --- a/src/helpers/dropUser/index.ts +++ b/src/helpers/dropUser/index.ts @@ -1,4 +1,4 @@ -import userSchema from "../../database/schemas/user"; +import userSchema from "../../models/user"; import logger from "../../logger"; diff --git a/src/helpers/fetchGuild/index.ts b/src/helpers/fetchGuild/index.ts index bf4aff5..a89e840 100644 --- a/src/helpers/fetchGuild/index.ts +++ b/src/helpers/fetchGuild/index.ts @@ -2,7 +2,7 @@ import { Guild } from "discord.js"; // Models -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; // Handlers import logger from "../../logger"; diff --git a/src/helpers/fetchUser/index.ts b/src/helpers/fetchUser/index.ts index 19b9f1f..3837f24 100644 --- a/src/helpers/fetchUser/index.ts +++ b/src/helpers/fetchUser/index.ts @@ -2,7 +2,7 @@ import { Guild, User } from "discord.js"; // Models -import userSchema from "../../database/schemas/user"; +import userSchema from "../../models/user"; // Handlers import logger from "../../logger"; diff --git a/src/helpers/getEmbedConfig/index.ts b/src/helpers/getEmbedConfig/index.ts index a52cbe5..22ddf29 100644 --- a/src/helpers/getEmbedConfig/index.ts +++ b/src/helpers/getEmbedConfig/index.ts @@ -1,4 +1,4 @@ -import guildSchema from "../../database/schemas/guild"; +import guildSchema from "../../models/guild"; import * as embedConfig from "../../config/embed"; import { Guild } from "discord.js"; diff --git a/src/index.ts b/src/index.ts index c6179e8..c9c82a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { token, intents } from "./config/discord"; import { Client } from "discord.js"; // discord.js -import database from "./database"; +import * as databaseManager from "./managers/database"; import * as scheduleManager from "./managers/schedule"; import * as eventManager from "./managers/event"; import * as commandManager from "./managers/command"; @@ -16,16 +16,10 @@ const main = async () => { intents, }); - // Start database manager - await database(); - - // Start schedule manager + // Start managers + await databaseManager.start(); await scheduleManager.start(client); - - // Start command handler await commandManager.register(client); - - // Start event handler await eventManager.register(client); // Authorize with Discord's API diff --git a/src/jobs/shopRoles.ts b/src/jobs/shopRoles.ts index c059672..90b8f06 100644 --- a/src/jobs/shopRoles.ts +++ b/src/jobs/shopRoles.ts @@ -4,9 +4,9 @@ import { Client } from "discord.js"; import logger from "../logger"; // Schemas -import userSchema from "../database/schemas/user"; -import shopRoleSchema from "../database/schemas/shopRole"; -import guildSchema from "../database/schemas/guild"; +import userSchema from "../models/user"; +import shopRoleSchema from "../models/shopRole"; +import guildSchema from "../models/guild"; export const options = { schedule: "*/1 * * * * *", diff --git a/src/database/index.ts b/src/managers/database/index.ts similarity index 78% rename from src/database/index.ts rename to src/managers/database/index.ts index 9060935..c16eb73 100644 --- a/src/database/index.ts +++ b/src/managers/database/index.ts @@ -2,12 +2,12 @@ import mongoose from "mongoose"; // Dependencies -import logger from "../logger"; +import logger from "../../logger"; // Configuration -import { url } from "../config/database"; +import { url } from "../../config/database"; -export default async () => { +export const start = async () => { await mongoose.connect(url).then(async (connection) => { logger.info(`Connected to database: ${connection.connection.name}`); }); diff --git a/src/database/schemas/api.ts b/src/models/api.ts similarity index 92% rename from src/database/schemas/api.ts rename to src/models/api.ts index 5a78afd..d3690df 100644 --- a/src/database/schemas/api.ts +++ b/src/models/api.ts @@ -1,6 +1,6 @@ import { Snowflake } from "discord.js"; import { model, Schema } from "mongoose"; -import { IEncryptionData } from "../../interfaces/EncryptionData"; +import { IEncryptionData } from "../interfaces/EncryptionData"; export interface IApi { guildId: Snowflake; diff --git a/src/database/schemas/counter.ts b/src/models/counter.ts similarity index 100% rename from src/database/schemas/counter.ts rename to src/models/counter.ts diff --git a/src/database/schemas/guild.ts b/src/models/guild.ts similarity index 100% rename from src/database/schemas/guild.ts rename to src/models/guild.ts diff --git a/src/database/schemas/shopRole.ts b/src/models/shopRole.ts similarity index 100% rename from src/database/schemas/shopRole.ts rename to src/models/shopRole.ts diff --git a/src/database/schemas/timeout.ts b/src/models/timeout.ts similarity index 100% rename from src/database/schemas/timeout.ts rename to src/models/timeout.ts diff --git a/src/database/schemas/user.ts b/src/models/user.ts similarity index 100% rename from src/database/schemas/user.ts rename to src/models/user.ts From c4a9882a9ee89b4925e6aea70001d8e2cbcf067a Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:42:09 +0200 Subject: [PATCH 30/75] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20shopRole=20job=20?= =?UTF-8?q?is=20now=20running=20evrery=205=20minutes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jobs/shopRoles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jobs/shopRoles.ts b/src/jobs/shopRoles.ts index 90b8f06..e9ed502 100644 --- a/src/jobs/shopRoles.ts +++ b/src/jobs/shopRoles.ts @@ -9,7 +9,7 @@ import shopRoleSchema from "../models/shopRole"; import guildSchema from "../models/guild"; export const options = { - schedule: "*/1 * * * * *", + schedule: "*/5 * * * *", // https://crontab.guru/ }; export const execute = async (client: Client) => { From ed237c8253b40c255b00b8dc3ec62282991e3560 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 17:42:45 +0200 Subject: [PATCH 31/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/managers/schedule/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/schedule/index.ts b/src/managers/schedule/index.ts index 84e77af..e66b349 100644 --- a/src/managers/schedule/index.ts +++ b/src/managers/schedule/index.ts @@ -14,7 +14,7 @@ export const start = async (client: Client) => { if (!jobNames) return logger.info("No jobs found"); await Promise.all( - jobNames.map(async (jobName, index) => { + jobNames.map(async (jobName) => { const job: IJob = await import(`../../jobs/shopRoles`); schedule.scheduleJob(job.options.schedule, async () => { From e6fb636cdbde76dec9e2c43f221adc7f40d6bd79 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 18:25:27 +0200 Subject: [PATCH 32/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20remov?= =?UTF-8?q?e=20unnessecery=20../?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberAdd/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/events/guildMemberAdd/index.ts b/src/events/guildMemberAdd/index.ts index 0dff9bf..156dfb7 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/events/guildMemberAdd/index.ts @@ -5,8 +5,10 @@ import { GuildMember } from "discord.js"; import updatePresence from "../../helpers/updatePresence"; import fetchUser from "../../helpers/fetchUser"; import logger from "../../logger"; -import joinMessage from "../guildMemberAdd/joinMessage"; -import audits from "../guildMemberAdd/audits"; + +import joinMessage from "./joinMessage"; +import audits from "./audits"; + import { IEventOptions } from "../../interfaces/EventOptions"; export const options: IEventOptions = { @@ -16,7 +18,7 @@ export const options: IEventOptions = { export const execute = async (member: GuildMember) => { const { client, user, guild } = member; - logger?.silly( + logger.silly( `New member: ${user.tag} (${user.id}) added to guild: ${guild.name} (${guild.id})` ); From 2a81675c1745e670a62bd92b10590b32fddf0149 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 18:25:50 +0200 Subject: [PATCH 33/75] =?UTF-8?q?=F0=9F=8E=A8=20better=20audit=20log=20fil?= =?UTF-8?q?e=20for=20guildMemberAdd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberAdd/audits.ts | 65 ++++++++++++++++------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/events/guildMemberAdd/audits.ts b/src/events/guildMemberAdd/audits.ts index 5134b14..9c52c04 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/events/guildMemberAdd/audits.ts @@ -7,52 +7,57 @@ import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { - const { footerText, footerIcon, successColor } = await getEmbedConfig( - member.guild - ); + const { client, guild } = member; const guildData = await guildSchema.findOne({ guildId: member.guild.id }); - - const { client } = member; - - if (guildData === null) return; - + if (!guildData) { + throw new Error("Could not find guild"); + } if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) return; + if (!guildData.audits.channelId) { + throw new Error("Channel not found"); + } - const channel = client.channels.cache.get(`${guildData.audits.channelId}`); + const embedConfig = await getEmbedConfig(guild); - if (channel === null) return; + const channel = client.channels.cache.get(guildData.audits.channelId); + if (channel?.type !== "GUILD_TEXT") { + throw new Error("Channel must be a text channel"); + } - (channel as TextChannel) + const embed = new MessageEmbed() + .setTimestamp(new Date()) + .setAuthor({ + name: "Member Joined", + iconURL: + "https://img.icons8.com/color-glass/48/000000/user-male-circle.png", + }) + .setFooter({ + text: embedConfig.footerText, + iconURL: embedConfig.footerIcon, + }); + + await channel .send({ embeds: [ - new MessageEmbed() - .setColor(successColor) - .setAuthor({ - name: "Member Joined", - iconURL: member.user.displayAvatarURL(), - }) - .setDescription(`${member.user} ${member.user.tag}`) + embed + .setColor(embedConfig.successColor) + .setDescription(`${member.user} - (${member.user.tag})`) .addFields([ - { name: "Account Age", value: `${member.user.createdAt}` }, - ]) - .setTimestamp() - .setFooter({ - text: footerText, - iconURL: footerIcon, - }), + { + name: "Account Age", + value: `${member.user.createdAt}`, + }, + ]), ], }) .then(async () => { - logger.info( + logger.debug( `Audit log sent for event guildMemberAdd in guild ${member.guild.name} (${member.guild.id})` ); }) .catch(async () => { - logger.error( - `Audit log failed to send for event guildMemberAdd in guild ${member.guild.name} (${member.guild.id})` - ); + throw new Error("Audit log failed to send"); }); }, }; From 1c722629dc58ed7946d31839ba38e5344d513267 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 18:26:00 +0200 Subject: [PATCH 34/75] =?UTF-8?q?=F0=9F=8E=A8=20better=20audit=20log=20fil?= =?UTF-8?q?e=20for=20guildMemberRemove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberRemove/audits.ts | 64 +++++++++++++++----------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/events/guildMemberRemove/audits.ts b/src/events/guildMemberRemove/audits.ts index 6d1e828..52204f8 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/events/guildMemberRemove/audits.ts @@ -7,49 +7,57 @@ import getEmbedConfig from "../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { - const { footerText, footerIcon, errorColor } = await getEmbedConfig( - member.guild - ); + const { client, guild } = member; const guildData = await guildSchema.findOne({ guildId: member.guild.id }); - - const { client } = member; - - if (guildData === null) return; - + if (!guildData) { + throw new Error("Could not find guild"); + } if (guildData.audits.status !== true) return; - if (!guildData.audits.channelId) return; + if (!guildData.audits.channelId) { + throw new Error("Channel not found"); + } - const channel = client.channels.cache.get(`${guildData.audits.channelId}`); + const embedConfig = await getEmbedConfig(guild); - if (channel === null) return; + const channel = client.channels.cache.get(guildData.audits.channelId); + if (channel?.type !== "GUILD_TEXT") { + throw new Error("Channel must be a text channel"); + } - (channel as TextChannel) + const embed = new MessageEmbed() + .setTimestamp(new Date()) + .setAuthor({ + name: "Member Left", + iconURL: + "https://img.icons8.com/color-glass/48/000000/user-male-circle.png", + }) + .setFooter({ + text: embedConfig.footerText, + iconURL: embedConfig.footerIcon, + }); + + channel .send({ embeds: [ - new MessageEmbed() - .setColor(errorColor) - .setAuthor({ - name: "Member Left", - iconURL: member.user.displayAvatarURL(), - }) - .setDescription(`${member.user} ${member.user.tag}`) - .setTimestamp() - .setFooter({ - text: footerText, - iconURL: footerIcon, - }), + embed + .setColor(embedConfig.errorColor) + .setDescription(`${member.user} - (${member.user.tag})`) + .addFields([ + { + name: "Account Age", + value: `${member.user.createdAt}`, + }, + ]), ], }) .then(async () => { - logger.info( + logger.debug( `Audit log sent for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})` ); }) .catch(async () => { - logger.error( - `Audit log failed to send for event guildMemberRemove in guild ${member.guild.name} (${member.guild.id})` - ); + throw new Error("Audit log failed to send"); }); }, }; From 89b57a367ee7802d7528bfc85f60d3435d00cc31 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 18:28:02 +0200 Subject: [PATCH 35/75] =?UTF-8?q?=F0=9F=9A=9A=20easier=20setup=20for=20con?= =?UTF-8?q?figs=20by=20example=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +--- .../example.database.ts => config_example/database.ts} | 0 src/{config/example.discord.ts => config_example/discord.ts} | 0 src/{config/example.embed.ts => config_example/embed.ts} | 0 .../example.encryption.ts => config_example/encryption.ts} | 0 src/{config/example.other.ts => config_example/other.ts} | 0 .../example.reputation.ts => config_example/reputation.ts} | 0 7 files changed, 1 insertion(+), 3 deletions(-) rename src/{config/example.database.ts => config_example/database.ts} (100%) rename src/{config/example.discord.ts => config_example/discord.ts} (100%) rename src/{config/example.embed.ts => config_example/embed.ts} (100%) rename src/{config/example.encryption.ts => config_example/encryption.ts} (100%) rename src/{config/example.other.ts => config_example/other.ts} (100%) rename src/{config/example.reputation.ts => config_example/reputation.ts} (100%) diff --git a/.gitignore b/.gitignore index 9f176fb..9e1cc15 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,7 @@ config.json package-lock.json -**/config/*.ts -!**/config/index.ts -!**/config/example.*.ts +config/ # Build build/ diff --git a/src/config/example.database.ts b/src/config_example/database.ts similarity index 100% rename from src/config/example.database.ts rename to src/config_example/database.ts diff --git a/src/config/example.discord.ts b/src/config_example/discord.ts similarity index 100% rename from src/config/example.discord.ts rename to src/config_example/discord.ts diff --git a/src/config/example.embed.ts b/src/config_example/embed.ts similarity index 100% rename from src/config/example.embed.ts rename to src/config_example/embed.ts diff --git a/src/config/example.encryption.ts b/src/config_example/encryption.ts similarity index 100% rename from src/config/example.encryption.ts rename to src/config_example/encryption.ts diff --git a/src/config/example.other.ts b/src/config_example/other.ts similarity index 100% rename from src/config/example.other.ts rename to src/config_example/other.ts diff --git a/src/config/example.reputation.ts b/src/config_example/reputation.ts similarity index 100% rename from src/config/example.reputation.ts rename to src/config_example/reputation.ts From b685f3a8d05438ec4615461b396ad50abd82352f Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 18:31:20 +0200 Subject: [PATCH 36/75] =?UTF-8?q?=E2=8F=AA=20iconURL=20is=20now=20bot=20av?= =?UTF-8?q?atar,=20due=20to=20local=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/events/guildMemberAdd/audits.ts | 3 +-- src/events/guildMemberRemove/audits.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/events/guildMemberAdd/audits.ts b/src/events/guildMemberAdd/audits.ts index 9c52c04..f2f3925 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/events/guildMemberAdd/audits.ts @@ -29,8 +29,7 @@ export default { .setTimestamp(new Date()) .setAuthor({ name: "Member Joined", - iconURL: - "https://img.icons8.com/color-glass/48/000000/user-male-circle.png", + iconURL: client.user?.displayAvatarURL(), }) .setFooter({ text: embedConfig.footerText, diff --git a/src/events/guildMemberRemove/audits.ts b/src/events/guildMemberRemove/audits.ts index 52204f8..92c9df8 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/events/guildMemberRemove/audits.ts @@ -29,8 +29,7 @@ export default { .setTimestamp(new Date()) .setAuthor({ name: "Member Left", - iconURL: - "https://img.icons8.com/color-glass/48/000000/user-male-circle.png", + iconURL: client.user?.displayAvatarURL(), }) .setFooter({ text: embedConfig.footerText, From 44eadfc618314aa7be5ead0321608f942d8ed290 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 19:58:45 +0200 Subject: [PATCH 37/75] =?UTF-8?q?=F0=9F=A9=B9=20forgot=20to=20make=20jobs?= =?UTF-8?q?=20dynamic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/managers/schedule/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/schedule/index.ts b/src/managers/schedule/index.ts index e66b349..9fc8aa9 100644 --- a/src/managers/schedule/index.ts +++ b/src/managers/schedule/index.ts @@ -15,7 +15,7 @@ export const start = async (client: Client) => { await Promise.all( jobNames.map(async (jobName) => { - const job: IJob = await import(`../../jobs/shopRoles`); + const job: IJob = await import(`../../jobs/${jobName}`); schedule.scheduleJob(job.options.schedule, async () => { logger.info(`Executed job ${jobName}!`); From cea6be5740a3d63c43c5c930bdaf3417af0cd38e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 20:00:08 +0200 Subject: [PATCH 38/75] =?UTF-8?q?=E2=9C=A8=20metadata=20for=20timeouts=20a?= =?UTF-8?q?nd=20better=20jobs=20#345=20#346?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cspell/custom-dictionary-workspace.txt | 1 + src/commands/fun/modules/meme/index.ts | 2 +- .../interactionCreate/components/isCommand.ts | 73 +++++++++++++++++++ src/helpers/addSeconds/index.ts | 5 ++ src/jobs/timeouts.ts | 35 +++++++++ src/models/timeout.ts | 9 +++ 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/helpers/addSeconds/index.ts create mode 100644 src/jobs/timeouts.ts diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index 92db357..d754312 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -1,5 +1,6 @@ # Custom Dictionary Words Controlpanel +cooldown cpgg dagen discordjs diff --git a/src/commands/fun/modules/meme/index.ts b/src/commands/fun/modules/meme/index.ts index c168557..249d2ee 100644 --- a/src/commands/fun/modules/meme/index.ts +++ b/src/commands/fun/modules/meme/index.ts @@ -5,7 +5,7 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; export default { - metadata: { guildOnly: false, ephemeral: false }, + metadata: { guildOnly: false, ephemeral: false, cooldown: 5 }, builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("meme").setDescription("Get a meme from r/memes)"); diff --git a/src/events/interactionCreate/components/isCommand.ts b/src/events/interactionCreate/components/isCommand.ts index 3addf8b..9ed5868 100644 --- a/src/events/interactionCreate/components/isCommand.ts +++ b/src/events/interactionCreate/components/isCommand.ts @@ -7,6 +7,8 @@ import deferReply from "../../../helpers/deferReply"; import getEmbedConfig from "../../../helpers/getEmbedConfig"; import getCommandMetadata from "../../../helpers/getCommandMetadata"; import capitalizeFirstLetter from "../../../helpers/capitalizeFirstLetter"; +import timeoutSchema from "../../../models/timeout"; +import addSeconds from "../../../helpers/addSeconds"; export default async (interaction: CommandInteraction) => { if (!interaction.isCommand()) return; @@ -45,6 +47,77 @@ export default async (interaction: CommandInteraction) => { }); } + if (metadata.cooldown) { + console.log("cooldown"); + // console.log(interaction); + + // Check if user has a timeout + const isTimeout = await timeoutSchema.findOne({ + guildId: guild.id, + userId: user.id, + cooldown: metadata.cooldown, + timeoutId: interaction.commandId, + }); + + // If user is not on timeout + if (isTimeout) { + logger?.silly(`User is on timeout`); + + const { guildId, userId, timeoutId, cooldown, createdAt } = isTimeout; + + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (overDue) { + timeoutSchema + .deleteOne({ + guildId, + userId, + timeoutId, + cooldown, + }) + .then(async () => { + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + }); + } else { + const diff = Math.round( + ((new Date(isTimeout.createdAt).getTime() - new Date().getTime()) * + -1) / + 1000 + ); + + return interaction?.editReply({ + embeds: [ + { + title: `[:x:] ${capitalizeFirstLetter( + interaction.options.getSubcommand() + )}`, + description: ` + You are currently on timeout, please wait ${diff} seconds. + + If it still doesn't work, please wait for a maximum of **1 hour** before contacting bot owner. + `, + timestamp: new Date(), + color: errorColor, + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + } + } + + await timeoutSchema.create({ + guildId: guild.id, + userId: user.id, + cooldown: metadata.cooldown, + timeoutId: interaction.commandId, + }); + } + if (metadata.guildOnly) { if (!guild) { logger.debug(`Guild is null`); diff --git a/src/helpers/addSeconds/index.ts b/src/helpers/addSeconds/index.ts new file mode 100644 index 0000000..a6836e5 --- /dev/null +++ b/src/helpers/addSeconds/index.ts @@ -0,0 +1,5 @@ +export default async (numOfSeconds: number, date = new Date()) => { + date.setSeconds(date.getSeconds() + numOfSeconds); + + return date; +}; diff --git a/src/jobs/timeouts.ts b/src/jobs/timeouts.ts new file mode 100644 index 0000000..3198772 --- /dev/null +++ b/src/jobs/timeouts.ts @@ -0,0 +1,35 @@ +import logger from "../logger"; + +import timeoutSchema from "../models/timeout"; + +import addSeconds from "../helpers/addSeconds"; + +export const options = { + schedule: "*/30 * * * *", // https://crontab.guru/ +}; + +export const execute = async () => { + const timeouts = await timeoutSchema.find(); + await Promise.all( + timeouts.map(async (timeout) => { + const { guildId, userId, timeoutId, cooldown, createdAt } = timeout; + + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (overDue) { + timeoutSchema + .deleteOne({ + guildId, + userId, + timeoutId, + cooldown, + }) + .then(async () => { + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + }); + } + }) + ); +}; diff --git a/src/models/timeout.ts b/src/models/timeout.ts index f923f08..0e3554c 100644 --- a/src/models/timeout.ts +++ b/src/models/timeout.ts @@ -4,7 +4,10 @@ import { Schema, model } from "mongoose"; export interface ITimeout { userId: Snowflake; guildId: Snowflake; + cooldown: number; timeoutId: string; + createdAt: Date; + updatedAt: Date; } const timeoutSchema = new Schema( @@ -21,6 +24,12 @@ const timeoutSchema = new Schema( unique: false, index: true, }, + cooldown: { + type: Number, + required: true, + unique: false, + index: true, + }, timeoutId: { type: String }, }, { timestamps: true } From 3196e39c70d3192d996d8573bfd6084119496265 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 30 May 2022 20:09:03 +0200 Subject: [PATCH 39/75] =?UTF-8?q?=F0=9F=9A=91=20allow=20dynamic=20timeouts?= =?UTF-8?q?=20to=20work,=20wait=20for=20#348?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/addSeconds/index.ts | 4 +++- src/models/timeout.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helpers/addSeconds/index.ts b/src/helpers/addSeconds/index.ts index a6836e5..6a89447 100644 --- a/src/helpers/addSeconds/index.ts +++ b/src/helpers/addSeconds/index.ts @@ -1,4 +1,6 @@ -export default async (numOfSeconds: number, date = new Date()) => { +export default async (numOfSeconds: number | undefined, date = new Date()) => { + if (!numOfSeconds) throw new Error("numOfSeconds is required"); + date.setSeconds(date.getSeconds() + numOfSeconds); return date; diff --git a/src/models/timeout.ts b/src/models/timeout.ts index 0e3554c..878f498 100644 --- a/src/models/timeout.ts +++ b/src/models/timeout.ts @@ -4,7 +4,7 @@ import { Schema, model } from "mongoose"; export interface ITimeout { userId: Snowflake; guildId: Snowflake; - cooldown: number; + cooldown?: number; timeoutId: string; createdAt: Date; updatedAt: Date; @@ -26,7 +26,7 @@ const timeoutSchema = new Schema( }, cooldown: { type: Number, - required: true, + required: false, unique: false, index: true, }, From e93f6042736b5fc76e279f9cc9cd76a4c8f908ff Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 10 Jun 2022 22:28:07 +0200 Subject: [PATCH 40/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20comma?= =?UTF-8?q?nds=20and=20events=20are=20now=20plugins?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/config/index.ts | 43 ----- src/commands/config/modules/audits/index.ts | 95 ---------- src/commands/config/modules/credits/index.ts | 144 -------------- .../embeds/components/getValues/index.ts | 38 ---- src/commands/config/modules/embeds/index.ts | 104 ---------- src/commands/config/modules/index.ts | 9 - src/commands/config/modules/points/index.ts | 117 ------------ .../config/modules/pterodactyl/index.ts | 78 -------- src/commands/config/modules/shop/index.ts | 97 ---------- src/commands/config/modules/welcome/index.ts | 142 -------------- src/commands/reputation/modules/give.ts | 165 ---------------- src/commands/shop/modules/index.ts | 4 - src/commands/utility/modules/about.ts | 38 ---- src/config_example/other.ts | 2 +- .../interactionCreate/components/isCommand.ts | 178 ------------------ src/events/interactionCreate/index.ts | 23 --- .../messageCreate/modules/credits/index.ts | 85 --------- .../messageCreate/modules/points/index.ts | 89 --------- src/handlers/deployCommands.ts | 6 +- src/helpers/addSeconds/index.ts | 2 +- src/helpers/cooldown/index.ts | 112 +++++++++++ src/helpers/deferReply/index.ts | 2 - src/helpers/listDir/index.ts | 8 +- src/index.ts | 11 +- src/logger/index.ts | 4 +- src/managers/command/index.ts | 21 ++- src/managers/database/index.ts | 11 +- src/managers/event/index.ts | 9 +- src/managers/index.ts | 13 ++ src/models/timeout.ts | 4 +- src/plugins/buttons/primary/index.ts | 7 + src/{ => plugins}/commands/counters/index.ts | 2 +- .../commands/counters/modules/index.ts | 0 .../commands/counters/modules/view/index.ts | 5 +- src/{ => plugins}/commands/credits/index.ts | 2 +- .../commands/credits/modules/balance/index.ts | 7 +- .../commands/credits/modules/gift/index.ts | 7 +- .../commands/credits/modules/index.ts | 0 .../commands/credits/modules/top/index.ts | 7 +- .../commands/credits/modules/work/index.ts | 56 +----- src/{ => plugins}/commands/fun/index.ts | 2 +- .../commands/fun/modules/index.ts | 0 .../commands/fun/modules/meme/index.ts | 4 +- src/{ => plugins}/commands/manage/index.ts | 2 +- .../commands/manage/modules/counters/index.ts | 2 +- .../modules/counters/modules/add/index.ts | 7 +- .../manage/modules/counters/modules/index.ts | 0 .../modules/counters/modules/remove/index.ts | 7 +- .../commands/manage/modules/credits/index.ts | 8 +- .../modules/credits/modules/give/index.ts | 9 +- .../credits/modules/giveaway}/index.ts | 65 ++++--- .../manage/modules/credits/modules/index.ts | 4 +- .../modules/credits/modules/set/index.ts | 7 +- .../modules/credits/modules/take/index.ts | 9 +- .../modules/credits/modules/transfer/index.ts | 7 +- .../commands/manage/modules/index.ts | 0 src/{ => plugins}/commands/profile/index.ts | 2 +- .../commands/profile/modules/index.ts | 0 .../commands/profile/modules/view/index.ts} | 7 +- .../commands/reputation/index.ts | 10 +- .../give/components/noSelfReputation.ts | 6 + .../commands/reputation/modules/give/index.ts | 87 +++++++++ .../commands/reputation/modules/index.ts | 0 src/{ => plugins}/commands/shop/index.ts | 10 +- .../commands/shop/modules/cpgg/index.ts} | 122 ++++++------ src/plugins/commands/shop/modules/index.ts | 4 + .../commands/shop/modules/roles/index.ts | 6 +- .../shop/modules/roles/modules/buy/index.ts} | 13 +- .../modules/roles/modules/cancel/index.ts} | 11 +- .../shop/modules/roles/modules/index.ts | 0 src/{ => plugins}/commands/utility/index.ts | 17 +- .../commands/utility/modules/about/index.ts | 71 +++++++ .../commands/utility/modules/avatar/index.ts} | 3 +- .../commands/utility/modules/index.ts | 0 .../commands/utility/modules/lookup/index.ts} | 5 +- .../commands/utility/modules/stats/index.ts} | 3 +- src/{ => plugins}/events/guildCreate/index.ts | 8 +- src/{ => plugins}/events/guildDelete/index.ts | 8 +- .../events/guildMemberAdd/audits.ts | 6 +- .../events/guildMemberAdd/index.ts | 8 +- .../events/guildMemberAdd/joinMessage.ts | 4 +- .../events/guildMemberRemove/audits.ts | 6 +- .../events/guildMemberRemove/index.ts | 8 +- .../events/guildMemberRemove/leaveMessage.ts | 4 +- .../events/interactionCreate/audits.ts | 10 +- .../interactionCreate/components/checks.ts | 51 +++++ .../interactionCreate/components/isButton.ts | 123 ++++++++++++ .../interactionCreate/components/isCommand.ts | 48 +++++ src/plugins/events/interactionCreate/index.ts | 51 +++++ .../events/messageCreate/index.ts | 2 +- .../messageCreate/modules/counters/index.ts | 4 +- .../messageCreate/modules/credits/index.ts | 46 +++++ .../events/messageCreate/modules/index.ts | 0 .../messageCreate/modules/points/index.ts | 51 +++++ .../events/messageDelete/audits.ts | 6 +- .../events/messageDelete/index.ts | 2 +- .../events/messageDelete/modules/counter.ts | 4 +- .../events/messageUpdate/audits.ts | 6 +- .../events/messageUpdate/index.ts | 6 +- .../events/messageUpdate/modules/counter.ts | 4 +- src/plugins/events/rateLimit/index.ts | 14 ++ src/{ => plugins}/events/ready/index.ts | 10 +- tsconfig.json | 16 +- 103 files changed, 977 insertions(+), 1786 deletions(-) delete mode 100644 src/commands/config/index.ts delete mode 100644 src/commands/config/modules/audits/index.ts delete mode 100644 src/commands/config/modules/credits/index.ts delete mode 100644 src/commands/config/modules/embeds/components/getValues/index.ts delete mode 100644 src/commands/config/modules/embeds/index.ts delete mode 100644 src/commands/config/modules/index.ts delete mode 100644 src/commands/config/modules/points/index.ts delete mode 100644 src/commands/config/modules/pterodactyl/index.ts delete mode 100644 src/commands/config/modules/shop/index.ts delete mode 100644 src/commands/config/modules/welcome/index.ts delete mode 100644 src/commands/reputation/modules/give.ts delete mode 100644 src/commands/shop/modules/index.ts delete mode 100644 src/commands/utility/modules/about.ts delete mode 100644 src/events/interactionCreate/components/isCommand.ts delete mode 100644 src/events/interactionCreate/index.ts delete mode 100644 src/events/messageCreate/modules/credits/index.ts delete mode 100644 src/events/messageCreate/modules/points/index.ts create mode 100644 src/helpers/cooldown/index.ts create mode 100644 src/managers/index.ts create mode 100644 src/plugins/buttons/primary/index.ts rename src/{ => plugins}/commands/counters/index.ts (93%) rename src/{ => plugins}/commands/counters/modules/index.ts (100%) rename src/{ => plugins}/commands/counters/modules/view/index.ts (91%) rename src/{ => plugins}/commands/credits/index.ts (96%) rename src/{ => plugins}/commands/credits/modules/balance/index.ts (91%) rename src/{ => plugins}/commands/credits/modules/gift/index.ts (96%) rename src/{ => plugins}/commands/credits/modules/index.ts (100%) rename src/{ => plugins}/commands/credits/modules/top/index.ts (88%) rename src/{ => plugins}/commands/credits/modules/work/index.ts (50%) rename src/{ => plugins}/commands/fun/index.ts (94%) rename src/{ => plugins}/commands/fun/modules/index.ts (100%) rename src/{ => plugins}/commands/fun/modules/meme/index.ts (92%) rename src/{ => plugins}/commands/manage/index.ts (95%) rename src/{ => plugins}/commands/manage/modules/counters/index.ts (95%) rename src/{ => plugins}/commands/manage/modules/counters/modules/add/index.ts (91%) rename src/{ => plugins}/commands/manage/modules/counters/modules/index.ts (100%) rename src/{ => plugins}/commands/manage/modules/counters/modules/remove/index.ts (91%) rename src/{ => plugins}/commands/manage/modules/credits/index.ts (84%) rename src/{ => plugins}/commands/manage/modules/credits/modules/give/index.ts (94%) rename src/{commands/manage/modules/credits/modules/drop => plugins/commands/manage/modules/credits/modules/giveaway}/index.ts (61%) rename src/{ => plugins}/commands/manage/modules/credits/modules/index.ts (55%) rename src/{ => plugins}/commands/manage/modules/credits/modules/set/index.ts (95%) rename src/{ => plugins}/commands/manage/modules/credits/modules/take/index.ts (94%) rename src/{ => plugins}/commands/manage/modules/credits/modules/transfer/index.ts (97%) rename src/{ => plugins}/commands/manage/modules/index.ts (100%) rename src/{ => plugins}/commands/profile/index.ts (94%) rename src/{ => plugins}/commands/profile/modules/index.ts (100%) rename src/{commands/profile/modules/view.ts => plugins/commands/profile/modules/view/index.ts} (92%) rename src/{ => plugins}/commands/reputation/index.ts (71%) create mode 100644 src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts create mode 100644 src/plugins/commands/reputation/modules/give/index.ts rename src/{ => plugins}/commands/reputation/modules/index.ts (100%) rename src/{ => plugins}/commands/shop/index.ts (74%) rename src/{commands/shop/modules/pterodactyl.ts => plugins/commands/shop/modules/cpgg/index.ts} (65%) create mode 100644 src/plugins/commands/shop/modules/index.ts rename src/{ => plugins}/commands/shop/modules/roles/index.ts (89%) rename src/{commands/shop/modules/roles/modules/buy.ts => plugins/commands/shop/modules/roles/modules/buy/index.ts} (90%) rename src/{commands/shop/modules/roles/modules/cancel.ts => plugins/commands/shop/modules/roles/modules/cancel/index.ts} (89%) rename src/{ => plugins}/commands/shop/modules/roles/modules/index.ts (100%) rename src/{ => plugins}/commands/utility/index.ts (73%) create mode 100644 src/plugins/commands/utility/modules/about/index.ts rename src/{commands/utility/modules/avatar.ts => plugins/commands/utility/modules/avatar/index.ts} (91%) rename src/{ => plugins}/commands/utility/modules/index.ts (100%) rename src/{commands/utility/modules/lookup.ts => plugins/commands/utility/modules/lookup/index.ts} (95%) rename src/{commands/utility/modules/stats.ts => plugins/commands/utility/modules/stats/index.ts} (95%) rename src/{ => plugins}/events/guildCreate/index.ts (60%) rename src/{ => plugins}/events/guildDelete/index.ts (64%) rename src/{ => plugins}/events/guildMemberAdd/audits.ts (91%) rename src/{ => plugins}/events/guildMemberAdd/index.ts (72%) rename src/{ => plugins}/events/guildMemberAdd/joinMessage.ts (91%) rename src/{ => plugins}/events/guildMemberRemove/audits.ts (91%) rename src/{ => plugins}/events/guildMemberRemove/index.ts (72%) rename src/{ => plugins}/events/guildMemberRemove/leaveMessage.ts (91%) rename src/{ => plugins}/events/interactionCreate/audits.ts (84%) create mode 100644 src/plugins/events/interactionCreate/components/checks.ts create mode 100644 src/plugins/events/interactionCreate/components/isButton.ts create mode 100644 src/plugins/events/interactionCreate/components/isCommand.ts create mode 100644 src/plugins/events/interactionCreate/index.ts rename src/{ => plugins}/events/messageCreate/index.ts (83%) rename src/{ => plugins}/events/messageCreate/modules/counters/index.ts (94%) create mode 100644 src/plugins/events/messageCreate/modules/credits/index.ts rename src/{ => plugins}/events/messageCreate/modules/index.ts (100%) create mode 100644 src/plugins/events/messageCreate/modules/points/index.ts rename src/{ => plugins}/events/messageDelete/audits.ts (91%) rename src/{ => plugins}/events/messageDelete/index.ts (82%) rename src/{ => plugins}/events/messageDelete/modules/counter.ts (90%) rename src/{ => plugins}/events/messageUpdate/audits.ts (92%) rename src/{ => plugins}/events/messageUpdate/index.ts (78%) rename src/{ => plugins}/events/messageUpdate/modules/counter.ts (89%) create mode 100644 src/plugins/events/rateLimit/index.ts rename src/{ => plugins}/events/ready/index.ts (53%) diff --git a/src/commands/config/index.ts b/src/commands/config/index.ts deleted file mode 100644 index 4110d5c..0000000 --- a/src/commands/config/index.ts +++ /dev/null @@ -1,43 +0,0 @@ -// Dependencies -import { SlashCommandBuilder } from "@discordjs/builders"; -import { CommandInteraction } from "discord.js"; - -// Modules -import modules from "./modules"; - -// Handlers -import logger from "../../logger"; - -export const builder = new SlashCommandBuilder() - .setName("config") - .setDescription("Manage guild configurations.") - - .addSubcommand(modules.pterodactyl.builder) - .addSubcommand(modules.credits.builder) - .addSubcommand(modules.points.builder) - .addSubcommand(modules.welcome.builder) - .addSubcommand(modules.audits.builder) - .addSubcommand(modules.shop.builder) - .addSubcommand(modules.embeds.builder); - -export const moduleData = modules; - -// Function -export const execute = async (interaction: CommandInteraction) => { - switch (interaction.options?.getSubcommand()) { - case "pterodactyl": - return modules.pterodactyl.execute(interaction); - case "credits": - return modules.credits.execute(interaction); - case "points": - return modules.points.execute(interaction); - case "welcome": - return modules.welcome.execute(interaction); - case "audits": - return modules.audits.execute(interaction); - case "shop": - return modules.shop.execute(interaction); - case "embeds": - return modules.embeds.execute(interaction); - } -}; diff --git a/src/commands/config/modules/audits/index.ts b/src/commands/config/modules/audits/index.ts deleted file mode 100644 index 6d85a15..0000000 --- a/src/commands/config/modules/audits/index.ts +++ /dev/null @@ -1,95 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { ChannelType } from "discord-api-types/v10"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("audits") - .setDescription("Audits") - .addBooleanOption((option) => - option.setName("status").setDescription("Should audits be enabled?") - ) - .addChannelOption((option) => - option - .setName("channel") - .setDescription("Channel for audit messages.") - .addChannelTypes(ChannelType.GuildText) - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - - const { guild, options } = interaction; - - // Get options - const status = options?.getBoolean("status"); - const channel = options?.getChannel("channel"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild not found in database.`); - } - - // Modify values - guildDB.audits.status = status !== null ? status : guildDB?.audits?.status; - guildDB.audits.channelId = - channel !== null ? channel.id : guildDB?.audits?.channelId; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild audits updated.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":hammer: Settings - Guild [Audits]", - description: `Audits settings updated.`, - color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.audits?.status}`, - inline: true, - }, - { - name: "🌊 Channel", - value: `${guildDB?.audits?.channelId}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/config/modules/credits/index.ts b/src/commands/config/modules/credits/index.ts deleted file mode 100644 index 20df392..0000000 --- a/src/commands/config/modules/credits/index.ts +++ /dev/null @@ -1,144 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -//Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("credits") - .setDescription(`Credits`) - .addBooleanOption((option) => - option.setName("status").setDescription("Should credits be enabled?") - ) - .addNumberOption((option) => - option.setName("rate").setDescription("Amount of credits per message.") - ) - .addNumberOption((option) => - option - .setName("minimum-length") - .setDescription("Minimum length of message to earn credits.") - ) - .addNumberOption((option) => - option - .setName("work-rate") - .setDescription("Maximum amount of credits on work.") - ) - .addNumberOption((option) => - option - .setName("work-timeout") - .setDescription("Timeout between work schedules (seconds).") - ) - .addNumberOption((option) => - option - .setName("timeout") - .setDescription("Timeout between earning credits (seconds).") - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); // Destructure member - const { guild, options } = interaction; - - if (guild == null) return; - - // Get options - const status = options?.getBoolean("status"); - const rate = options?.getNumber("rate"); - const timeout = options?.getNumber("timeout"); - const minimumLength = options?.getNumber("minimum-length"); - const workRate = options?.getNumber("work-rate"); - const workTimeout = options?.getNumber("work-timeout"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild is null`); - } - - // Modify values - guildDB.credits.status = - status !== null ? status : guildDB?.credits?.status; - guildDB.credits.rate = rate !== null ? rate : guildDB?.credits?.rate; - guildDB.credits.timeout = - timeout !== null ? timeout : guildDB?.credits?.timeout; - guildDB.credits.workRate = - workRate !== null ? workRate : guildDB?.credits?.workRate; - guildDB.credits.workTimeout = - workTimeout !== null ? workTimeout : guildDB?.credits?.workTimeout; - guildDB.credits.minimumLength = - minimumLength !== null ? minimumLength : guildDB?.credits?.minimumLength; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild saved`); - - return interaction?.editReply({ - embeds: [ - { - title: ":tools: Settings - Guild [Credits]", - description: `Credits settings updated.`, - color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.credits?.status}`, - inline: true, - }, - { - name: "📈 Rate", - value: `${guildDB?.credits?.rate}`, - inline: true, - }, - { - name: "📈 Work Rate", - value: `${guildDB?.credits?.workRate}`, - inline: true, - }, - { - name: "🔨 Minimum Length", - value: `${guildDB?.credits?.minimumLength}`, - inline: true, - }, - { - name: "⏰ Timeout", - value: `${guildDB?.credits?.timeout}`, - inline: true, - }, - { - name: "⏰ Work Timeout", - value: `${guildDB?.credits?.workTimeout}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/config/modules/embeds/components/getValues/index.ts b/src/commands/config/modules/embeds/components/getValues/index.ts deleted file mode 100644 index 38702e2..0000000 --- a/src/commands/config/modules/embeds/components/getValues/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ColorResolvable, CommandInteraction } from "discord.js"; -import guildSchema from "../../../../../../models/guild"; -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; - -export default async (interaction: CommandInteraction) => { - const { options, guild } = interaction; - - if (!guild) throw new Error("Guild not found"); - - const embedConfig = await getEmbedConfig(guild); - if (!embedConfig) throw new Error("Embed config not found"); - - // Get new values - const newSuccessColor = options.getString("success-color") as ColorResolvable; - const newWaitColor = options.getString("wait-color") as ColorResolvable; - const newErrorColor = options.getString("error-color") as ColorResolvable; - const newFooterIcon = options.getString("footer-icon"); - const newFooterText = options.getString("footer-text"); - - // Get guild values - const guildData = await guildSchema.findOne({ - guildId: guild.id, - }); - if (!guildData) throw new Error("Guild data not found"); - if (!guildData?.embeds) - throw new Error("Guild embed configuration not found"); - let { successColor, waitColor, errorColor, footerText, footerIcon } = - guildData.embeds; - - // Set new values - successColor = newSuccessColor || successColor; - waitColor = newWaitColor || waitColor; - errorColor = newErrorColor || errorColor; - footerIcon = newFooterIcon || footerIcon; - footerText = newFooterText || footerText; - - return { successColor, waitColor, errorColor, footerText, footerIcon }; -}; diff --git a/src/commands/config/modules/embeds/index.ts b/src/commands/config/modules/embeds/index.ts deleted file mode 100644 index 218bb26..0000000 --- a/src/commands/config/modules/embeds/index.ts +++ /dev/null @@ -1,104 +0,0 @@ -// Dependencies -import { - ColorResolvable, - CommandInteraction, - MessageEmbed, - Permissions, -} from "discord.js"; - -//Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; -import getValues from "./components/getValues"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("embeds") - .setDescription(`Embeds`) - .addStringOption((option) => - option - .setName("success-color") - .setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("wait-color").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("error-color").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("footer-icon").setDescription("No provided description") - ) - .addStringOption((option) => - option.setName("footer-text").setDescription("No provided description") - ); - }, - execute: async (interaction: CommandInteraction) => { - const { guild } = interaction; - if (!guild) throw new Error("Guild not found"); - - const { successColor, waitColor, errorColor, footerText, footerIcon } = - await getValues(interaction); - - // Initialize embed object - const embed = new MessageEmbed() - .setTitle("[:tools:] Embeds") - .setFooter({ text: footerText, iconURL: footerIcon }) - .setTimestamp(new Date()); - - // Get guild values - const guildData = await guildSchema.findOne({ - guildId: guild.id, - }); - if (!guildData) throw new Error("Guild data not found"); - - await guildData.save().then(async () => { - embed - .setDescription("Following embed configuration will be used.") - .setColor(successColor) - .addFields([ - { - name: "🟢 Success Color", - value: `${successColor}`, - inline: true, - }, - { - name: "🟡 Wait Color", - value: `${waitColor}`, - inline: true, - }, - { - name: "🔴 Error Color", - value: `${errorColor}`, - inline: true, - }, - { - name: "🖼️ Footer Icon", - value: `${footerIcon}`, - inline: true, - }, - { - name: "📄 Footer Text", - value: `${footerText}`, - inline: true, - }, - ]); - - return interaction.editReply({ - embeds: [embed], - }); - }); - }, -}; diff --git a/src/commands/config/modules/index.ts b/src/commands/config/modules/index.ts deleted file mode 100644 index 09a9f5a..0000000 --- a/src/commands/config/modules/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import audits from "./audits"; -import credits from "./credits"; -import points from "./points"; -import pterodactyl from "./pterodactyl"; -import shop from "./shop"; -import welcome from "./welcome"; -import embeds from "./embeds"; - -export default { audits, credits, points, pterodactyl, shop, welcome, embeds }; diff --git a/src/commands/config/modules/points/index.ts b/src/commands/config/modules/points/index.ts deleted file mode 100644 index 6683df7..0000000 --- a/src/commands/config/modules/points/index.ts +++ /dev/null @@ -1,117 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("points") - .setDescription("Points") - .addBooleanOption((option) => - option.setName("status").setDescription("Should credits be enabled?") - ) - .addNumberOption((option) => - option.setName("rate").setDescription("Amount of credits per message.") - ) - .addNumberOption((option) => - option - .setName("minimum-length") - .setDescription("Minimum length of message to earn credits.") - ) - .addNumberOption((option) => - option - .setName("timeout") - .setDescription("Timeout between earning credits (milliseconds).") - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - - // Destructure member - const { options, guild } = interaction; - - // Get options - const status = options?.getBoolean("status"); - const rate = options?.getNumber("rate"); - const timeout = options?.getNumber("timeout"); - const minimumLength = options?.getNumber("minimum-length"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild not found in database.`); - } - - // Modify values - guildDB.points.status = status !== null ? status : guildDB?.points?.status; - guildDB.points.rate = rate !== null ? rate : guildDB?.points?.rate; - guildDB.points.timeout = - timeout !== null ? timeout : guildDB?.points?.timeout; - guildDB.points.minimumLength = - minimumLength !== null ? minimumLength : guildDB?.points?.minimumLength; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild points updated.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":hammer: Settings - Guild [Points]", - description: `Points settings updated.`, - color: successColor, - fields: [ - { - name: "🤖 Status", - value: `${guildDB?.points?.status}`, - inline: true, - }, - { - name: "📈 Rate", - value: `${guildDB?.points?.rate}`, - inline: true, - }, - { - name: "🔨 Minimum Length", - value: `${guildDB?.points?.minimumLength}`, - inline: true, - }, - { - name: "⏰ Timeout", - value: `${guildDB?.points?.timeout}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/config/modules/pterodactyl/index.ts b/src/commands/config/modules/pterodactyl/index.ts deleted file mode 100644 index c73189a..0000000 --- a/src/commands/config/modules/pterodactyl/index.ts +++ /dev/null @@ -1,78 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import apiSchema from "../../../../models/api"; -import encryption from "../../../../handlers/encryption"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("pterodactyl") - .setDescription("Controlpanel.gg") - .addStringOption((option) => - option - .setName("url") - .setDescription(`Controlpanel.gg URL`) - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("token") - .setDescription(`Controlpanel.gg Token`) - .setRequired(true) - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); // Destructure member - const { options, guild } = interaction; - - // Get options - const tokenData = options.getString("token"); - const url = options.getString("url"); - const token = tokenData && encryption.encrypt(tokenData); - - // Update API credentials - await apiSchema - ?.findOneAndUpdate( - { guildId: guild?.id }, - { url, token }, - { new: true, upsert: true } - ) - .then(async () => { - logger?.silly(`Updated API credentials.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":hammer: Settings - Guild [Pterodactyl]", - color: successColor, - description: `Successfully updated API credentials.`, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/config/modules/shop/index.ts b/src/commands/config/modules/shop/index.ts deleted file mode 100644 index fc4f467..0000000 --- a/src/commands/config/modules/shop/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("shop") - .setDescription("Shop") - .addBooleanOption((option) => - option - .setName("roles-status") - .setDescription("Should roles be enabled?") - ) - .addNumberOption((option) => - option - .setName("roles-price-per-hour") - .setDescription("Price per hour for roles.") - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); // Destructure member - const { options, guild } = interaction; - - // Get options - const rolesStatus = options?.getBoolean("roles-status"); - const rolesPricePerHour = options?.getNumber("roles-price-per-hour"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild not found in database.`); - } - - // Modify values - guildDB.shop.roles.status = - rolesStatus !== null ? rolesStatus : guildDB?.shop?.roles?.status; - guildDB.shop.roles.pricePerHour = - rolesPricePerHour !== null - ? rolesPricePerHour - : guildDB?.shop?.roles?.pricePerHour; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild shop updated.`); - - return interaction?.editReply({ - embeds: [ - { - title: ":hammer: Settings - Guild [Shop]", - description: `Shop settings updated.`, - color: successColor, - fields: [ - { - name: "🤖 Roles Status", - value: `${guildDB?.shop?.roles.status}`, - inline: true, - }, - { - name: "🌊 Roles Price Per Hour", - value: `${guildDB?.shop?.roles.pricePerHour}`, - inline: true, - }, - ], - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/config/modules/welcome/index.ts b/src/commands/config/modules/welcome/index.ts deleted file mode 100644 index 8405aeb..0000000 --- a/src/commands/config/modules/welcome/index.ts +++ /dev/null @@ -1,142 +0,0 @@ -// Dependencies -import { CommandInteraction, Permissions } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; - -// Handlers -import logger from "../../../../logger"; - -// Models -import guildSchema from "../../../../models/guild"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { ChannelType } from "discord-api-types/v10"; - -// Function -export default { - metadata: { - guildOnly: true, - ephemeral: true, - permissions: [Permissions.FLAGS.MANAGE_GUILD], - }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("welcome") - .setDescription("Welcome") - .addBooleanOption((option) => - option.setName("status").setDescription("Should welcome be enabled?") - ) - .addChannelOption((option) => - option - .setName("join-channel") - .setDescription("Channel for join messages.") - .addChannelTypes(ChannelType.GuildText) - ) - - .addChannelOption((option) => - option - .setName("leave-channel") - .setDescription("Channel for leave messages.") - .addChannelTypes(ChannelType.GuildText) - ) - - .addStringOption((option) => - option - .setName("leave-message") - .setDescription("Message for leave messages.") - ) - .addStringOption((option) => - option - .setName("join-message") - .setDescription("Message for join messages.") - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); // Destructure member - const { options, guild } = interaction; - - // Get options - const status = options?.getBoolean("status"); - const joinChannel = options?.getChannel("join-channel"); - const leaveChannel = options?.getChannel("leave-channel"); - const joinChannelMessage = options?.getString("join-message"); - const leaveChannelMessage = options?.getString("leave-message"); - - // Get guild object - const guildDB = await guildSchema?.findOne({ - guildId: guild?.id, - }); - - if (guildDB === null) { - return logger?.silly(`Guild not found in database.`); - } - - // Modify values - guildDB.welcome.status = - status !== null ? status : guildDB?.welcome?.status; - guildDB.welcome.joinChannel = - joinChannel !== null ? joinChannel.id : guildDB?.welcome?.joinChannel; - guildDB.welcome.leaveChannel = - leaveChannel !== null ? leaveChannel.id : guildDB?.welcome?.leaveChannel; - - guildDB.welcome.joinChannelMessage = - joinChannelMessage !== null - ? joinChannelMessage - : guildDB?.welcome?.joinChannelMessage; - guildDB.welcome.leaveChannelMessage = - leaveChannelMessage !== null - ? leaveChannelMessage - : guildDB?.welcome?.leaveChannelMessage; - - // Save guild - await guildDB?.save()?.then(async () => { - logger?.silly(`Guild welcome updated.`); - - if (!guildDB?.welcome?.status) { - return interaction?.editReply({ - embeds: [ - { - title: "[:tools:] Welcome", - description: `This module is currently disabled, please enable it to continue.`, - color: successColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - - return interaction?.editReply({ - embeds: [ - { - title: "[:tools:] Welcome", - description: `The following configuration will be used. - - [👋] **Welcome** - - ㅤ**Channel**: <#${guildDB?.welcome?.joinChannel}> - ㅤ**Message**: ${guildDB?.welcome?.joinChannelMessage} - - [🚪] **Leave** - - ㅤ**Channel**: <#${guildDB?.welcome?.leaveChannel}> - ㅤ**Message**: ${guildDB?.welcome?.leaveChannelMessage}`, - color: successColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - }, -}; diff --git a/src/commands/reputation/modules/give.ts b/src/commands/reputation/modules/give.ts deleted file mode 100644 index 8e7d980..0000000 --- a/src/commands/reputation/modules/give.ts +++ /dev/null @@ -1,165 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../helpers/getEmbedConfig"; - -import { timeout } from "../../../config/reputation"; - -// Handlers -import logger from "../../../logger"; - -// Models -import timeoutSchema from "../../../models/timeout"; -import fetchUser from "../../../helpers/fetchUser"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { guildOnly: true, ephemeral: true }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("give") - .setDescription("Give reputation to a user") - .addUserOption((option) => - option - .setName("target") - .setDescription("The user you want to repute.") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("type") - .setDescription("What type of reputation you want to repute") - .setRequired(true) - .addChoices( - { name: "Positive", value: "positive" }, - { - name: "Negative", - value: "negative", - } - ) - ); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(interaction.guild); // Destructure - const { options, user, guild } = interaction; - - // Target option - const optionTarget = options?.getUser("target"); - - // Type information - const optionType = options?.getString("type"); - - if (guild === null) { - return logger?.silly(`Guild is null`); - } - - // User information - const userObj = await fetchUser(user, guild); - - if (userObj === null) { - return logger?.silly(`User is null`); - } - - // Check if user has a timeout - const isTimeout = await timeoutSchema?.findOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-04-10-16-42", - }); - - // If user is not on timeout - if (isTimeout) { - logger?.silly(`User is on timeout`); - - return interaction?.editReply({ - embeds: [ - { - title: ":loudspeaker: Reputation [Give]", - description: `You cannot give reputation while on timeout, please wait ${timeout} seconds.`, - timestamp: new Date(), - color: errorColor, - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - - // Do not allow self reputation - if (optionTarget?.id === user?.id) { - logger?.silly(`User is trying to give reputation to self`); - - return interaction?.editReply({ - embeds: [ - { - title: ":loudspeaker: Reputation [Give]", - description: `You cannot give reputation to yourself.`, - timestamp: new Date(), - color: errorColor, - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - - // If type is positive - if (optionType === "positive") { - logger?.silly(`User is giving positive reputation`); - - userObj.reputation += 1; - } - - // If type is negative - else if (optionType === "negative") { - logger?.silly(`User is giving negative reputation`); - - userObj.reputation -= 1; - } - - // Save user - await userObj?.save()?.then(async () => { - logger?.silly(`User reputation has been updated`); - - await timeoutSchema?.create({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-04-10-16-42", - }); - - return interaction?.editReply({ - embeds: [ - { - title: ":loudspeaker: Reputation [Give]", - description: `You have given reputation to ${optionTarget}`, - timestamp: new Date(), - color: successColor, - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - }); - - setTimeout(async () => { - logger?.silly(`Removing timeout`); - - await timeoutSchema?.deleteOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-04-10-16-42", - }); - }, timeout); - }, -}; diff --git a/src/commands/shop/modules/index.ts b/src/commands/shop/modules/index.ts deleted file mode 100644 index d191ec6..0000000 --- a/src/commands/shop/modules/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import pterodactyl from "./pterodactyl"; -import * as roles from "./roles"; - -export default { pterodactyl, roles }; diff --git a/src/commands/utility/modules/about.ts b/src/commands/utility/modules/about.ts deleted file mode 100644 index 18eca4c..0000000 --- a/src/commands/utility/modules/about.ts +++ /dev/null @@ -1,38 +0,0 @@ -// Dependencies -import { CommandInteraction } from "discord.js"; - -// Configurations -import getEmbedConfig from "../../../helpers/getEmbedConfig"; - -import { hosterName, hosterUrl } from "../../../config/other"; -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -// Function -export default { - metadata: { guildOnly: false, ephemeral: false }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command.setName("about").setDescription("About this bot!)"); - }, - execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { successColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - const interactionEmbed = { - title: ":hammer: Utilities [About]", - description: `This bot is hosted by ${ - hosterUrl ? `[${hosterName}](${hosterUrl})` : `${hosterName}` - }, the bot is developed by [Zyner](https://github.com/ZynerOrg)! - - If you are interested in contributing, then just [fork it](https://github.com/ZynerOrg/xyter) yourself, we :heart: Open Source.`, - color: successColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }; - interaction?.editReply({ embeds: [interactionEmbed] }); - }, -}; diff --git a/src/config_example/other.ts b/src/config_example/other.ts index 1695d42..eefd62c 100644 --- a/src/config_example/other.ts +++ b/src/config_example/other.ts @@ -8,7 +8,7 @@ export const guildId = ""; export const hosterName = "someone"; // Hoster Url -export const hosterUrl = "scheme://domain.tld"; +export const hosterUrl = "https://xyter.zyner.org/customization/change-hoster"; // Winston log level export const logLevel = "info"; diff --git a/src/events/interactionCreate/components/isCommand.ts b/src/events/interactionCreate/components/isCommand.ts deleted file mode 100644 index 9ed5868..0000000 --- a/src/events/interactionCreate/components/isCommand.ts +++ /dev/null @@ -1,178 +0,0 @@ -// Dependencies -import { CommandInteraction, MessageEmbed } from "discord.js"; - -import logger from "../../../logger"; - -import deferReply from "../../../helpers/deferReply"; -import getEmbedConfig from "../../../helpers/getEmbedConfig"; -import getCommandMetadata from "../../../helpers/getCommandMetadata"; -import capitalizeFirstLetter from "../../../helpers/capitalizeFirstLetter"; -import timeoutSchema from "../../../models/timeout"; -import addSeconds from "../../../helpers/addSeconds"; - -export default async (interaction: CommandInteraction) => { - if (!interaction.isCommand()) return; - if (interaction.guild == null) return; - - const { errorColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - - const { client, guild, commandName, user, memberPermissions } = interaction; - - const currentCommand = client.commands.get(commandName); - - if (currentCommand == null) { - logger.silly(`Command ${commandName} not found`); - } - - const metadata = await getCommandMetadata(interaction, currentCommand); - - await deferReply(interaction, metadata.ephemeral || false); - - if ( - metadata.permissions && - metadata.guildOnly && - !memberPermissions?.has(metadata.permissions) - ) { - return interaction?.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription(`You do not have the permission to manage the bot.`) - .setTimestamp(new Date()) - .setColor(errorColor) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - - if (metadata.cooldown) { - console.log("cooldown"); - // console.log(interaction); - - // Check if user has a timeout - const isTimeout = await timeoutSchema.findOne({ - guildId: guild.id, - userId: user.id, - cooldown: metadata.cooldown, - timeoutId: interaction.commandId, - }); - - // If user is not on timeout - if (isTimeout) { - logger?.silly(`User is on timeout`); - - const { guildId, userId, timeoutId, cooldown, createdAt } = isTimeout; - - const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); - - if (overDue) { - timeoutSchema - .deleteOne({ - guildId, - userId, - timeoutId, - cooldown, - }) - .then(async () => { - logger.debug( - `Timeout document ${timeoutId} has been deleted from user ${userId}.` - ); - }); - } else { - const diff = Math.round( - ((new Date(isTimeout.createdAt).getTime() - new Date().getTime()) * - -1) / - 1000 - ); - - return interaction?.editReply({ - embeds: [ - { - title: `[:x:] ${capitalizeFirstLetter( - interaction.options.getSubcommand() - )}`, - description: ` - You are currently on timeout, please wait ${diff} seconds. - - If it still doesn't work, please wait for a maximum of **1 hour** before contacting bot owner. - `, - timestamp: new Date(), - color: errorColor, - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - } - } - - await timeoutSchema.create({ - guildId: guild.id, - userId: user.id, - cooldown: metadata.cooldown, - timeoutId: interaction.commandId, - }); - } - - if (metadata.guildOnly) { - if (!guild) { - logger.debug(`Guild is null`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setDescription("This command is only available for guild") - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - } - - if (metadata.dmOnly) { - if (guild) { - logger.silly(`Guild exist`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setDescription("This command is only available in DM.") - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - } - - await currentCommand - .execute(interaction) - .then(async () => { - return logger?.silly( - `Command: ${commandName} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})` - ); - }) - .catch(async (error: string) => { - logger?.error(`${error}`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setTitle( - `[:x:] ${capitalizeFirstLetter( - interaction.options.getSubcommand() - )}` - ) - .setDescription(`${"``"}${error}${"``"}`) - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - }); -}; diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts deleted file mode 100644 index 7e173dc..0000000 --- a/src/events/interactionCreate/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// 3rd party dependencies -import { CommandInteraction } from "discord.js"; - -// Dependencies -import isCommand from "../../events/interactionCreate/components/isCommand"; -import logger from "../../logger"; -import audits from "./audits"; -import { IEventOptions } from "../../interfaces/EventOptions"; - -export const options: IEventOptions = { - type: "on", -}; - -export const execute = async (interaction: CommandInteraction) => { - const { guild, id } = interaction; - - logger?.silly( - `New interaction: ${id} in guild: ${guild?.name} (${guild?.id})` - ); - - await audits.execute(interaction); - await isCommand(interaction); -}; diff --git a/src/events/messageCreate/modules/credits/index.ts b/src/events/messageCreate/modules/credits/index.ts deleted file mode 100644 index ce96c4a..0000000 --- a/src/events/messageCreate/modules/credits/index.ts +++ /dev/null @@ -1,85 +0,0 @@ -import logger from "../../../../logger"; -import timeouts from "../../../../models/timeout"; -import { Message } from "discord.js"; - -import fetchUser from "../../../../helpers/fetchUser"; -import fetchGuild from "../../../../helpers/fetchGuild"; - -export default { - execute: async (message: Message) => { - const { guild, author, content, channel } = message; - - if (guild == null) return; - if (author.bot) return; - if (channel?.type !== "GUILD_TEXT") return; - - const { id: guildId } = guild; - const { id: userId } = author; - - const guildData = await fetchGuild(guild); - const userData = await fetchUser(author, guild); - - if (content.length < guildData.credits.minimumLength) return; - - const timeoutData = { - guildId, - userId, - timeoutId: "2022-04-14-13-51-00", - }; - - const timeout = await timeouts.findOne(timeoutData); - - if (timeout) { - logger.silly( - `User ${userId} in guild ${guildId} is on timeout 2022-04-14-13-51-00` - ); - return; - } - - userData.credits += guildData.credits.rate; - - await userData - .save() - .then(async () => { - logger.silly( - `User ${userId} in guild ${guildId} has ${userData.credits} credits` - ); - }) - .catch(async (err) => { - logger.error( - `Error saving credits for user ${userId} in guild ${guildId}`, - err - ); - }); - - await timeouts - .create(timeoutData) - .then(async () => { - logger.silly( - `Timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId} has been created` - ); - }) - .catch(async (err) => { - logger.error( - `Error creating timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId}`, - err - ); - }); - - setTimeout(async () => { - await timeouts - .deleteOne(timeoutData) - .then(async () => { - logger.silly( - `Timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId} has been deleted` - ); - }) - .catch(async (err) => { - logger.error( - `Error deleting timeout 2022-04-14-13-51-00 for user ${userId} in guild ${guildId}`, - err - ); - }); - }, guildData.credits.timeout); - }, -}; diff --git a/src/events/messageCreate/modules/points/index.ts b/src/events/messageCreate/modules/points/index.ts deleted file mode 100644 index 9a8acd7..0000000 --- a/src/events/messageCreate/modules/points/index.ts +++ /dev/null @@ -1,89 +0,0 @@ -import logger from "../../../../logger"; -import timeouts from "../../../../models/timeout"; - -import fetchUser from "../../../../helpers/fetchUser"; -import fetchGuild from "../../../../helpers/fetchGuild"; - -import { Message } from "discord.js"; -export default { - execute: async (message: Message) => { - const { guild, author, content, channel } = message; - - if (guild == null) return; - if (author.bot) return; - if (channel?.type !== "GUILD_TEXT") return; - - const { id: guildId } = guild; - const { id: userId } = author; - - const guildData = await fetchGuild(guild); - const userData = await fetchUser(author, guild); - - if (content.length < guildData.credits.minimumLength) return; - - const timeoutData = { - guildId, - userId, - timeoutId: "2022-04-14-14-15-00", - }; - - const timeout = await timeouts.findOne(timeoutData); - - if (timeout) { - logger.silly( - `User ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id} is on timeout 2022-04-14-14-15-00` - ); - return; - } - - userData.points += guildData.points.rate; - - await userData - .save() - .then(async () => { - logger.silly( - `Successfully saved user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` - ); - }) - .catch(async (err) => { - logger.error( - `Error saving points for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`, - err - ); - }); - - logger.silly( - `User ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id}) has ${userData.points} points` - ); - - await timeouts - .create(timeoutData) - .then(async () => { - logger.silly( - `Successfully created timeout for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` - ); - }) - .catch(async (err) => { - logger.error( - `Error creating timeout 2022-04-14-14-15-00 for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`, - err - ); - }); - - setTimeout(async () => { - await timeouts - .deleteOne(timeoutData) - .then(async () => { - logger.silly( - `Successfully deleted timeout 2022-04-14-14-15-00 for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` - ); - }) - .catch(async (err) => { - logger.error( - `Error deleting timeout 2022-04-14-14-15-00 for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`, - err - ); - }); - }, guildData.points.timeout); - }, -}; diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands.ts index 2123da7..4542377 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands.ts @@ -12,6 +12,10 @@ import { ICommand } from "../interfaces/Command"; export default async (client: Client) => { const commandList: Array = []; + if (!client.commands) { + throw new Error("client.commands is not defined"); + } + logger.info("Gathering command list"); await Promise.all( @@ -25,7 +29,7 @@ export default async (client: Client) => { logger.info(`Finished gathering command list.`); }) .catch(async (error) => { - logger.error(`${error}`); + throw new Error(`Could not gather command list: ${error}`); }); const rest = new REST({ version: "9" }).setToken(token); diff --git a/src/helpers/addSeconds/index.ts b/src/helpers/addSeconds/index.ts index 6a89447..91bff4e 100644 --- a/src/helpers/addSeconds/index.ts +++ b/src/helpers/addSeconds/index.ts @@ -1,4 +1,4 @@ -export default async (numOfSeconds: number | undefined, date = new Date()) => { +export default async (numOfSeconds: number, date: Date) => { if (!numOfSeconds) throw new Error("numOfSeconds is required"); date.setSeconds(date.getSeconds() + numOfSeconds); diff --git a/src/helpers/cooldown/index.ts b/src/helpers/cooldown/index.ts new file mode 100644 index 0000000..2417d81 --- /dev/null +++ b/src/helpers/cooldown/index.ts @@ -0,0 +1,112 @@ +// Dependencies +import { CommandInteraction, Message } from "discord.js"; + +import logger from "../../logger"; + +import getEmbedConfig from "../../helpers/getEmbedConfig"; +import timeoutSchema from "../../models/timeout"; +import addSeconds from "../../helpers/addSeconds"; + +export const interaction = async (i: CommandInteraction, cooldown: number) => { + const { guild, user, commandId } = i; + + // Check if user has a timeout + const hasTimeout = await timeoutSchema.findOne({ + guildId: guild?.id || "0", + userId: user.id, + cooldown: cooldown, + timeoutId: commandId, + }); + + // If user is not on timeout + if (hasTimeout) { + const { guildId, userId, timeoutId, createdAt } = hasTimeout; + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (!overDue) { + const diff = Math.round( + (new Date(hasTimeout.createdAt).getTime() - new Date().getTime()) / 1000 + ); + + throw new Error( + `You must wait ${diff} seconds before using this command.` + ); + } + + // Delete timeout + await timeoutSchema + .deleteOne({ + guildId, + userId, + timeoutId, + cooldown, + }) + .then(async () => { + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + }); + } + // Create timeout + await timeoutSchema.create({ + guildId: guild?.id || "0", + userId: user.id, + cooldown: cooldown, + timeoutId: commandId, + }); +}; + +export const message = async ( + message: Message, + cooldown: number, + id: string +) => { + const { guild, member } = message; + if (!guild) throw new Error("Guild is undefined"); + if (!member) throw new Error("Member is undefined"); + + // Check if user has a timeout + const hasTimeout = await timeoutSchema.findOne({ + guildId: guild?.id || "0", + userId: member.id, + cooldown: cooldown, + timeoutId: id, + }); + + // If user is not on timeout + if (hasTimeout) { + const { guildId, userId, timeoutId, createdAt } = hasTimeout; + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (!overDue) { + const diff = Math.round( + (new Date(hasTimeout.createdAt).getTime() - new Date().getTime()) / 1000 + ); + + throw new Error( + `User: ${userId} on timeout-id: ${id} with cooldown: ${cooldown} secs with remaining: ${diff} secs.` + ); + } + + // Delete timeout + await timeoutSchema + .deleteOne({ + guildId, + userId: member.id, + timeoutId: id, + cooldown, + }) + .then(async () => { + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + }); + } + // Create timeout + await timeoutSchema.create({ + guildId: guild?.id || "0", + userId: member.id, + cooldown: cooldown, + timeoutId: id, + }); +}; diff --git a/src/helpers/deferReply/index.ts b/src/helpers/deferReply/index.ts index 45d95ed..b5cfdc3 100644 --- a/src/helpers/deferReply/index.ts +++ b/src/helpers/deferReply/index.ts @@ -2,8 +2,6 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; import getEmbedConfig from "../../helpers/getEmbedConfig"; export default async (interaction: CommandInteraction, ephemeral: boolean) => { - if (interaction.guild == null) return; - await interaction.deferReply({ ephemeral, }); diff --git a/src/helpers/listDir/index.ts b/src/helpers/listDir/index.ts index 247fbe0..95ed1da 100644 --- a/src/helpers/listDir/index.ts +++ b/src/helpers/listDir/index.ts @@ -2,9 +2,7 @@ import fs from "fs"; const fsPromises = fs.promises; export default async (path: string) => { - try { - return await fsPromises.readdir(path); - } catch (err) { - console.error("Error occurred while reading directory!", err); - } + return fsPromises.readdir(path).catch(async (e) => { + throw new Error(`Could not list directory: ${path}`, e); + }); }; diff --git a/src/index.ts b/src/index.ts index c9c82a1..ef3cab7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,10 +4,7 @@ import { token, intents } from "./config/discord"; import { Client } from "discord.js"; // discord.js -import * as databaseManager from "./managers/database"; -import * as scheduleManager from "./managers/schedule"; -import * as eventManager from "./managers/event"; -import * as commandManager from "./managers/command"; +import * as managers from "./managers"; // Main process that starts all other sub processes const main = async () => { @@ -16,11 +13,7 @@ const main = async () => { intents, }); - // Start managers - await databaseManager.start(); - await scheduleManager.start(client); - await commandManager.register(client); - await eventManager.register(client); + await managers.start(client); // Authorize with Discord's API await client.login(token); diff --git a/src/logger/index.ts b/src/logger/index.ts index 1ffbceb..0593ec9 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -3,7 +3,8 @@ import "winston-daily-rotate-file"; import { logLevel } from "../config/other"; -const { combine, timestamp, printf, colorize, align, json } = winston.format; +const { combine, timestamp, printf, errors, colorize, align, json } = + winston.format; export default winston.createLogger({ level: logLevel || "info", @@ -16,6 +17,7 @@ export default winston.createLogger({ }), new winston.transports.Console({ format: combine( + errors({ stack: true, trace: true }), // <-- use errors format colorize({ all: true }), timestamp({ format: "YYYY-MM-DD HH:MM:ss", diff --git a/src/managers/command/index.ts b/src/managers/command/index.ts index ece1712..c3c08f9 100644 --- a/src/managers/command/index.ts +++ b/src/managers/command/index.ts @@ -1,20 +1,25 @@ -import fs from "fs"; // fs -import { Collection, Client } from "discord.js"; // discord.js -import logger from "../../logger"; -import { ICommand } from "../../interfaces/Command"; +import { Collection, Client } from "discord.js"; import listDir from "../../helpers/listDir"; +import logger from "../../logger"; + +import { ICommand } from "../../interfaces/Command"; export const register = async (client: Client) => { client.commands = new Collection(); - const commandNames = await listDir("commands"); - if (!commandNames) return; + const commandNames = await listDir("plugins/commands"); + + if (!commandNames) throw new Error("Could not list commands"); logger.info(`Loading ${commandNames.length} commands`); await Promise.all( commandNames.map(async (commandName) => { - const command: ICommand = await import(`../../commands/${commandName}`); + const command: ICommand = await import( + `../../plugins/commands/${commandName}` + ).catch(async (e) => { + throw new Error(`Could not load command: ${commandName}`, e); + }); client.commands.set(command.builder.name, command); @@ -25,6 +30,6 @@ export const register = async (client: Client) => { logger.info(`Finished loading commands.`); }) .catch(async (err) => { - logger.error(`${err}`); + throw new Error(`Could not load commands: ${err}`); }); }; diff --git a/src/managers/database/index.ts b/src/managers/database/index.ts index c16eb73..0063c61 100644 --- a/src/managers/database/index.ts +++ b/src/managers/database/index.ts @@ -8,9 +8,14 @@ import logger from "../../logger"; import { url } from "../../config/database"; export const start = async () => { - await mongoose.connect(url).then(async (connection) => { - logger.info(`Connected to database: ${connection.connection.name}`); - }); + await mongoose + .connect(url) + .then(async (connection) => { + logger.info(`Connected to database: ${connection.connection.name}`); + }) + .catch(async (e) => { + logger.error("Could not connect to database", e); + }); mongoose.connection.on("error", async (error) => { logger.error(`${error}`); diff --git a/src/managers/event/index.ts b/src/managers/event/index.ts index 9718b12..348e138 100644 --- a/src/managers/event/index.ts +++ b/src/managers/event/index.ts @@ -2,15 +2,18 @@ import { Client } from "discord.js"; import listDir from "../../helpers/listDir"; import { IEvent } from "../../interfaces/Event"; +import logger from "../../logger"; export const register = async (client: Client) => { - const eventNames = await listDir("events"); + const eventNames = await listDir("plugins/events"); if (!eventNames) return; for await (const eventName of eventNames) { - const event: IEvent = await import(`../../events/${eventName}`); + const event: IEvent = await import(`../../plugins/events/${eventName}`); const eventExecutor = async (...args: Promise[]) => - event.execute(...args); + event.execute(...args).catch(async (err) => { + logger.error(`${err}`); + }); if (!event.options?.type) return; switch (event.options.type) { diff --git a/src/managers/index.ts b/src/managers/index.ts new file mode 100644 index 0000000..6981d3c --- /dev/null +++ b/src/managers/index.ts @@ -0,0 +1,13 @@ +import { Client } from "discord.js"; + +import * as database from "./database"; +import * as schedule from "./schedule"; +import * as event from "./event"; +import * as command from "./command"; + +export const start = async (client: Client) => { + await database.start(); + await schedule.start(client); + await command.register(client); + await event.register(client); +}; diff --git a/src/models/timeout.ts b/src/models/timeout.ts index 878f498..0e3554c 100644 --- a/src/models/timeout.ts +++ b/src/models/timeout.ts @@ -4,7 +4,7 @@ import { Schema, model } from "mongoose"; export interface ITimeout { userId: Snowflake; guildId: Snowflake; - cooldown?: number; + cooldown: number; timeoutId: string; createdAt: Date; updatedAt: Date; @@ -26,7 +26,7 @@ const timeoutSchema = new Schema( }, cooldown: { type: Number, - required: false, + required: true, unique: false, index: true, }, diff --git a/src/plugins/buttons/primary/index.ts b/src/plugins/buttons/primary/index.ts new file mode 100644 index 0000000..bd71158 --- /dev/null +++ b/src/plugins/buttons/primary/index.ts @@ -0,0 +1,7 @@ +import { CommandInteraction } from "discord.js"; + +export const metadata = { guildOnly: false, ephemeral: false }; + +export const execute = async (interaction: CommandInteraction) => { + console.log("primary button clicked!"); +}; diff --git a/src/commands/counters/index.ts b/src/plugins/commands/counters/index.ts similarity index 93% rename from src/commands/counters/index.ts rename to src/plugins/commands/counters/index.ts index da17e90..eca16dc 100644 --- a/src/commands/counters/index.ts +++ b/src/plugins/commands/counters/index.ts @@ -1,6 +1,6 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; -import logger from "../../logger"; +import logger from "../../../logger"; import modules from "../../commands/counters/modules"; diff --git a/src/commands/counters/modules/index.ts b/src/plugins/commands/counters/modules/index.ts similarity index 100% rename from src/commands/counters/modules/index.ts rename to src/plugins/commands/counters/modules/index.ts diff --git a/src/commands/counters/modules/view/index.ts b/src/plugins/commands/counters/modules/view/index.ts similarity index 91% rename from src/commands/counters/modules/view/index.ts rename to src/plugins/commands/counters/modules/view/index.ts index 6c3196f..77e1714 100644 --- a/src/commands/counters/modules/view/index.ts +++ b/src/plugins/commands/counters/modules/view/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; -import counterSchema from "../../../../models/counter"; +import counterSchema from "../../../../../models/counter"; export default { metadata: { guildOnly: true, ephemeral: false }, @@ -25,7 +25,6 @@ export default { }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild } = interaction; diff --git a/src/commands/credits/index.ts b/src/plugins/commands/credits/index.ts similarity index 96% rename from src/commands/credits/index.ts rename to src/plugins/commands/credits/index.ts index 02c03a5..9d1a3b4 100644 --- a/src/commands/credits/index.ts +++ b/src/plugins/commands/credits/index.ts @@ -1,6 +1,6 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "../../logger"; +import logger from "../../../logger"; import modules from "./modules"; diff --git a/src/commands/credits/modules/balance/index.ts b/src/plugins/commands/credits/modules/balance/index.ts similarity index 91% rename from src/commands/credits/modules/balance/index.ts rename to src/plugins/commands/credits/modules/balance/index.ts index 2387d57..0e646c2 100644 --- a/src/commands/credits/modules/balance/index.ts +++ b/src/plugins/commands/credits/modules/balance/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "../../../../logger"; +import logger from "../../../../../logger"; -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; export default { metadata: { guildOnly: true, ephemeral: true }, @@ -19,7 +19,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, user, guild } = interaction; diff --git a/src/commands/credits/modules/gift/index.ts b/src/plugins/commands/credits/modules/gift/index.ts similarity index 96% rename from src/commands/credits/modules/gift/index.ts rename to src/plugins/commands/credits/modules/gift/index.ts index 9873c02..84b2350 100644 --- a/src/commands/credits/modules/gift/index.ts +++ b/src/plugins/commands/credits/modules/gift/index.ts @@ -2,15 +2,15 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../logger"; +import logger from "../../../../../logger"; import mongoose from "mongoose"; // Models -import fetchUser from "../../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -38,7 +38,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, user, guild, client } = interaction; diff --git a/src/commands/credits/modules/index.ts b/src/plugins/commands/credits/modules/index.ts similarity index 100% rename from src/commands/credits/modules/index.ts rename to src/plugins/commands/credits/modules/index.ts diff --git a/src/commands/credits/modules/top/index.ts b/src/plugins/commands/credits/modules/top/index.ts similarity index 88% rename from src/commands/credits/modules/top/index.ts rename to src/plugins/commands/credits/modules/top/index.ts index 78539c4..29aadda 100644 --- a/src/commands/credits/modules/top/index.ts +++ b/src/plugins/commands/credits/modules/top/index.ts @@ -1,10 +1,10 @@ -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import logger from "../../../../logger"; +import logger from "../../../../../logger"; -import userSchema, { IUser } from "../../../../models/user"; +import userSchema, { IUser } from "../../../../../models/user"; export default { metadata: { guildOnly: true, ephemeral: false }, @@ -13,7 +13,6 @@ export default { return command.setName("top").setDescription(`View the top users`); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { guild } = interaction; diff --git a/src/commands/credits/modules/work/index.ts b/src/plugins/commands/credits/modules/work/index.ts similarity index 50% rename from src/commands/credits/modules/work/index.ts rename to src/plugins/commands/credits/modules/work/index.ts index ba1a08e..a84a696 100644 --- a/src/commands/credits/modules/work/index.ts +++ b/src/plugins/commands/credits/modules/work/index.ts @@ -4,17 +4,17 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import Chance from "chance"; // Configurations -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../logger"; +import logger from "../../../../../logger"; // Models -import timeoutSchema from "../../../../models/timeout"; +import * as cooldown from "../../../../../helpers/cooldown"; // Helpers -import fetchUser from "../../../../helpers/fetchUser"; -import fetchGuild from "../../../../helpers/fetchGuild"; +import fetchUser from "../../../../../helpers/fetchUser"; +import fetchGuild from "../../../../../helpers/fetchGuild"; export default { metadata: { guildOnly: true, ephemeral: true }, @@ -23,9 +23,9 @@ export default { return command.setName("work").setDescription(`Work to earn credits`); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(interaction.guild); // Destructure member + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); // Destructure member const { guild, user } = interaction; const embed = new MessageEmbed() @@ -39,33 +39,13 @@ export default { // Chance module const chance = new Chance(); - // Check if user has a timeout - const isTimeout = await timeoutSchema?.findOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - if (guild === null) { return logger?.silly(`Guild is null`); } const guildDB = await fetchGuild(guild); - // If user is not on timeout - if (isTimeout) { - logger?.silly(`User ${user?.id} is on timeout`); - - return interaction.editReply({ - embeds: [ - embed - .setDescription( - `You are on timeout, please wait ${guildDB?.credits.workTimeout} seconds.` - ) - .setColor(errorColor), - ], - }); - } + await cooldown.interaction(interaction, guildDB?.credits?.workTimeout); const creditsEarned = chance.integer({ min: 0, @@ -93,23 +73,5 @@ export default { ], }); }); - - // Create a timeout for the user - await timeoutSchema?.create({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - - setTimeout(async () => { - logger?.silly(`Removing timeout for user ${user?.id}`); - - // When timeout is out, remove it from the database - await timeoutSchema?.deleteOne({ - guildId: guild?.id, - userId: user?.id, - timeoutId: "2022-03-15-19-16", - }); - }, guildDB?.credits?.workTimeout); }, }; diff --git a/src/commands/fun/index.ts b/src/plugins/commands/fun/index.ts similarity index 94% rename from src/commands/fun/index.ts rename to src/plugins/commands/fun/index.ts index 5c71cd2..e0337a6 100644 --- a/src/commands/fun/index.ts +++ b/src/plugins/commands/fun/index.ts @@ -1,6 +1,6 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "../../logger"; +import logger from "../../../logger"; import modules from "../../commands/fun/modules"; diff --git a/src/commands/fun/modules/index.ts b/src/plugins/commands/fun/modules/index.ts similarity index 100% rename from src/commands/fun/modules/index.ts rename to src/plugins/commands/fun/modules/index.ts diff --git a/src/commands/fun/modules/meme/index.ts b/src/plugins/commands/fun/modules/meme/index.ts similarity index 92% rename from src/commands/fun/modules/meme/index.ts rename to src/plugins/commands/fun/modules/meme/index.ts index 249d2ee..88b2304 100644 --- a/src/commands/fun/modules/meme/index.ts +++ b/src/plugins/commands/fun/modules/meme/index.ts @@ -1,11 +1,11 @@ -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import axios from "axios"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; export default { - metadata: { guildOnly: false, ephemeral: false, cooldown: 5 }, + metadata: { guildOnly: false, ephemeral: false, cooldown: 15 }, builder: (command: SlashCommandSubcommandBuilder) => { return command.setName("meme").setDescription("Get a meme from r/memes)"); diff --git a/src/commands/manage/index.ts b/src/plugins/commands/manage/index.ts similarity index 95% rename from src/commands/manage/index.ts rename to src/plugins/commands/manage/index.ts index 14b5f6c..1f914bb 100644 --- a/src/commands/manage/index.ts +++ b/src/plugins/commands/manage/index.ts @@ -4,7 +4,7 @@ import { CommandInteraction } from "discord.js"; // Groups import modules from "../../commands/manage/modules"; -import logger from "../../logger"; +import logger from "../../../logger"; export const moduleData = modules; diff --git a/src/commands/manage/modules/counters/index.ts b/src/plugins/commands/manage/modules/counters/index.ts similarity index 95% rename from src/commands/manage/modules/counters/index.ts rename to src/plugins/commands/manage/modules/counters/index.ts index 36d6cd9..dbafa9f 100644 --- a/src/commands/manage/modules/counters/index.ts +++ b/src/plugins/commands/manage/modules/counters/index.ts @@ -2,7 +2,7 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -import logger from "../../../../logger"; +import logger from "../../../../../logger"; // Modules import modules from "./modules"; diff --git a/src/commands/manage/modules/counters/modules/add/index.ts b/src/plugins/commands/manage/modules/counters/modules/add/index.ts similarity index 91% rename from src/commands/manage/modules/counters/modules/add/index.ts rename to src/plugins/commands/manage/modules/counters/modules/add/index.ts index 5d7ea53..d00a319 100644 --- a/src/commands/manage/modules/counters/modules/add/index.ts +++ b/src/plugins/commands/manage/modules/counters/modules/add/index.ts @@ -4,12 +4,12 @@ import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Models -import counterSchema from "../../../../../../models/counter"; +import counterSchema from "../../../../../../../models/counter"; // Function export default { @@ -43,7 +43,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild } = interaction; diff --git a/src/commands/manage/modules/counters/modules/index.ts b/src/plugins/commands/manage/modules/counters/modules/index.ts similarity index 100% rename from src/commands/manage/modules/counters/modules/index.ts rename to src/plugins/commands/manage/modules/counters/modules/index.ts diff --git a/src/commands/manage/modules/counters/modules/remove/index.ts b/src/plugins/commands/manage/modules/counters/modules/remove/index.ts similarity index 91% rename from src/commands/manage/modules/counters/modules/remove/index.ts rename to src/plugins/commands/manage/modules/counters/modules/remove/index.ts index c265f0b..563829b 100644 --- a/src/commands/manage/modules/counters/modules/remove/index.ts +++ b/src/plugins/commands/manage/modules/counters/modules/remove/index.ts @@ -2,13 +2,13 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Models -import counterSchema from "../../../../../../models/counter"; +import counterSchema from "../../../../../../../models/counter"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { ChannelType } from "discord-api-types/v10"; @@ -33,7 +33,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild } = interaction; diff --git a/src/commands/manage/modules/credits/index.ts b/src/plugins/commands/manage/modules/credits/index.ts similarity index 84% rename from src/commands/manage/modules/credits/index.ts rename to src/plugins/commands/manage/modules/credits/index.ts index 5e215ec..b4673ff 100644 --- a/src/commands/manage/modules/credits/index.ts +++ b/src/plugins/commands/manage/modules/credits/index.ts @@ -1,6 +1,6 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; -import logger from "../../../../logger"; +import logger from "../../../../../logger"; import modules from "./modules"; @@ -14,7 +14,7 @@ export const builder = (group: SlashCommandSubcommandGroupBuilder) => { .addSubcommand(modules.set.builder) .addSubcommand(modules.take.builder) .addSubcommand(modules.transfer.builder) - .addSubcommand(modules.drop.builder); + .addSubcommand(modules.giveaway.builder); }; export const execute = async (interaction: CommandInteraction) => { @@ -27,7 +27,7 @@ export const execute = async (interaction: CommandInteraction) => { return modules.take.execute(interaction); case "transfer": return modules.transfer.execute(interaction); - case "drop": - return modules.drop.execute(interaction); + case "giveaway": + return modules.giveaway.execute(interaction); } }; diff --git a/src/commands/manage/modules/credits/modules/give/index.ts b/src/plugins/commands/manage/modules/credits/modules/give/index.ts similarity index 94% rename from src/commands/manage/modules/credits/modules/give/index.ts rename to src/plugins/commands/manage/modules/credits/modules/give/index.ts index ebbc762..9615f73 100644 --- a/src/commands/manage/modules/credits/modules/give/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/give/index.ts @@ -3,16 +3,16 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Helpers -import pluralize from "../../../../../../helpers/pluralize"; +import pluralize from "../../../../../../../helpers/pluralize"; // Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import fetchUser from "../../../../../../../helpers/fetchUser"; // Function export default { @@ -40,7 +40,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure const { guild, options } = interaction; diff --git a/src/commands/manage/modules/credits/modules/drop/index.ts b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts similarity index 61% rename from src/commands/manage/modules/credits/modules/drop/index.ts rename to src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts index 7141c9a..9ee2f17 100644 --- a/src/commands/manage/modules/credits/modules/drop/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts @@ -1,22 +1,21 @@ // Dependencies -import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; +import { + CommandInteraction, + MessageActionRow, + MessageButton, + MessageEmbed, + Permissions, +} from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { v4 as uuidv4 } from "uuid"; import axios from "axios"; -import apiSchema from "../../../../../../models/api"; -import encryption from "../../../../../../handlers/encryption"; +import apiSchema from "../../../../../../../models/api"; +import encryption from "../../../../../../../handlers/encryption"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; -// Handlers -import logger from "../../../../../../logger"; - -// Helpers -import pluralize from "../../../../../../helpers/pluralize"; - -// Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import { ChannelType } from "discord-api-types/v10"; // Function export default { @@ -28,8 +27,8 @@ export default { builder: (command: SlashCommandSubcommandBuilder) => { return command - .setName("drop") - .setDescription("Drop some credits for specified amount of users.") + .setName("giveaway") + .setDescription("Giveaway some credits for specified amount of users.") .addIntegerOption((option) => option .setName("uses") @@ -47,12 +46,13 @@ export default { .setName("channel") .setDescription("The channel to send the message to.") .setRequired(true) + .addChannelTypes(ChannelType.GuildText) ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(interaction.guild); // Destructure + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); // Destructure const { guild, options } = interaction; const uses = options?.getInteger("uses"); @@ -76,31 +76,39 @@ export default { if (!apiCredentials) return; const api = axios?.create({ - baseURL: apiCredentials.url, + baseURL: `${apiCredentials?.url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`, }, }); - const shopUrl = apiCredentials?.url?.replace("/api", "/store"); + const shopUrl = `${apiCredentials?.url}/store`; await api .post("vouchers", { uses, code, credits: creditAmount, - memo: `${interaction?.createdTimestamp} - ${interaction?.user?.id}`, + memo: `[GIVEAWAY] ${interaction?.createdTimestamp} - ${interaction?.user?.id}`, }) .then(async () => { await interaction.editReply({ embeds: [ embed .setColor(successColor) - .setDescription(`Successfully crated code: ${code}`), + .setDescription(`Successfully created code: ${code}`), ], }); - const discordChannel = guild.channels.cache.get(channel.id); + const buttons = new MessageActionRow().addComponents( + new MessageButton() + .setLabel("Redeem it here") + .setStyle("LINK") + .setEmoji("🏦") + .setURL(`${shopUrl}?voucher=${code}`) + ); + + const discordChannel = guild?.channels.cache.get(channel.id); if (!discordChannel) return; @@ -109,17 +117,20 @@ export default { discordChannel.send({ embeds: [ new MessageEmbed() - .setTitle("[:parachute:] Code Drop!") + .setTitle("[:parachute:] Credits!") .addFields([ - { name: "Code", value: `${code}`, inline: true }, - { name: "Amount", value: `${creditAmount}`, inline: true }, - { name: "Uses", value: `${uses}`, inline: true }, + { + name: "💶 Credits", + value: `${creditAmount}`, + inline: true, + }, ]) .setDescription( - `${interaction.user} dropped a voucher! You can use the code [here](${shopUrl})!` + `${interaction.user} dropped a voucher for a maximum **${uses}** members!` ) .setColor(successColor), ], + components: [buttons], }); }); }, diff --git a/src/commands/manage/modules/credits/modules/index.ts b/src/plugins/commands/manage/modules/credits/modules/index.ts similarity index 55% rename from src/commands/manage/modules/credits/modules/index.ts rename to src/plugins/commands/manage/modules/credits/modules/index.ts index 07b72e6..96acc29 100644 --- a/src/commands/manage/modules/credits/modules/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/index.ts @@ -2,6 +2,6 @@ import give from "./give"; import set from "./set"; import take from "./take"; import transfer from "./transfer"; -import drop from "./drop"; +import giveaway from "./giveaway"; -export default { give, set, take, transfer, drop }; +export default { give, set, take, transfer, giveaway }; diff --git a/src/commands/manage/modules/credits/modules/set/index.ts b/src/plugins/commands/manage/modules/credits/modules/set/index.ts similarity index 95% rename from src/commands/manage/modules/credits/modules/set/index.ts rename to src/plugins/commands/manage/modules/credits/modules/set/index.ts index a8e1771..a3be389 100644 --- a/src/commands/manage/modules/credits/modules/set/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/set/index.ts @@ -2,15 +2,15 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Helpers // Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import fetchUser from "../../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -39,7 +39,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild } = interaction; diff --git a/src/commands/manage/modules/credits/modules/take/index.ts b/src/plugins/commands/manage/modules/credits/modules/take/index.ts similarity index 94% rename from src/commands/manage/modules/credits/modules/take/index.ts rename to src/plugins/commands/manage/modules/credits/modules/take/index.ts index 5cf794a..fd3076b 100644 --- a/src/commands/manage/modules/credits/modules/take/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/take/index.ts @@ -2,16 +2,16 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Helpers -import pluralize from "../../../../../../helpers/pluralize"; +import pluralize from "../../../../../../../helpers/pluralize"; // Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import fetchUser from "../../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -40,7 +40,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure const { guild, options } = interaction; diff --git a/src/commands/manage/modules/credits/modules/transfer/index.ts b/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts similarity index 97% rename from src/commands/manage/modules/credits/modules/transfer/index.ts rename to src/plugins/commands/manage/modules/credits/modules/transfer/index.ts index 011e603..dca0091 100644 --- a/src/commands/manage/modules/credits/modules/transfer/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/transfer/index.ts @@ -4,13 +4,13 @@ import { CommandInteraction, MessageEmbed, Permissions } from "discord.js"; import mongoose from "mongoose"; // Configurations -import getEmbedConfig from "../../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Handlers -import logger from "../../../../../../logger"; +import logger from "../../../../../../../logger"; // Models -import fetchUser from "../../../../../../helpers/fetchUser"; +import fetchUser from "../../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -45,7 +45,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); // Destructure member const { guild, options } = interaction; diff --git a/src/commands/manage/modules/index.ts b/src/plugins/commands/manage/modules/index.ts similarity index 100% rename from src/commands/manage/modules/index.ts rename to src/plugins/commands/manage/modules/index.ts diff --git a/src/commands/profile/index.ts b/src/plugins/commands/profile/index.ts similarity index 94% rename from src/commands/profile/index.ts rename to src/plugins/commands/profile/index.ts index 2039179..68cdc73 100644 --- a/src/commands/profile/index.ts +++ b/src/plugins/commands/profile/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import modules from "../../commands/profile/modules"; // Handlers -import logger from "../../logger"; +import logger from "../../../logger"; export const moduleData = modules; diff --git a/src/commands/profile/modules/index.ts b/src/plugins/commands/profile/modules/index.ts similarity index 100% rename from src/commands/profile/modules/index.ts rename to src/plugins/commands/profile/modules/index.ts diff --git a/src/commands/profile/modules/view.ts b/src/plugins/commands/profile/modules/view/index.ts similarity index 92% rename from src/commands/profile/modules/view.ts rename to src/plugins/commands/profile/modules/view/index.ts index 5a59fd3..4fbd5c6 100644 --- a/src/commands/profile/modules/view.ts +++ b/src/plugins/commands/profile/modules/view/index.ts @@ -2,12 +2,12 @@ import { CommandInteraction } from "discord.js"; // Configurations -import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Models -import fetchUser from "../../../helpers/fetchUser"; +import fetchUser from "../../../../../helpers/fetchUser"; -import logger from "../../../logger"; +import logger from "../../../../../logger"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -24,7 +24,6 @@ export default { }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); // Destructure diff --git a/src/commands/reputation/index.ts b/src/plugins/commands/reputation/index.ts similarity index 71% rename from src/commands/reputation/index.ts rename to src/plugins/commands/reputation/index.ts index b0812d4..ae1876e 100644 --- a/src/commands/reputation/index.ts +++ b/src/plugins/commands/reputation/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "../../logger"; +import logger from "../../../logger"; export const moduleData = modules; @@ -17,13 +17,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.give.builder); export const execute = async (interaction: CommandInteraction) => { - const { options } = interaction; - - if (options?.getSubcommand() === "give") { - logger?.silly(`Executing give subcommand`); - + if (interaction.options.getSubcommand() === "give") { await modules.give.execute(interaction); } - - logger?.silly(`No subcommand found`); }; diff --git a/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts b/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts new file mode 100644 index 0000000..f6a6778 --- /dev/null +++ b/src/plugins/commands/reputation/modules/give/components/noSelfReputation.ts @@ -0,0 +1,6 @@ +import { User } from "discord.js"; +export default async (to: User | null, from: User | null) => { + if (from?.id === to?.id) { + throw new Error("You cannot give reputation to yourself."); + } +}; diff --git a/src/plugins/commands/reputation/modules/give/index.ts b/src/plugins/commands/reputation/modules/give/index.ts new file mode 100644 index 0000000..c899ecb --- /dev/null +++ b/src/plugins/commands/reputation/modules/give/index.ts @@ -0,0 +1,87 @@ +import { CommandInteraction } from "discord.js"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; +import { timeout } from "../../../../../config/reputation"; +import logger from "../../../../../logger"; +import fetchUser from "../../../../../helpers/fetchUser"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import * as cooldown from "../../../../../helpers/cooldown"; +import noSelfReputation from "./components/noSelfReputation"; + +export default { + metadata: { guildOnly: true, ephemeral: true }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("give") + .setDescription("Give reputation to a user") + .addUserOption((option) => + option + .setName("target") + .setDescription("The user you want to repute.") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("type") + .setDescription("What type of reputation you want to repute") + .setRequired(true) + .addChoices( + { name: "Positive", value: "positive" }, + { + name: "Negative", + value: "negative", + } + ) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { options, user, guild } = interaction; + + const { errorColor, successColor, footerText, footerIcon } = + await getEmbedConfig(guild); // Destructure + + const optionTarget = options?.getUser("target"); + const optionType = options?.getString("type"); + + if (!guild) throw new Error("Guild is undefined"); + + const userObj = await fetchUser(user, guild); + if (!userObj) throw new Error("User is undefined"); + + // Pre-checks + await noSelfReputation(optionTarget, user); + + // Check if user is on cooldown otherwise create one + await cooldown.interaction(interaction, timeout); + + switch (optionType) { + case "positive": + userObj.reputation += 1; + break; + case "negative": + userObj.reputation += 1; + break; + default: + throw new Error("Invalid reputation type"); + } + + await userObj.save().then(async () => { + logger.silly(`User reputation has been updated`); + + await interaction.editReply({ + embeds: [ + { + title: "[:loudspeaker:] Give", + description: `You have given a ${optionType} repute to ${optionTarget}`, + timestamp: new Date(), + color: successColor, + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + }); + }); + }, +}; diff --git a/src/commands/reputation/modules/index.ts b/src/plugins/commands/reputation/modules/index.ts similarity index 100% rename from src/commands/reputation/modules/index.ts rename to src/plugins/commands/reputation/modules/index.ts diff --git a/src/commands/shop/index.ts b/src/plugins/commands/shop/index.ts similarity index 74% rename from src/commands/shop/index.ts rename to src/plugins/commands/shop/index.ts index 2ef6f65..697c94e 100644 --- a/src/commands/shop/index.ts +++ b/src/plugins/commands/shop/index.ts @@ -6,7 +6,7 @@ import { CommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "../../logger"; +import logger from "../../../logger"; export const moduleData = modules; @@ -14,16 +14,16 @@ export const moduleData = modules; export const builder = new SlashCommandBuilder() .setName("shop") .setDescription("Shop for credits and custom roles.") - .addSubcommand(modules.pterodactyl.builder) + .addSubcommand(modules.cpgg.builder) .addSubcommandGroup(modules.roles.builder); export const execute = async (interaction: CommandInteraction) => { const { options } = interaction; - if (options?.getSubcommand() === "pterodactyl") { - logger.silly(`Executing pterodactyl subcommand`); + if (options?.getSubcommand() === "cpgg") { + logger.silly(`Executing cpgg subcommand`); - return modules.pterodactyl.execute(interaction); + return modules.cpgg.execute(interaction); } if (options?.getSubcommandGroup() === "roles") { diff --git a/src/commands/shop/modules/pterodactyl.ts b/src/plugins/commands/shop/modules/cpgg/index.ts similarity index 65% rename from src/commands/shop/modules/pterodactyl.ts rename to src/plugins/commands/shop/modules/cpgg/index.ts index 207774c..aeee472 100644 --- a/src/commands/shop/modules/pterodactyl.ts +++ b/src/plugins/commands/shop/modules/cpgg/index.ts @@ -1,25 +1,30 @@ -import { CommandInteraction } from "discord.js"; +import { + CommandInteraction, + MessageActionRow, + MessageButton, +} from "discord.js"; import { v4 as uuidv4 } from "uuid"; import axios from "axios"; -import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; -import logger from "../../../logger"; -import encryption from "../../../handlers/encryption"; +import logger from "../../../../../logger"; +import encryption from "../../../../../handlers/encryption"; -import pluralize from "../../../helpers/pluralize"; +import pluralize from "../../../../../helpers/pluralize"; -import apiSchema from "../../../models/api"; -import fetchUser from "../../../helpers/fetchUser"; +import apiSchema from "../../../../../models/api"; +import fetchUser from "../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; +import { message } from "../../../../../helpers/cooldown/index"; export default { metadata: { guildOnly: true, ephemeral: true }, builder: (command: SlashCommandSubcommandBuilder) => { return command - .setName("pterodactyl") - .setDescription("Buy pterodactyl power.") + .setName("cpgg") + .setDescription("Buy cpgg power.") .addIntegerOption((option) => option .setName("amount") @@ -27,7 +32,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild, user, client } = interaction; @@ -71,8 +75,8 @@ export default { return interaction?.editReply({ embeds: [ { - title: ":shopping_cart: Shop [Pterodactyl]", - description: `You **can't** withdraw for __Pterodactyl__ below **100**.`, + title: "[:shopping_cart:] CPGG", + description: `You **can't** withdraw for __CPGG__ below **100**.`, color: errorColor, fields: [ { @@ -96,9 +100,9 @@ export default { return interaction?.editReply({ embeds: [ { - title: ":shopping_cart: Shop [Pterodactyl]", + title: "[:shopping_cart:] CPGG", description: - "You **can't** withdraw for __Pterodactyl__ above **1.000.000**.", + "You **can't** withdraw for __CPGG__ above **1.000.000**.", color: errorColor, fields: [ { @@ -122,7 +126,7 @@ export default { return interaction?.editReply({ embeds: [ { - title: ":shopping_cart: Shop [Pterodactyl]", + title: "[:shopping_cart:] CPGG", description: `You have **insufficient** credits.`, color: errorColor, fields: [ @@ -150,13 +154,21 @@ export default { if (!apiCredentials) return; const api = axios?.create({ - baseURL: apiCredentials.url, + baseURL: `${apiCredentials.url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`, }, }); - const shopUrl = apiCredentials?.url?.replace("/api", "/store"); + const shopUrl = `${apiCredentials?.url}/store`; + + const buttons = new MessageActionRow().addComponents( + new MessageButton() + .setLabel("Redeem it here") + .setStyle("LINK") + .setEmoji("🏦") + .setURL(`${shopUrl}?voucher=${code}`) + ); await api @@ -178,43 +190,47 @@ export default { ?.then(async () => { logger?.silly(`Successfully saved new credits.`); - await dmUser?.send({ - embeds: [ - { - title: ":shopping_cart: Shop [Pterodactyl]", - description: `Redeem this voucher [here](${shopUrl})!`, - fields: [ - { name: "Code", value: `${code}`, inline: true }, + if (!interaction.guild) throw new Error("Guild is undefined"); + + await dmUser + ?.send({ + embeds: [ + { + title: "[:shopping_cart:] CPGG", + description: `This voucher comes from **${interaction.guild.name}**.`, + fields: [ + { + name: "💶 Credits", + value: `${optionAmount || userDB?.credits}`, + inline: true, + }, + ], + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }, + ], + components: [buttons], + }) + .then(async (msg) => { + return interaction?.editReply({ + embeds: [ { - name: "Credits", - value: `${optionAmount || userDB?.credits}`, - inline: true, + title: "[:shopping_cart:] CPGG", + description: `I have sent you the code in [DM](${msg.url})!`, + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, }, ], - color: successColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); - - return interaction?.editReply({ - embeds: [ - { - title: ":shopping_cart: Shop [Pterodactyl]", - description: "I have sent you the code in DM!", - color: successColor, - timestamp: new Date(), - footer: { - iconURL: footerIcon, - text: footerText, - }, - }, - ], - }); + }); + }); }) .catch(async (error) => { @@ -223,7 +239,7 @@ export default { return interaction?.editReply({ embeds: [ { - title: ":shopping_cart: Shop [Pterodactyl]", + title: "[:shopping_cart:] CPGG", description: "Something went wrong.", color: errorColor, timestamp: new Date(), @@ -243,7 +259,7 @@ export default { return interaction?.editReply({ embeds: [ { - title: ":shopping_cart: Shop [Pterodactyl]", + title: "[:shopping_cart:] CPGG", description: "Something went wrong.", color: errorColor, timestamp: new Date(), diff --git a/src/plugins/commands/shop/modules/index.ts b/src/plugins/commands/shop/modules/index.ts new file mode 100644 index 0000000..c3df89d --- /dev/null +++ b/src/plugins/commands/shop/modules/index.ts @@ -0,0 +1,4 @@ +import cpgg from "./cpgg"; +import * as roles from "./roles"; + +export default { cpgg, roles }; diff --git a/src/commands/shop/modules/roles/index.ts b/src/plugins/commands/shop/modules/roles/index.ts similarity index 89% rename from src/commands/shop/modules/roles/index.ts rename to src/plugins/commands/shop/modules/roles/index.ts index 7d6cb90..f16a962 100644 --- a/src/commands/shop/modules/roles/index.ts +++ b/src/plugins/commands/shop/modules/roles/index.ts @@ -3,14 +3,14 @@ import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; // Handlers -import logger from "../../../../logger"; +import logger from "../../../../../logger"; -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; // Modules import modules from "./modules"; -import guildSchema from "../../../../models/guild"; +import guildSchema from "../../../../../models/guild"; export const moduleData = modules; diff --git a/src/commands/shop/modules/roles/modules/buy.ts b/src/plugins/commands/shop/modules/roles/modules/buy/index.ts similarity index 90% rename from src/commands/shop/modules/roles/modules/buy.ts rename to src/plugins/commands/shop/modules/roles/modules/buy/index.ts index 3d8ff54..23f91dc 100644 --- a/src/commands/shop/modules/roles/modules/buy.ts +++ b/src/plugins/commands/shop/modules/roles/modules/buy/index.ts @@ -6,17 +6,17 @@ import { } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "../../../../../models/shopRole"; -import guildSchema from "../../../../../models/guild"; +import shopRolesSchema from "../../../../../../../models/shopRole"; +import guildSchema from "../../../../../../../models/guild"; -import logger from "../../../../../logger"; +import logger from "../../../../../../../logger"; // Helpers -import pluralize from "../../../../../helpers/pluralize"; -import fetchUser from "../../../../../helpers/fetchUser"; +import pluralize from "../../../../../../../helpers/pluralize"; +import fetchUser from "../../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -41,7 +41,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild, user, member } = interaction; diff --git a/src/commands/shop/modules/roles/modules/cancel.ts b/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts similarity index 89% rename from src/commands/shop/modules/roles/modules/cancel.ts rename to src/plugins/commands/shop/modules/roles/modules/cancel/index.ts index d8b4314..5ff483e 100644 --- a/src/commands/shop/modules/roles/modules/cancel.ts +++ b/src/plugins/commands/shop/modules/roles/modules/cancel/index.ts @@ -2,16 +2,16 @@ import { CommandInteraction, GuildMemberRoleManager } from "discord.js"; // Configurations -import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../../../helpers/getEmbedConfig"; // Models -import shopRolesSchema from "../../../../../models/shopRole"; +import shopRolesSchema from "../../../../../../../models/shopRole"; -import logger from "../../../../../logger"; +import logger from "../../../../../../../logger"; // Helpers -import pluralize from "../../../../../helpers/pluralize"; -import fetchUser from "../../../../../helpers/fetchUser"; +import pluralize from "../../../../../../../helpers/pluralize"; +import fetchUser from "../../../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function @@ -30,7 +30,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const { options, guild, user, member } = interaction; diff --git a/src/commands/shop/modules/roles/modules/index.ts b/src/plugins/commands/shop/modules/roles/modules/index.ts similarity index 100% rename from src/commands/shop/modules/roles/modules/index.ts rename to src/plugins/commands/shop/modules/roles/modules/index.ts diff --git a/src/commands/utility/index.ts b/src/plugins/commands/utility/index.ts similarity index 73% rename from src/commands/utility/index.ts rename to src/plugins/commands/utility/index.ts index 6fb52db..c97ef47 100644 --- a/src/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -1,16 +1,9 @@ -// Dependencies import { SlashCommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; -// Modules -import modules from "../../commands/utility/modules"; - -// Handlers -import logger from "../../logger"; - +import modules from "./modules"; export const moduleData = modules; -// Function export const builder = new SlashCommandBuilder() .setName("utility") .setDescription("Common utility.") @@ -21,9 +14,7 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.avatar.builder); export const execute = async (interaction: CommandInteraction) => { - const { options } = interaction; - - switch (options.getSubcommand()) { + switch (interaction.options.getSubcommand()) { case "lookup": return modules.lookup.execute(interaction); case "about": @@ -33,6 +24,8 @@ export const execute = async (interaction: CommandInteraction) => { case "avatar": return modules.avatar.execute(interaction); default: - logger.error(`Unknown subcommand ${options.getSubcommand()}`); + throw new Error( + `Unknown subcommand: ${interaction.options.getSubcommand()}` + ); } }; diff --git a/src/plugins/commands/utility/modules/about/index.ts b/src/plugins/commands/utility/modules/about/index.ts new file mode 100644 index 0000000..f89d74d --- /dev/null +++ b/src/plugins/commands/utility/modules/about/index.ts @@ -0,0 +1,71 @@ +// Dependencies +import { + CommandInteraction, + MessageActionRow, + MessageButton, +} from "discord.js"; + +// Configurations +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; + +import { hosterName, hosterUrl } from "../../../../../config/other"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + metadata: { guildOnly: false, ephemeral: false }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command.setName("about").setDescription("About this bot!)"); + }, + execute: async (interaction: CommandInteraction) => { + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const buttons = new MessageActionRow().addComponents( + new MessageButton() + .setLabel("Source Code") + .setStyle("LINK") + .setEmoji("📄") + .setURL("https://github.com/ZynerOrg/xyter"), + new MessageButton() + .setLabel("Website") + .setStyle("LINK") + .setEmoji("🌐") + .setURL("https://zyner.org"), + new MessageButton() + .setLabel("Get Help") + .setStyle("LINK") + .setEmoji("💬") + .setURL("https://discord.zyner.org"), + new MessageButton() + .setLabel(`Hosted by ${hosterName}`) + .setStyle("LINK") + .setEmoji("⚒️") + .setURL(`${hosterUrl}`) + ); + + const interactionEmbed = { + title: "[:tools:] About", + description: ` + **Xyter**'s goal is to provide a __privacy-friendly__ discord bot. + We created **Xyter** to **replace the mess** of having a dozen or so bots in __your__ community. + On top of this, you can also see our **source code** for **security** and **privacy** issues. + As well as making your own **fork** of the bot, you can also get **help** from our community. + + Developed with ❤️ by **Zyner**, a non-profit project by teens. + `, + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + await interaction.editReply({ + embeds: [interactionEmbed], + components: [buttons], + }); + }, +}; diff --git a/src/commands/utility/modules/avatar.ts b/src/plugins/commands/utility/modules/avatar/index.ts similarity index 91% rename from src/commands/utility/modules/avatar.ts rename to src/plugins/commands/utility/modules/avatar/index.ts index 57110cf..24ab6c1 100644 --- a/src/commands/utility/modules/avatar.ts +++ b/src/plugins/commands/utility/modules/avatar/index.ts @@ -1,4 +1,4 @@ -import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { CommandInteraction, MessageEmbed } from "discord.js"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; @@ -17,7 +17,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/commands/utility/modules/index.ts b/src/plugins/commands/utility/modules/index.ts similarity index 100% rename from src/commands/utility/modules/index.ts rename to src/plugins/commands/utility/modules/index.ts diff --git a/src/commands/utility/modules/lookup.ts b/src/plugins/commands/utility/modules/lookup/index.ts similarity index 95% rename from src/commands/utility/modules/lookup.ts rename to src/plugins/commands/utility/modules/lookup/index.ts index a5825f9..44abe14 100644 --- a/src/commands/utility/modules/lookup.ts +++ b/src/plugins/commands/utility/modules/lookup/index.ts @@ -1,11 +1,11 @@ import axios from "axios"; import { CommandInteraction } from "discord.js"; -import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import embedBuilder from "../../../helpers/embedBuilder"; +import embedBuilder from "../../../../../helpers/embedBuilder"; export default { metadata: { guildOnly: false, ephemeral: false }, @@ -24,7 +24,6 @@ export default { ); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { errorColor, successColor, footerText, footerIcon } = await getEmbedConfig(interaction.guild); const embedTitle = "[:hammer:] Utility (Lookup)"; diff --git a/src/commands/utility/modules/stats.ts b/src/plugins/commands/utility/modules/stats/index.ts similarity index 95% rename from src/commands/utility/modules/stats.ts rename to src/plugins/commands/utility/modules/stats/index.ts index 805b948..a2a8282 100644 --- a/src/commands/utility/modules/stats.ts +++ b/src/plugins/commands/utility/modules/stats/index.ts @@ -1,4 +1,4 @@ -import getEmbedConfig from "../../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; import { CommandInteraction } from "discord.js"; @@ -9,7 +9,6 @@ export default { return command.setName("stats").setDescription("Check bot statistics!)"); }, execute: async (interaction: CommandInteraction) => { - if (interaction.guild == null) return; const { successColor, footerText, footerIcon } = await getEmbedConfig( interaction.guild ); diff --git a/src/events/guildCreate/index.ts b/src/plugins/events/guildCreate/index.ts similarity index 60% rename from src/events/guildCreate/index.ts rename to src/plugins/events/guildCreate/index.ts index a309884..60d5a3c 100644 --- a/src/events/guildCreate/index.ts +++ b/src/plugins/events/guildCreate/index.ts @@ -1,8 +1,8 @@ import { Guild } from "discord.js"; -import updatePresence from "../../helpers/updatePresence"; -import fetchGuild from "../../helpers/fetchGuild"; -import logger from "../../logger"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import updatePresence from "../../../helpers/updatePresence"; +import fetchGuild from "../../../helpers/fetchGuild"; +import logger from "../../../logger"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildDelete/index.ts b/src/plugins/events/guildDelete/index.ts similarity index 64% rename from src/events/guildDelete/index.ts rename to src/plugins/events/guildDelete/index.ts index be090b8..146351f 100644 --- a/src/events/guildDelete/index.ts +++ b/src/plugins/events/guildDelete/index.ts @@ -2,10 +2,10 @@ import { Guild } from "discord.js"; // Dependencies -import updatePresence from "../../helpers/updatePresence"; -import dropGuild from "../../helpers/dropGuild"; -import logger from "../../logger"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import updatePresence from "../../../helpers/updatePresence"; +import dropGuild from "../../../helpers/dropGuild"; +import logger from "../../../logger"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberAdd/audits.ts b/src/plugins/events/guildMemberAdd/audits.ts similarity index 91% rename from src/events/guildMemberAdd/audits.ts rename to src/plugins/events/guildMemberAdd/audits.ts index f2f3925..89c0384 100644 --- a/src/events/guildMemberAdd/audits.ts +++ b/src/plugins/events/guildMemberAdd/audits.ts @@ -1,9 +1,9 @@ -import logger from "../../logger"; +import logger from "../../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberAdd/index.ts b/src/plugins/events/guildMemberAdd/index.ts similarity index 72% rename from src/events/guildMemberAdd/index.ts rename to src/plugins/events/guildMemberAdd/index.ts index 156dfb7..8310579 100644 --- a/src/events/guildMemberAdd/index.ts +++ b/src/plugins/events/guildMemberAdd/index.ts @@ -2,14 +2,14 @@ import { GuildMember } from "discord.js"; // Dependencies -import updatePresence from "../../helpers/updatePresence"; -import fetchUser from "../../helpers/fetchUser"; -import logger from "../../logger"; +import updatePresence from "../../../helpers/updatePresence"; +import fetchUser from "../../../helpers/fetchUser"; +import logger from "../../../logger"; import joinMessage from "./joinMessage"; import audits from "./audits"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberAdd/joinMessage.ts b/src/plugins/events/guildMemberAdd/joinMessage.ts similarity index 91% rename from src/events/guildMemberAdd/joinMessage.ts rename to src/plugins/events/guildMemberAdd/joinMessage.ts index 4ffc3d4..47f9043 100644 --- a/src/events/guildMemberAdd/joinMessage.ts +++ b/src/plugins/events/guildMemberAdd/joinMessage.ts @@ -1,8 +1,8 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberRemove/audits.ts b/src/plugins/events/guildMemberRemove/audits.ts similarity index 91% rename from src/events/guildMemberRemove/audits.ts rename to src/plugins/events/guildMemberRemove/audits.ts index 92c9df8..a940ca3 100644 --- a/src/events/guildMemberRemove/audits.ts +++ b/src/plugins/events/guildMemberRemove/audits.ts @@ -1,9 +1,9 @@ -import logger from "../../logger"; +import logger from "../../../logger"; import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/guildMemberRemove/index.ts b/src/plugins/events/guildMemberRemove/index.ts similarity index 72% rename from src/events/guildMemberRemove/index.ts rename to src/plugins/events/guildMemberRemove/index.ts index 502aad4..b900a12 100644 --- a/src/events/guildMemberRemove/index.ts +++ b/src/plugins/events/guildMemberRemove/index.ts @@ -2,12 +2,12 @@ import { GuildMember } from "discord.js"; // Dependencies -import updatePresence from "../../helpers/updatePresence"; -import dropUser from "../../helpers/dropUser"; -import logger from "../../logger"; +import updatePresence from "../../../helpers/updatePresence"; +import dropUser from "../../../helpers/dropUser"; +import logger from "../../../logger"; import leaveMessage from "./leaveMessage"; import audits from "./audits"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/guildMemberRemove/leaveMessage.ts b/src/plugins/events/guildMemberRemove/leaveMessage.ts similarity index 91% rename from src/events/guildMemberRemove/leaveMessage.ts rename to src/plugins/events/guildMemberRemove/leaveMessage.ts index 5d3a36e..daae364 100644 --- a/src/events/guildMemberRemove/leaveMessage.ts +++ b/src/plugins/events/guildMemberRemove/leaveMessage.ts @@ -1,8 +1,8 @@ import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (member: GuildMember) => { diff --git a/src/events/interactionCreate/audits.ts b/src/plugins/events/interactionCreate/audits.ts similarity index 84% rename from src/events/interactionCreate/audits.ts rename to src/plugins/events/interactionCreate/audits.ts index 3f68219..7c71f80 100644 --- a/src/events/interactionCreate/audits.ts +++ b/src/plugins/events/interactionCreate/audits.ts @@ -1,9 +1,9 @@ -import logger from "../../logger"; +import logger from "../../../logger"; import { Interaction, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (interaction: Interaction) => { @@ -38,10 +38,12 @@ export default { .setDescription( ` **Interaction created by** ${interaction.user.username} **in** ${interaction.channel} + ㅤ**Interaction ID**: ${interaction.id} + ㅤ**Type**: ${interaction.type} + ㅤ**User ID**: ${interaction.user.id} ` ) .setThumbnail(interaction.user.displayAvatarURL()) - .addFields([{ name: "Event", value: "interactionCreate" }]) .setTimestamp() .setFooter({ text: footerText, diff --git a/src/plugins/events/interactionCreate/components/checks.ts b/src/plugins/events/interactionCreate/components/checks.ts new file mode 100644 index 0000000..006a14f --- /dev/null +++ b/src/plugins/events/interactionCreate/components/checks.ts @@ -0,0 +1,51 @@ +import { CommandInteraction, MessageEmbed } from "discord.js"; +import * as cooldown from "../../../../helpers/cooldown"; +import logger from "../../../../logger"; + +export default async ( + interaction: CommandInteraction, + metadata: any, + embedConfig: any +) => { + if ( + metadata.permissions && + metadata.guildOnly && + !interaction.memberPermissions?.has(metadata.permissions) + ) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:x:] Permission") + .setDescription(`You do not have the permission to manage the bot.`) + .setTimestamp(new Date()) + .setColor(embedConfig.errorColor) + .setFooter({ + text: embedConfig.footerText, + iconURL: embedConfig.footerIcon, + }), + ], + }); + } + + logger.info(metadata); + + if (metadata.cooldown) { + await cooldown + .interaction(interaction, metadata.cooldown) + .catch(async (error) => { + throw new Error("Cooldown error: " + error); + }); + } + + if (metadata.guildOnly) { + if (!interaction.guild) { + throw new Error("This command is guild only."); + } + } + + if (metadata.dmOnly) { + if (interaction.guild) { + throw new Error("This command is DM only."); + } + } +}; diff --git a/src/plugins/events/interactionCreate/components/isButton.ts b/src/plugins/events/interactionCreate/components/isButton.ts new file mode 100644 index 0000000..eaf1605 --- /dev/null +++ b/src/plugins/events/interactionCreate/components/isButton.ts @@ -0,0 +1,123 @@ +// Dependencies +import { CommandInteraction, MessageEmbed } from "discord.js"; + +import logger from "../../../../logger"; + +import deferReply from "../../../../helpers/deferReply"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import capitalizeFirstLetter from "../../../../helpers/capitalizeFirstLetter"; +import * as cooldown from "../../../../helpers/cooldown"; + +export default async (interaction: CommandInteraction) => { + if (!interaction.isButton()) return; + + const { errorColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const { guild, customId, user, memberPermissions } = interaction; + + const currentButton = await import(`../../../buttons/${customId}`); + + if (currentButton == null) { + logger.silly(`Button ${customId} not found`); + } + + const metadata = currentButton.metadata; + + await deferReply(interaction, metadata.ephemeral || false); + + if (metadata.guildOnly) { + if (!guild) { + logger.debug(`Guild is null`); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:x:] Permission") + .setDescription("This command is only available for guild") + .setColor(errorColor) + .setTimestamp(new Date()) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + } + } + + if ( + metadata.permissions && + metadata.guildOnly && + !memberPermissions?.has(metadata.permissions) + ) { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:x:] Permission") + .setDescription(`You do not have the permission to manage the bot.`) + .setTimestamp(new Date()) + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + } + + if (metadata.dmOnly) { + if (guild) { + logger.silly(`Guild exist`); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:x:] Permission") + .setDescription("This command is only available in DM.") + .setColor(errorColor) + .setTimestamp(new Date()) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + } + } + + if (metadata.cooldown) { + await cooldown + .interaction(interaction, metadata.cooldown) + .catch(async (error) => { + return interaction?.editReply({ + embeds: [ + new MessageEmbed() + .setTitle("[:x:] Permission") + .setDescription(`${error}`) + .setTimestamp(new Date()) + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + }); + } + + await currentButton + .execute(interaction) + .then(async () => { + return logger?.silly( + `Button: ${customId} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})` + ); + }) + .catch(async (error: string) => { + logger?.debug(`INTERACTION BUTTON CATCH: ${error}`); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle( + `[:x:] ${capitalizeFirstLetter( + interaction.options.getSubcommand() + )}` + ) + .setDescription(`${"``"}${error}${"``"}`) + .setColor(errorColor) + .setTimestamp(new Date()) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + }); +}; diff --git a/src/plugins/events/interactionCreate/components/isCommand.ts b/src/plugins/events/interactionCreate/components/isCommand.ts new file mode 100644 index 0000000..3a14ad6 --- /dev/null +++ b/src/plugins/events/interactionCreate/components/isCommand.ts @@ -0,0 +1,48 @@ +// Dependencies +import { CommandInteraction, MessageEmbed } from "discord.js"; + +import logger from "../../../../logger"; + +import deferReply from "../../../../helpers/deferReply"; +import getEmbedConfig from "../../../../helpers/getEmbedConfig"; +import getCommandMetadata from "../../../../helpers/getCommandMetadata"; +import capitalizeFirstLetter from "../../../../helpers/capitalizeFirstLetter"; +import * as cooldown from "../../../../helpers/cooldown"; + +export default async (interaction: CommandInteraction) => { + if (!interaction.isCommand()) return; + + const { errorColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const { client, guild, commandName, user, memberPermissions } = interaction; + + const currentCommand = client.commands.get(commandName); + + if (currentCommand == null) { + logger.silly(`Command ${commandName} not found`); + } + + const metadata = await getCommandMetadata(interaction, currentCommand); + + await deferReply(interaction, metadata.ephemeral || false); + + if (metadata.guildOnly && !guild) + throw new Error("This command is guild only."); + + if ( + metadata.permissions && + metadata.guildOnly && + !memberPermissions?.has(metadata.permissions) + ) + throw new Error("You don't have the required permissions"); + + if (metadata.dmOnly && guild) + throw new Error("This command is only available in DM"); + + if (metadata.cooldown) + await cooldown.interaction(interaction, metadata.cooldown); + + await currentCommand.execute(interaction); +}; diff --git a/src/plugins/events/interactionCreate/index.ts b/src/plugins/events/interactionCreate/index.ts new file mode 100644 index 0000000..f7365ec --- /dev/null +++ b/src/plugins/events/interactionCreate/index.ts @@ -0,0 +1,51 @@ +// 3rd party dependencies +import { CommandInteraction, MessageEmbed } from "discord.js"; + +// Dependencies +import isCommand from "../../events/interactionCreate/components/isCommand"; +import isButton from "../../events/interactionCreate/components/isButton"; +import logger from "../../../logger"; +import audits from "./audits"; +import { IEventOptions } from "../../../interfaces/EventOptions"; +import capitalizeFirstLetter from "../../../helpers/capitalizeFirstLetter"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; + +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (interaction: CommandInteraction) => { + const { guild, id } = interaction; + + logger?.silly( + `New interaction: ${id} in guild: ${guild?.name} (${guild?.id})` + ); + + const { errorColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + await audits.execute(interaction); + + try { + await isCommand(interaction); + await isButton(interaction); + } catch (error) { + logger.debug(`${error}`); + + return interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle( + `[:x:] ${capitalizeFirstLetter( + interaction.options.getSubcommand() + )}` + ) + .setDescription(`${"``"}${error}${"``"}`) + .setColor(errorColor) + .setTimestamp(new Date()) + .setFooter({ text: footerText, iconURL: footerIcon }), + ], + }); + } +}; diff --git a/src/events/messageCreate/index.ts b/src/plugins/events/messageCreate/index.ts similarity index 83% rename from src/events/messageCreate/index.ts rename to src/plugins/events/messageCreate/index.ts index f5beddf..06619f0 100644 --- a/src/events/messageCreate/index.ts +++ b/src/plugins/events/messageCreate/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; import modules from "../../events/messageCreate/modules"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageCreate/modules/counters/index.ts b/src/plugins/events/messageCreate/modules/counters/index.ts similarity index 94% rename from src/events/messageCreate/modules/counters/index.ts rename to src/plugins/events/messageCreate/modules/counters/index.ts index 9dcfca5..1a3c7a3 100644 --- a/src/events/messageCreate/modules/counters/index.ts +++ b/src/plugins/events/messageCreate/modules/counters/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; -import logger from "../../../../logger"; -import counterSchema from "../../../../models/counter"; +import logger from "../../../../../logger"; +import counterSchema from "../../../../../models/counter"; export default { execute: async (message: Message) => { diff --git a/src/plugins/events/messageCreate/modules/credits/index.ts b/src/plugins/events/messageCreate/modules/credits/index.ts new file mode 100644 index 0000000..24a5ce2 --- /dev/null +++ b/src/plugins/events/messageCreate/modules/credits/index.ts @@ -0,0 +1,46 @@ +import logger from "../../../../../logger"; +import { Message } from "discord.js"; + +import fetchUser from "../../../../../helpers/fetchUser"; +import fetchGuild from "../../../../../helpers/fetchGuild"; + +import * as cooldown from "../../../../../helpers/cooldown"; + +export default { + execute: async (message: Message) => { + const { guild, author, content, channel } = message; + + if (guild == null) return; + if (author.bot) return; + if (channel?.type !== "GUILD_TEXT") return; + + const { id: guildId } = guild; + const { id: userId } = author; + + const guildData = await fetchGuild(guild); + const userData = await fetchUser(author, guild); + + if (content.length < guildData.credits.minimumLength) return; + + await cooldown.message( + message, + guildData.credits.timeout, + "messageCreate-credits" + ); + + userData.credits += guildData.credits.rate; + + await userData + .save() + .then(async () => { + logger.silly( + `User ${userId} in guild ${guildId} has ${userData.credits} credits` + ); + }) + .catch(async (err) => { + logger.error( + `Error saving credits for user ${userId} in guild ${guildId} - ${err}` + ); + }); + }, +}; diff --git a/src/events/messageCreate/modules/index.ts b/src/plugins/events/messageCreate/modules/index.ts similarity index 100% rename from src/events/messageCreate/modules/index.ts rename to src/plugins/events/messageCreate/modules/index.ts diff --git a/src/plugins/events/messageCreate/modules/points/index.ts b/src/plugins/events/messageCreate/modules/points/index.ts new file mode 100644 index 0000000..4a4496b --- /dev/null +++ b/src/plugins/events/messageCreate/modules/points/index.ts @@ -0,0 +1,51 @@ +import logger from "../../../../../logger"; + +import * as cooldown from "../../../../../helpers/cooldown"; + +import fetchUser from "../../../../../helpers/fetchUser"; +import fetchGuild from "../../../../../helpers/fetchGuild"; + +import { Message } from "discord.js"; +export default { + execute: async (message: Message) => { + const { guild, author, content, channel } = message; + + if (guild == null) return; + if (author.bot) return; + if (channel?.type !== "GUILD_TEXT") return; + + const { id: guildId } = guild; + const { id: userId } = author; + + const guildData = await fetchGuild(guild); + const userData = await fetchUser(author, guild); + + if (content.length < guildData.credits.minimumLength) return; + + await cooldown.message( + message, + guildData.credits.timeout, + "messageCreate-points" + ); + + userData.points += guildData.points.rate; + + await userData + .save() + .then(async () => { + logger.silly( + `Successfully saved user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` + ); + }) + .catch(async (err) => { + logger.error( + `Error saving points for user ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})`, + err + ); + }); + + logger.silly( + `User ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id}) has ${userData.points} points` + ); + }, +}; diff --git a/src/events/messageDelete/audits.ts b/src/plugins/events/messageDelete/audits.ts similarity index 91% rename from src/events/messageDelete/audits.ts rename to src/plugins/events/messageDelete/audits.ts index 0b8698e..4b5d5a2 100644 --- a/src/events/messageDelete/audits.ts +++ b/src/plugins/events/messageDelete/audits.ts @@ -1,9 +1,9 @@ -import logger from "../../logger"; +import logger from "../../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (message: Message) => { diff --git a/src/events/messageDelete/index.ts b/src/plugins/events/messageDelete/index.ts similarity index 82% rename from src/events/messageDelete/index.ts rename to src/plugins/events/messageDelete/index.ts index 7279add..3cb7f6e 100644 --- a/src/events/messageDelete/index.ts +++ b/src/plugins/events/messageDelete/index.ts @@ -1,7 +1,7 @@ import { Message } from "discord.js"; import audits from "../../events/messageDelete/audits"; import counter from "./modules/counter"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", diff --git a/src/events/messageDelete/modules/counter.ts b/src/plugins/events/messageDelete/modules/counter.ts similarity index 90% rename from src/events/messageDelete/modules/counter.ts rename to src/plugins/events/messageDelete/modules/counter.ts index 7fa9e46..5681da8 100644 --- a/src/events/messageDelete/modules/counter.ts +++ b/src/plugins/events/messageDelete/modules/counter.ts @@ -2,8 +2,8 @@ import { Message } from "discord.js"; // Models -import counterSchema from "../../../models/counter"; -import logger from "../../../logger"; +import counterSchema from "../../../../models/counter"; +import logger from "../../../../logger"; export default async (message: Message) => { const { guild, channel, author, content } = message; diff --git a/src/events/messageUpdate/audits.ts b/src/plugins/events/messageUpdate/audits.ts similarity index 92% rename from src/events/messageUpdate/audits.ts rename to src/plugins/events/messageUpdate/audits.ts index db75a84..515a090 100644 --- a/src/events/messageUpdate/audits.ts +++ b/src/plugins/events/messageUpdate/audits.ts @@ -1,10 +1,10 @@ /* eslint-disable no-loops/no-loops */ -import logger from "../../logger"; +import logger from "../../../logger"; import { Message, MessageEmbed, TextChannel } from "discord.js"; -import guildSchema from "../../models/guild"; +import guildSchema from "../../../models/guild"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; +import getEmbedConfig from "../../../helpers/getEmbedConfig"; export default { execute: async (oldMessage: Message, newMessage: Message) => { diff --git a/src/events/messageUpdate/index.ts b/src/plugins/events/messageUpdate/index.ts similarity index 78% rename from src/events/messageUpdate/index.ts rename to src/plugins/events/messageUpdate/index.ts index 263d53e..23b5588 100644 --- a/src/events/messageUpdate/index.ts +++ b/src/plugins/events/messageUpdate/index.ts @@ -1,12 +1,12 @@ // Dependencies import { Message } from "discord.js"; -import logger from "../../logger"; +import logger from "../../../logger"; // Modules import counter from "./modules/counter"; import audits from "./audits"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "on", @@ -15,7 +15,7 @@ export const options: IEventOptions = { export const execute = async (oldMessage: Message, newMessage: Message) => { const { author, guild } = newMessage; - await audits.execute(oldMessage, newMessage); + // await audits.execute(oldMessage, newMessage); logger?.silly( `Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` diff --git a/src/events/messageUpdate/modules/counter.ts b/src/plugins/events/messageUpdate/modules/counter.ts similarity index 89% rename from src/events/messageUpdate/modules/counter.ts rename to src/plugins/events/messageUpdate/modules/counter.ts index 9a79118..03c60b9 100644 --- a/src/events/messageUpdate/modules/counter.ts +++ b/src/plugins/events/messageUpdate/modules/counter.ts @@ -2,8 +2,8 @@ import { Message } from "discord.js"; // Models -import counterSchema from "../../../models/counter"; -import logger from "../../../logger"; +import counterSchema from "../../../../models/counter"; +import logger from "../../../../logger"; export default async (message: Message) => { const { guild, channel, author, content } = message; diff --git a/src/plugins/events/rateLimit/index.ts b/src/plugins/events/rateLimit/index.ts new file mode 100644 index 0000000..8886c1a --- /dev/null +++ b/src/plugins/events/rateLimit/index.ts @@ -0,0 +1,14 @@ +// Dependencies +import { Client } from "discord.js"; +import logger from "../../../logger"; + +// Helpers +import { IEventOptions } from "../../../interfaces/EventOptions"; + +export const options: IEventOptions = { + type: "on", +}; + +export const execute = async (client: Client) => { + logger.warn("Discord's API client is rate-limited!"); +}; diff --git a/src/events/ready/index.ts b/src/plugins/events/ready/index.ts similarity index 53% rename from src/events/ready/index.ts rename to src/plugins/events/ready/index.ts index bd1e060..125bdc8 100644 --- a/src/events/ready/index.ts +++ b/src/plugins/events/ready/index.ts @@ -1,12 +1,12 @@ // Dependencies import { Client } from "discord.js"; -import logger from "../../logger"; +import logger from "../../../logger"; // Helpers -import updatePresence from "../../helpers/updatePresence"; -import deployCommands from "../../handlers/deployCommands"; -import devMode from "../../handlers/devMode"; -import { IEventOptions } from "../../interfaces/EventOptions"; +import updatePresence from "../../../helpers/updatePresence"; +import deployCommands from "../../../handlers/deployCommands"; +import devMode from "../../../handlers/devMode"; +import { IEventOptions } from "../../../interfaces/EventOptions"; export const options: IEventOptions = { type: "once", diff --git a/tsconfig.json b/tsconfig.json index 0879e1c..83ed3fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,21 +14,7 @@ "outDir": "./build", "resolveJsonModule": true, "baseUrl": "./src", - "typeRoots": ["/types/common", "./node_modules/@types"], - "paths": { - "@interface/*": ["interfaces/*"], - "@root/*": ["*"], - "@config/*": ["config/*"], - "@events/*": ["events/*"], - "@logger": ["logger"], - "@database": ["database"], - "@jobs/*": ["jobs/*"], - "@handlers/*": ["handlers/*"], - "@helpers/*": ["helpers/*"], - "@locale": ["locale"], - "@plugins/*": ["plugins/*"], - "@schemas/*": ["database/schemas/*"] - } + "typeRoots": ["/types/common", "./node_modules/@types"] }, "include": ["./src"], "exclude": ["./node_modules", "./test"] From 766dac5c9857ae3cb49139328e30baf95ab67b1a Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 10 Jun 2022 22:31:40 +0200 Subject: [PATCH 41/75] =?UTF-8?q?=F0=9F=A9=B9=20revert=20development=20cha?= =?UTF-8?q?nges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/buttons/primary/index.ts | 3 ++- src/plugins/events/messageUpdate/index.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/plugins/buttons/primary/index.ts b/src/plugins/buttons/primary/index.ts index bd71158..c1441db 100644 --- a/src/plugins/buttons/primary/index.ts +++ b/src/plugins/buttons/primary/index.ts @@ -1,7 +1,8 @@ import { CommandInteraction } from "discord.js"; +import logger from "../../../logger"; export const metadata = { guildOnly: false, ephemeral: false }; export const execute = async (interaction: CommandInteraction) => { - console.log("primary button clicked!"); + logger.debug("primary button clicked!"); }; diff --git a/src/plugins/events/messageUpdate/index.ts b/src/plugins/events/messageUpdate/index.ts index 23b5588..9c9bf47 100644 --- a/src/plugins/events/messageUpdate/index.ts +++ b/src/plugins/events/messageUpdate/index.ts @@ -15,7 +15,7 @@ export const options: IEventOptions = { export const execute = async (oldMessage: Message, newMessage: Message) => { const { author, guild } = newMessage; - // await audits.execute(oldMessage, newMessage); + await audits.execute(oldMessage, newMessage); logger?.silly( `Message update event fired by ${author.tag} (${author.id}) in guild: ${guild?.name} (${guild?.id})` From c4a70ae28c8ff76e3fcde6c801cdfac9be2a726b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 10 Jun 2022 23:06:23 +0200 Subject: [PATCH 42/75] =?UTF-8?q?=F0=9F=9A=B8=20Added=20button=20link=20fo?= =?UTF-8?q?r=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/utility/modules/about/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/commands/utility/modules/about/index.ts b/src/plugins/commands/utility/modules/about/index.ts index f89d74d..92af9cb 100644 --- a/src/plugins/commands/utility/modules/about/index.ts +++ b/src/plugins/commands/utility/modules/about/index.ts @@ -29,6 +29,11 @@ export default { .setStyle("LINK") .setEmoji("📄") .setURL("https://github.com/ZynerOrg/xyter"), + new MessageButton() + .setLabel("Documentation") + .setStyle("LINK") + .setEmoji("📚") + .setURL("https://xyter.zyner.org"), new MessageButton() .setLabel("Website") .setStyle("LINK") From a674f0328ce1326af8553974faf4fb4e0f52cf65 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 10 Jun 2022 23:07:19 +0200 Subject: [PATCH 43/75] =?UTF-8?q?=F0=9F=9A=B8=20README.md=20now=20only=20b?= =?UTF-8?q?adges,=20documentation=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 58 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index c6ca509..c73ca8a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
-

An multi-purpose bot built with discord.js

+

A privacy-focused bot built with discord.js

@@ -15,61 +15,7 @@

- About • - Features + Documentation • - Installation - • - License - • - Credits

- -## ❓ About - -Xyter is an open source, multi-purpose Discord bot that is develoepd by students. You can invite it to your Discord server using [this](https://bot.zyner.org) link! It comes packaged with a variety of commands and a multitude of settings that can be tailored to your server's specific needs. - -**To run this on Pterodactyl** please set startup command to `./node_modules/.bin/ts-node src/index.ts`! - -If you liked this repository, feel free to leave a star ⭐ to help promote Xyter! - -**For a more updated documentation visit [this site](https://xyter.zyner.org/)!** - -## ❗ Features - -**10+** commands and counting across **13** different categories! - -- 💰 **Credits**: `balance`, `gift`, `top`, `work`, `give`, `take`, `set` and `transfer`! -- 💬 **Counters**: `view`, `add`, `remove`! -- 🔨 **Settings**: `guild credits`, `guild pterodactyl`, `guild points` and `user appearence`! -- 👑 **Profile**: `view`! -- 🖼 **Reputation**: `give`! -- 💰 **Shop**: `roles buy`, `roles cancel` and `pterodactyl`! -- ❔ **Utilities**: `lookup`, `about` and `stats`! -- **Full list** of commands: [here](https://github.com/ZynerOrg/xyter/blob/master/docs/COMMANDS.md). - -Xyter also comes packed with a variety of features, such as: - -- **Slash Commands** -- **Multi-language support**. -- And much more! There are over **5+** settings to tweak! - -## 📝 To-Do - -- Bug fixes -- Code optimisation -- New discord features -- Suggestions we deem very good. - -Some more is available in issues - -## 📖 License - -Released under the [GPL-3.0 License](https://github.com/ZynerOrg/xyter/blob/master/LICENSE) license. - -## 📜 Credits - -- **[Vermium#9649](https://github.com/VermiumSifell)** - Founder, creator, hoster. -- **[Mastergamer433#5762](https://github.com/Mastergamer433)** - Work command for credits. -- Want to be on this list, aswell? - Check out the [Contributing page](https://github.com/ZynerOrg/xyter/blob/master/docs/CONTRIBUTING.md). From d98dccf397bb3eb9fbc9d452018c9b66933186c1 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Fri, 10 Jun 2022 23:07:42 +0200 Subject: [PATCH 44/75] =?UTF-8?q?=F0=9F=9A=B8=20set=20/shop=20cpgg=20amoun?= =?UTF-8?q?t=20required?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/shop/modules/cpgg/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/commands/shop/modules/cpgg/index.ts b/src/plugins/commands/shop/modules/cpgg/index.ts index aeee472..82ee508 100644 --- a/src/plugins/commands/shop/modules/cpgg/index.ts +++ b/src/plugins/commands/shop/modules/cpgg/index.ts @@ -29,6 +29,7 @@ export default { option .setName("amount") .setDescription("How much credits you want to withdraw.") + .setRequired(true) ); }, execute: async (interaction: CommandInteraction) => { From 46bb4b6f6d9b1e282ee7402d802d3316644e2a7d Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:24:21 +0200 Subject: [PATCH 45/75] =?UTF-8?q?=F0=9F=9A=9A=20move=20timeouts=20job=20in?= =?UTF-8?q?to=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jobs/{timeouts.ts => timeouts/index.ts} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/jobs/{timeouts.ts => timeouts/index.ts} (84%) diff --git a/src/jobs/timeouts.ts b/src/jobs/timeouts/index.ts similarity index 84% rename from src/jobs/timeouts.ts rename to src/jobs/timeouts/index.ts index 3198772..ce18f09 100644 --- a/src/jobs/timeouts.ts +++ b/src/jobs/timeouts/index.ts @@ -1,8 +1,8 @@ -import logger from "../logger"; +import logger from "../../logger"; -import timeoutSchema from "../models/timeout"; +import timeoutSchema from "../../models/timeout"; -import addSeconds from "../helpers/addSeconds"; +import addSeconds from "../../helpers/addSeconds"; export const options = { schedule: "*/30 * * * *", // https://crontab.guru/ From 8e59690fe0c0a59021ae2a90ebd5734d155413b7 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:24:56 +0200 Subject: [PATCH 46/75] =?UTF-8?q?=F0=9F=9A=9A=20deployCommands=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{deployCommands.ts => deployCommands/index.ts} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/handlers/{deployCommands.ts => deployCommands/index.ts} (88%) diff --git a/src/handlers/deployCommands.ts b/src/handlers/deployCommands/index.ts similarity index 88% rename from src/handlers/deployCommands.ts rename to src/handlers/deployCommands/index.ts index 4542377..492e1ab 100644 --- a/src/handlers/deployCommands.ts +++ b/src/handlers/deployCommands/index.ts @@ -1,13 +1,13 @@ -import { token, clientId } from "../config/discord"; -import { devMode, guildId } from "../config/other"; +import { token, clientId } from "../../config/discord"; +import { devMode, guildId } from "../../config/other"; -import logger from "../logger"; +import logger from "../../logger"; import { Client } from "discord.js"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10"; -import { ICommand } from "../interfaces/Command"; +import { ICommand } from "../../interfaces/Command"; export default async (client: Client) => { const commandList: Array = []; From c0b036bd4d4fddf8dd8f51c45f24b8ab68009716 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:25:16 +0200 Subject: [PATCH 47/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20devMode=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/{devMode.ts => devMode/index.ts} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/handlers/{devMode.ts => devMode/index.ts} (79%) diff --git a/src/handlers/devMode.ts b/src/handlers/devMode/index.ts similarity index 79% rename from src/handlers/devMode.ts rename to src/handlers/devMode/index.ts index 764fbcf..c7900a0 100644 --- a/src/handlers/devMode.ts +++ b/src/handlers/devMode/index.ts @@ -1,10 +1,10 @@ // Dependencies import { Client } from "discord.js"; -import logger from "../logger"; +import logger from "../../logger"; // Configuration -import { devMode, guildId } from "../config/other"; +import { devMode, guildId } from "../../config/other"; export default async (client: Client) => { if (!devMode) { From 9fb4f24427bfa0771fdb3e789401d19a2494ef62 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:25:34 +0200 Subject: [PATCH 48/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20encryption=20Foldefo?= =?UTF-8?q?lder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/{encryption.ts => encryption/index.ts} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/handlers/{encryption.ts => encryption/index.ts} (84%) diff --git a/src/handlers/encryption.ts b/src/handlers/encryption/index.ts similarity index 84% rename from src/handlers/encryption.ts rename to src/handlers/encryption/index.ts index de5a7b9..8b6512c 100644 --- a/src/handlers/encryption.ts +++ b/src/handlers/encryption/index.ts @@ -1,8 +1,8 @@ import crypto from "crypto"; -import { secretKey, algorithm } from "../config/encryption"; +import { secretKey, algorithm } from "../../config/encryption"; -import { IEncryptionData } from "../interfaces/EncryptionData"; +import { IEncryptionData } from "../../interfaces/EncryptionData"; const iv = crypto.randomBytes(16); From 827678dfcf259cc06c24cdc6a7543076fe7f328e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:26:06 +0200 Subject: [PATCH 49/75] =?UTF-8?q?=F0=9F=8E=A8=20remove=20unnessecery=20if?= =?UTF-8?q?=20statement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/addSeconds/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/helpers/addSeconds/index.ts b/src/helpers/addSeconds/index.ts index 91bff4e..6c47b18 100644 --- a/src/helpers/addSeconds/index.ts +++ b/src/helpers/addSeconds/index.ts @@ -1,7 +1,4 @@ -export default async (numOfSeconds: number, date: Date) => { - if (!numOfSeconds) throw new Error("numOfSeconds is required"); - - date.setSeconds(date.getSeconds() + numOfSeconds); - +export default async (seconds: number, date: Date) => { + date.setSeconds(date.getSeconds() + seconds); return date; }; From f56f33e215083a21d36e3de397ab2767cfaf5b5b Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:27:23 +0200 Subject: [PATCH 50/75] =?UTF-8?q?=F0=9F=8E=A8=20getEmbedConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/getEmbedConfig/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/helpers/getEmbedConfig/index.ts b/src/helpers/getEmbedConfig/index.ts index 22ddf29..ccd3fdb 100644 --- a/src/helpers/getEmbedConfig/index.ts +++ b/src/helpers/getEmbedConfig/index.ts @@ -3,18 +3,16 @@ import * as embedConfig from "../../config/embed"; import { Guild } from "discord.js"; -export default async (guild: Guild | null) => { - if (guild == null) - return { - ...embedConfig, - }; +export default async (guild?: Guild | null) => { + if (!guild) { + return { ...embedConfig }; + } const guildConfig = await guildSchema.findOne({ guildId: guild.id }); - - if (guildConfig == null) + if (!guildConfig) { return { ...embedConfig, }; - + } return guildConfig.embeds; }; From 40e434f5c67820f92190df5833b3b44f89294b44 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:28:07 +0200 Subject: [PATCH 51/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20e=20i?= =?UTF-8?q?s=20now=20err?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/listDir/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/listDir/index.ts b/src/helpers/listDir/index.ts index 95ed1da..382e41d 100644 --- a/src/helpers/listDir/index.ts +++ b/src/helpers/listDir/index.ts @@ -2,7 +2,7 @@ import fs from "fs"; const fsPromises = fs.promises; export default async (path: string) => { - return fsPromises.readdir(path).catch(async (e) => { - throw new Error(`Could not list directory: ${path}`, e); + return fsPromises.readdir(path).catch(async (err) => { + throw new Error(`Could not list directory: ${path}`, err); }); }; From d0f2cd3027cb139dbe77272fbcaefb84e84a4746 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 18:28:33 +0200 Subject: [PATCH 52/75] =?UTF-8?q?=F0=9F=8E=A8=20remove=20newlines=20when?= =?UTF-8?q?=20not=20logical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/updatePresence/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/helpers/updatePresence/index.ts b/src/helpers/updatePresence/index.ts index a8c4a35..334a3e2 100644 --- a/src/helpers/updatePresence/index.ts +++ b/src/helpers/updatePresence/index.ts @@ -5,15 +5,12 @@ import logger from "../../logger"; // Function export default async (client: Client) => { if (!client?.user) throw new Error("Client's user is undefined."); - const { guilds } = client; const memberCount = guilds.cache.reduce((a, g) => a + g.memberCount, 0); - const guildCount = guilds.cache.size; const status = `${memberCount} users in ${guildCount} guilds.`; - client.user.setPresence({ activities: [{ type: "LISTENING", name: status }], status: "online", From e94b48a6d2ce63dd7ff7d5bdd9213bc8654a2874 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 19:42:30 +0200 Subject: [PATCH 53/75] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Mongoose=20ShopRo?= =?UTF-8?q?le=20Interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/ShopRole.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/interfaces/ShopRole.ts diff --git a/src/interfaces/ShopRole.ts b/src/interfaces/ShopRole.ts new file mode 100644 index 0000000..ec62cfd --- /dev/null +++ b/src/interfaces/ShopRole.ts @@ -0,0 +1,9 @@ +import { Snowflake } from "discord.js"; +import { Document } from "mongoose"; + +export interface IShopRole extends Document { + guildId: Snowflake; + userId: Snowflake; + roleId: Snowflake; + lastPayed: Date; +} From f70bbc9171aa096c74b33623d04b55ef08fdd589 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 19:45:07 +0200 Subject: [PATCH 54/75] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20shopR?= =?UTF-8?q?oles=20job=20splitted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jobs/shop/index.ts | 12 ++ .../modules/roles/components/dueForPayment.ts | 10 ++ .../roles/components/overDueForPayment.ts | 85 +++++++++++++ src/jobs/shop/modules/roles/index.ts | 32 +++++ src/jobs/shopRoles.ts | 114 ------------------ 5 files changed, 139 insertions(+), 114 deletions(-) create mode 100644 src/jobs/shop/index.ts create mode 100644 src/jobs/shop/modules/roles/components/dueForPayment.ts create mode 100644 src/jobs/shop/modules/roles/components/overDueForPayment.ts create mode 100644 src/jobs/shop/modules/roles/index.ts delete mode 100644 src/jobs/shopRoles.ts diff --git a/src/jobs/shop/index.ts b/src/jobs/shop/index.ts new file mode 100644 index 0000000..d2f76d1 --- /dev/null +++ b/src/jobs/shop/index.ts @@ -0,0 +1,12 @@ +// Dependencies +import { Client } from "discord.js"; + +import * as roles from "./modules/roles"; + +export const options = { + schedule: "*/5 * * * * *", // https://crontab.guru/ +}; + +export const execute = async (client: Client) => { + await roles.execute(client); +}; diff --git a/src/jobs/shop/modules/roles/components/dueForPayment.ts b/src/jobs/shop/modules/roles/components/dueForPayment.ts new file mode 100644 index 0000000..ad8a59c --- /dev/null +++ b/src/jobs/shop/modules/roles/components/dueForPayment.ts @@ -0,0 +1,10 @@ +import { Client } from "discord.js"; +import logger from "../../../../../logger"; + +import { IShopRole } from "../../../../../interfaces/ShopRole"; + +export const execute = async (_client: Client, role: IShopRole) => { + const { roleId } = role; + + logger.silly(`Shop role ${roleId} is not due for payment.`); +}; diff --git a/src/jobs/shop/modules/roles/components/overDueForPayment.ts b/src/jobs/shop/modules/roles/components/overDueForPayment.ts new file mode 100644 index 0000000..77ab6e0 --- /dev/null +++ b/src/jobs/shop/modules/roles/components/overDueForPayment.ts @@ -0,0 +1,85 @@ +import { Client } from "discord.js"; +import logger from "../../../../../logger"; + +import { IShopRole } from "../../../../../interfaces/ShopRole"; +import guildSchema from "../../../../../models/guild"; +import userSchema from "../../../../../models/user"; +import shopRoleSchema from "../../../../../models/shopRole"; + +export const execute = async (client: Client, role: IShopRole) => { + const { guildId, userId, roleId } = role; + if (!userId) throw new Error("User ID not found for shop role."); + + const guildData = await guildSchema.findOne({ guildId }); + if (!guildData) throw new Error("Guild not found."); + + const userData = await userSchema.findOne({ guildId, userId }); + if (!userData) throw new Error("User not found."); + + const rGuild = client.guilds.cache.get(guildId); + if (!rGuild) throw new Error("Guild not found."); + + const rMember = await rGuild.members.fetch(userId); + if (!rMember) throw new Error("Member not found."); + + const rRole = rMember.roles.cache.get(roleId); + if (!rRole) throw new Error("Role not found."); + + logger.debug(`Shop role ${roleId} is due for payment.`); + + const { pricePerHour } = guildData.shop.roles; + + if (userData.credits < pricePerHour) { + await rMember.roles + .remove(roleId) + .then(async () => { + await shopRoleSchema + .deleteOne({ + userId, + roleId, + guildId, + }) + .then(async () => { + logger.silly( + `Shop role document ${roleId} has been deleted from user ${userId}.` + ); + }) + .catch(async (err) => { + throw new Error( + `Error deleting shop role document ${roleId} from user ${userId}.`, + err + ); + }); + }) + .catch(async (err) => { + throw new Error( + `Error removing role ${roleId} from user ${userId}.`, + err + ); + }); + + throw new Error("User does not have enough credits."); + } + + userData.credits -= pricePerHour; + await userData + .save() + .then(async () => { + logger.silly(`User ${userId} has been updated.`); + + role.lastPayed = new Date(); + await role + .save() + .then(async () => { + logger.silly(`Shop role ${roleId} has been updated.`); + }) + .catch(async (err) => { + throw new Error(`Error updating shop role ${roleId}.`, err); + }); + + logger.debug(`Shop role ${roleId} has been paid.`); + }) + .catch(async (err) => { + throw new Error(`Error updating user ${userId}.`, err); + }); +}; diff --git a/src/jobs/shop/modules/roles/index.ts b/src/jobs/shop/modules/roles/index.ts new file mode 100644 index 0000000..c8e393a --- /dev/null +++ b/src/jobs/shop/modules/roles/index.ts @@ -0,0 +1,32 @@ +import { Client } from "discord.js"; + +import { IShopRole } from "../../../../interfaces/ShopRole"; +import shopRoleSchema from "../../../../models/shopRole"; + +import * as overDueForPayment from "./components/overDueForPayment"; +import * as dueForPayment from "./components/dueForPayment"; + +export const execute = async (client: Client) => { + const roles = await shopRoleSchema.find(); + + await Promise.all( + roles.map(async (role: IShopRole) => { + const { lastPayed } = role; + const nextPayment = new Date( + lastPayed.setHours(lastPayed.getHours() + 1) + ); + + const now = new Date(); + + if (nextPayment > now) { + await dueForPayment.execute(client, role); + + return; + } + + if (nextPayment < now) { + await overDueForPayment.execute(client, role); + } + }) + ); +}; diff --git a/src/jobs/shopRoles.ts b/src/jobs/shopRoles.ts deleted file mode 100644 index e9ed502..0000000 --- a/src/jobs/shopRoles.ts +++ /dev/null @@ -1,114 +0,0 @@ -// Dependencies -import { Client } from "discord.js"; - -import logger from "../logger"; - -// Schemas -import userSchema from "../models/user"; -import shopRoleSchema from "../models/shopRole"; -import guildSchema from "../models/guild"; - -export const options = { - schedule: "*/5 * * * *", // https://crontab.guru/ -}; - -export const execute = async (client: Client) => { - const roles = await shopRoleSchema.find(); - await Promise.all( - roles.map(async (role) => { - const { guildId, userId, roleId } = role; - const lastPayment = new Date(role.lastPayed); - const nextPayment = new Date( - lastPayment.setHours(lastPayment.getHours() + 1) - ); - if (new Date() < nextPayment) { - logger.silly(`Shop role ${roleId} is not due for payment.`); - } - const guildData = await guildSchema.findOne({ guildId }); - if (!guildData) { - logger.error(`Guild ${guildId} not found.`); - return; - } - if (!userId) { - logger.error(`User ID not found for shop role ${roleId}.`); - return; - } - const userData = await userSchema.findOne({ guildId, userId }); - if (!userData) { - logger.error(`User ${userId} not found for shop role ${roleId}.`); - return; - } - const rGuild = client?.guilds?.cache?.get(guildId); - const rMember = await rGuild?.members?.fetch(userId); - if (!rMember) { - logger.error(`Member ${userId} not found for shop role ${roleId}.`); - return; - } - const rRole = rMember.roles.cache.get(roleId); - if (!rMember || !rRole) { - logger.error(`Member ${userId} not found for shop role ${roleId}.`); - await shopRoleSchema - .deleteOne({ - userId, - roleId, - guildId, - }) - .then(async () => { - logger.silly( - `Shop role document ${roleId} has been deleted from user ${userId}.` - ); - }) - .catch(async (error) => { - logger.error( - `Error deleting shop role document ${roleId} from user ${userId}.`, - error - ); - }); - return; - } - if (new Date() > nextPayment) { - logger.silly( - `Shop role ${roleId} is due for payment. Withdrawing credits from user ${userId}.` - ); - const { pricePerHour } = guildData.shop.roles; - if (userData.credits < pricePerHour) { - logger.error( - `User ${userId} does not have enough credits to pay for shop role ${roleId}.` - ); - if (!rMember) { - logger.error(`Member ${userId} not found for shop role ${roleId}.`); - return; - } - rMember.roles.remove(roleId); - return; - } - userData.credits -= pricePerHour; - await userData - .save() - .then(async () => { - role.lastPayed = new Date(); - await role - .save() - .then(async () => { - logger.silly(`Shop role ${roleId} has been paid for.`); - }) - .catch(async (err) => { - logger.error( - `Error saving shop role ${roleId} last payed date.`, - err - ); - }); - logger.silly( - `Shop role ${roleId} has been paid for. Keeping role ${roleId} for user ${userId}.` - ); - }) - .catch(async (err) => { - logger.error( - `Error saving user ${userId} credits for shop role ${roleId}.`, - err - ); - }); - } - }) - ); -}; From e1ae56e36004ab7e2e38d70e07fd9c091c01b365 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 21:58:54 +0200 Subject: [PATCH 55/75] =?UTF-8?q?=F0=9F=92=AC=20Repliable=20to=20wordlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cspell/custom-dictionary-workspace.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index d754312..f5e0cc5 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -23,6 +23,7 @@ pino Poäng Profil rando +Repliable satta senaste Sifell From 24e44f723517a0134bb8a8ece16bc2893df3cee2 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sat, 11 Jun 2022 21:59:47 +0200 Subject: [PATCH 56/75] =?UTF-8?q?=E2=9C=A8=20button=20cooldowns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/cooldown/index.ts | 61 +++++++-- src/helpers/deferReply/index.ts | 17 +-- src/jobs/shop/index.ts | 2 +- src/models/api.ts | 21 +-- .../commands/credits/modules/top/index.ts | 2 +- .../commands/credits/modules/work/index.ts | 2 +- .../modules/credits/modules/giveaway/index.ts | 6 +- .../commands/reputation/modules/give/index.ts | 2 +- .../commands/shop/modules/cpgg/index.ts | 5 +- .../interactionCreate/components/checks.ts | 51 -------- .../interactionCreate/components/isButton.ts | 123 ------------------ .../interactionCreate/components/isCommand.ts | 48 ------- .../handlers/button/index.ts | 36 +++++ .../handlers/command/index.ts | 34 +++++ .../interactionCreate/handlers/index.ts | 11 ++ src/plugins/events/interactionCreate/index.ts | 15 +-- 16 files changed, 173 insertions(+), 263 deletions(-) delete mode 100644 src/plugins/events/interactionCreate/components/checks.ts delete mode 100644 src/plugins/events/interactionCreate/components/isButton.ts delete mode 100644 src/plugins/events/interactionCreate/components/isCommand.ts create mode 100644 src/plugins/events/interactionCreate/handlers/button/index.ts create mode 100644 src/plugins/events/interactionCreate/handlers/command/index.ts create mode 100644 src/plugins/events/interactionCreate/handlers/index.ts diff --git a/src/helpers/cooldown/index.ts b/src/helpers/cooldown/index.ts index 2417d81..45d2729 100644 --- a/src/helpers/cooldown/index.ts +++ b/src/helpers/cooldown/index.ts @@ -1,5 +1,5 @@ // Dependencies -import { CommandInteraction, Message } from "discord.js"; +import { CommandInteraction, ButtonInteraction, Message } from "discord.js"; import logger from "../../logger"; @@ -7,7 +7,7 @@ import getEmbedConfig from "../../helpers/getEmbedConfig"; import timeoutSchema from "../../models/timeout"; import addSeconds from "../../helpers/addSeconds"; -export const interaction = async (i: CommandInteraction, cooldown: number) => { +export const command = async (i: CommandInteraction, cooldown: number) => { const { guild, user, commandId } = i; // Check if user has a timeout @@ -56,12 +56,57 @@ export const interaction = async (i: CommandInteraction, cooldown: number) => { }); }; -export const message = async ( - message: Message, - cooldown: number, - id: string -) => { - const { guild, member } = message; +export const button = async (i: ButtonInteraction, cooldown: number) => { + const { guild, user, customId } = i; + + // Check if user has a timeout + const hasTimeout = await timeoutSchema.findOne({ + guildId: guild?.id || "0", + userId: user.id, + cooldown: cooldown, + timeoutId: customId, + }); + + // If user is not on timeout + if (hasTimeout) { + const { guildId, userId, timeoutId, createdAt } = hasTimeout; + const overDue = (await addSeconds(cooldown, createdAt)) < new Date(); + + if (!overDue) { + const diff = Math.round( + (new Date(hasTimeout.createdAt).getTime() - new Date().getTime()) / 1000 + ); + + throw new Error( + `You must wait ${diff} seconds before using this command.` + ); + } + + // Delete timeout + await timeoutSchema + .deleteOne({ + guildId, + userId, + timeoutId, + cooldown, + }) + .then(async () => { + logger.debug( + `Timeout document ${timeoutId} has been deleted from user ${userId}.` + ); + }); + } + // Create timeout + await timeoutSchema.create({ + guildId: guild?.id || "0", + userId: user.id, + cooldown: cooldown, + timeoutId: customId, + }); +}; + +export const message = async (msg: Message, cooldown: number, id: string) => { + const { guild, member } = msg; if (!guild) throw new Error("Guild is undefined"); if (!member) throw new Error("Member is undefined"); diff --git a/src/helpers/deferReply/index.ts b/src/helpers/deferReply/index.ts index b5cfdc3..02cc413 100644 --- a/src/helpers/deferReply/index.ts +++ b/src/helpers/deferReply/index.ts @@ -1,25 +1,26 @@ -import { CommandInteraction, MessageEmbed } from "discord.js"; +import { Interaction, MessageEmbed } from "discord.js"; import getEmbedConfig from "../../helpers/getEmbedConfig"; -export default async (interaction: CommandInteraction, ephemeral: boolean) => { +export default async (interaction: Interaction, ephemeral: boolean) => { + if (!interaction.isRepliable()) + throw new Error(`Cannot reply to an interaction that is not repliable`); + await interaction.deferReply({ ephemeral, }); - const { waitColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); + const embedConfig = await getEmbedConfig(interaction.guild); await interaction.editReply({ embeds: [ new MessageEmbed() .setFooter({ - text: footerText, - iconURL: footerIcon, + text: embedConfig.footerText, + iconURL: embedConfig.footerIcon, }) .setTimestamp(new Date()) .setTitle("Processing your request") - .setColor(waitColor) + .setColor(embedConfig.waitColor) .setDescription("Please wait..."), ], }); diff --git a/src/jobs/shop/index.ts b/src/jobs/shop/index.ts index d2f76d1..b2ef366 100644 --- a/src/jobs/shop/index.ts +++ b/src/jobs/shop/index.ts @@ -4,7 +4,7 @@ import { Client } from "discord.js"; import * as roles from "./modules/roles"; export const options = { - schedule: "*/5 * * * * *", // https://crontab.guru/ + schedule: "*/5 * * * *", // https://crontab.guru/ }; export const execute = async (client: Client) => { diff --git a/src/models/api.ts b/src/models/api.ts index d3690df..fd5cbd7 100644 --- a/src/models/api.ts +++ b/src/models/api.ts @@ -4,7 +4,7 @@ import { IEncryptionData } from "../interfaces/EncryptionData"; export interface IApi { guildId: Snowflake; - url: string; + url: IEncryptionData; token: IEncryptionData; } @@ -17,11 +17,18 @@ const apiSchema = new Schema( index: true, }, url: { - type: String, - required: true, - unique: false, - index: true, - default: "https://localhost/api/", + iv: { + type: String, + required: true, + unique: false, + index: true, + }, + content: { + type: String, + required: true, + unique: false, + index: true, + }, }, token: { iv: { @@ -29,14 +36,12 @@ const apiSchema = new Schema( required: true, unique: false, index: true, - default: "token", }, content: { type: String, required: true, unique: false, index: true, - default: "token", }, }, }, diff --git a/src/plugins/commands/credits/modules/top/index.ts b/src/plugins/commands/credits/modules/top/index.ts index 29aadda..54478aa 100644 --- a/src/plugins/commands/credits/modules/top/index.ts +++ b/src/plugins/commands/credits/modules/top/index.ts @@ -54,7 +54,7 @@ export default { embeds: [ embed .setDescription( - `Below are the top 10 users in this guild. + `Below are the top ten members in this guild. ${topTen.map(entry).join("\n")} ` diff --git a/src/plugins/commands/credits/modules/work/index.ts b/src/plugins/commands/credits/modules/work/index.ts index a84a696..ef0a550 100644 --- a/src/plugins/commands/credits/modules/work/index.ts +++ b/src/plugins/commands/credits/modules/work/index.ts @@ -45,7 +45,7 @@ export default { const guildDB = await fetchGuild(guild); - await cooldown.interaction(interaction, guildDB?.credits?.workTimeout); + await cooldown.command(interaction, guildDB?.credits?.workTimeout); const creditsEarned = chance.integer({ min: 0, diff --git a/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts index 9ee2f17..acb73cb 100644 --- a/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts @@ -75,14 +75,16 @@ export default { if (!apiCredentials) return; + const url = encryption.decrypt(apiCredentials?.url); + const api = axios?.create({ - baseURL: `${apiCredentials?.url}/api/`, + baseURL: `${url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`, }, }); - const shopUrl = `${apiCredentials?.url}/store`; + const shopUrl = `${url}/store`; await api .post("vouchers", { diff --git a/src/plugins/commands/reputation/modules/give/index.ts b/src/plugins/commands/reputation/modules/give/index.ts index c899ecb..eb58abe 100644 --- a/src/plugins/commands/reputation/modules/give/index.ts +++ b/src/plugins/commands/reputation/modules/give/index.ts @@ -52,7 +52,7 @@ export default { await noSelfReputation(optionTarget, user); // Check if user is on cooldown otherwise create one - await cooldown.interaction(interaction, timeout); + await cooldown.command(interaction, timeout); switch (optionType) { case "positive": diff --git a/src/plugins/commands/shop/modules/cpgg/index.ts b/src/plugins/commands/shop/modules/cpgg/index.ts index 82ee508..90dbe70 100644 --- a/src/plugins/commands/shop/modules/cpgg/index.ts +++ b/src/plugins/commands/shop/modules/cpgg/index.ts @@ -153,15 +153,16 @@ export default { }); if (!apiCredentials) return; + const url = encryption.decrypt(apiCredentials?.url); const api = axios?.create({ - baseURL: `${apiCredentials.url}/api/`, + baseURL: `${url}/api/`, headers: { Authorization: `Bearer ${encryption.decrypt(apiCredentials.token)}`, }, }); - const shopUrl = `${apiCredentials?.url}/store`; + const shopUrl = `${url}/store`; const buttons = new MessageActionRow().addComponents( new MessageButton() diff --git a/src/plugins/events/interactionCreate/components/checks.ts b/src/plugins/events/interactionCreate/components/checks.ts deleted file mode 100644 index 006a14f..0000000 --- a/src/plugins/events/interactionCreate/components/checks.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { CommandInteraction, MessageEmbed } from "discord.js"; -import * as cooldown from "../../../../helpers/cooldown"; -import logger from "../../../../logger"; - -export default async ( - interaction: CommandInteraction, - metadata: any, - embedConfig: any -) => { - if ( - metadata.permissions && - metadata.guildOnly && - !interaction.memberPermissions?.has(metadata.permissions) - ) { - return interaction?.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription(`You do not have the permission to manage the bot.`) - .setTimestamp(new Date()) - .setColor(embedConfig.errorColor) - .setFooter({ - text: embedConfig.footerText, - iconURL: embedConfig.footerIcon, - }), - ], - }); - } - - logger.info(metadata); - - if (metadata.cooldown) { - await cooldown - .interaction(interaction, metadata.cooldown) - .catch(async (error) => { - throw new Error("Cooldown error: " + error); - }); - } - - if (metadata.guildOnly) { - if (!interaction.guild) { - throw new Error("This command is guild only."); - } - } - - if (metadata.dmOnly) { - if (interaction.guild) { - throw new Error("This command is DM only."); - } - } -}; diff --git a/src/plugins/events/interactionCreate/components/isButton.ts b/src/plugins/events/interactionCreate/components/isButton.ts deleted file mode 100644 index eaf1605..0000000 --- a/src/plugins/events/interactionCreate/components/isButton.ts +++ /dev/null @@ -1,123 +0,0 @@ -// Dependencies -import { CommandInteraction, MessageEmbed } from "discord.js"; - -import logger from "../../../../logger"; - -import deferReply from "../../../../helpers/deferReply"; -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; -import capitalizeFirstLetter from "../../../../helpers/capitalizeFirstLetter"; -import * as cooldown from "../../../../helpers/cooldown"; - -export default async (interaction: CommandInteraction) => { - if (!interaction.isButton()) return; - - const { errorColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - - const { guild, customId, user, memberPermissions } = interaction; - - const currentButton = await import(`../../../buttons/${customId}`); - - if (currentButton == null) { - logger.silly(`Button ${customId} not found`); - } - - const metadata = currentButton.metadata; - - await deferReply(interaction, metadata.ephemeral || false); - - if (metadata.guildOnly) { - if (!guild) { - logger.debug(`Guild is null`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription("This command is only available for guild") - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - } - - if ( - metadata.permissions && - metadata.guildOnly && - !memberPermissions?.has(metadata.permissions) - ) { - return interaction?.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription(`You do not have the permission to manage the bot.`) - .setTimestamp(new Date()) - .setColor(errorColor) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - - if (metadata.dmOnly) { - if (guild) { - logger.silly(`Guild exist`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription("This command is only available in DM.") - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - } - } - - if (metadata.cooldown) { - await cooldown - .interaction(interaction, metadata.cooldown) - .catch(async (error) => { - return interaction?.editReply({ - embeds: [ - new MessageEmbed() - .setTitle("[:x:] Permission") - .setDescription(`${error}`) - .setTimestamp(new Date()) - .setColor(errorColor) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - }); - } - - await currentButton - .execute(interaction) - .then(async () => { - return logger?.silly( - `Button: ${customId} executed in guild: ${guild?.name} (${guild?.id}) by user: ${user?.tag} (${user?.id})` - ); - }) - .catch(async (error: string) => { - logger?.debug(`INTERACTION BUTTON CATCH: ${error}`); - - return interaction.editReply({ - embeds: [ - new MessageEmbed() - .setTitle( - `[:x:] ${capitalizeFirstLetter( - interaction.options.getSubcommand() - )}` - ) - .setDescription(`${"``"}${error}${"``"}`) - .setColor(errorColor) - .setTimestamp(new Date()) - .setFooter({ text: footerText, iconURL: footerIcon }), - ], - }); - }); -}; diff --git a/src/plugins/events/interactionCreate/components/isCommand.ts b/src/plugins/events/interactionCreate/components/isCommand.ts deleted file mode 100644 index 3a14ad6..0000000 --- a/src/plugins/events/interactionCreate/components/isCommand.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Dependencies -import { CommandInteraction, MessageEmbed } from "discord.js"; - -import logger from "../../../../logger"; - -import deferReply from "../../../../helpers/deferReply"; -import getEmbedConfig from "../../../../helpers/getEmbedConfig"; -import getCommandMetadata from "../../../../helpers/getCommandMetadata"; -import capitalizeFirstLetter from "../../../../helpers/capitalizeFirstLetter"; -import * as cooldown from "../../../../helpers/cooldown"; - -export default async (interaction: CommandInteraction) => { - if (!interaction.isCommand()) return; - - const { errorColor, footerText, footerIcon } = await getEmbedConfig( - interaction.guild - ); - - const { client, guild, commandName, user, memberPermissions } = interaction; - - const currentCommand = client.commands.get(commandName); - - if (currentCommand == null) { - logger.silly(`Command ${commandName} not found`); - } - - const metadata = await getCommandMetadata(interaction, currentCommand); - - await deferReply(interaction, metadata.ephemeral || false); - - if (metadata.guildOnly && !guild) - throw new Error("This command is guild only."); - - if ( - metadata.permissions && - metadata.guildOnly && - !memberPermissions?.has(metadata.permissions) - ) - throw new Error("You don't have the required permissions"); - - if (metadata.dmOnly && guild) - throw new Error("This command is only available in DM"); - - if (metadata.cooldown) - await cooldown.interaction(interaction, metadata.cooldown); - - await currentCommand.execute(interaction); -}; diff --git a/src/plugins/events/interactionCreate/handlers/button/index.ts b/src/plugins/events/interactionCreate/handlers/button/index.ts new file mode 100644 index 0000000..3373f09 --- /dev/null +++ b/src/plugins/events/interactionCreate/handlers/button/index.ts @@ -0,0 +1,36 @@ +// Dependencies +import { Interaction } from "discord.js"; + +import deferReply from "../../../../../helpers/deferReply"; +import * as cooldown from "../../../../../helpers/cooldown"; + +export default async (interaction: Interaction) => { + if (!interaction.isButton()) return; + + const { guild, customId, memberPermissions } = interaction; + + const currentButton = await import(`../../../buttons/${customId}`); + + if (!currentButton) throw new Error(`Unknown button ${customId}`); + + const metadata = currentButton.metadata; + + await deferReply(interaction, metadata.ephemeral || false); + + if (metadata.guildOnly && !guild) + throw new Error("This command is guild only."); + + if ( + metadata.permissions && + metadata.guildOnly && + !memberPermissions?.has(metadata.permissions) + ) + throw new Error("You don't have the required permissions"); + + if (metadata.dmOnly && guild) + throw new Error("This command is only available in DM"); + + if (metadata.cooldown) await cooldown.button(interaction, metadata.cooldown); + + await currentButton.execute(interaction); +}; diff --git a/src/plugins/events/interactionCreate/handlers/command/index.ts b/src/plugins/events/interactionCreate/handlers/command/index.ts new file mode 100644 index 0000000..b6b30ec --- /dev/null +++ b/src/plugins/events/interactionCreate/handlers/command/index.ts @@ -0,0 +1,34 @@ +// Dependencies +import { Interaction } from "discord.js"; + +import deferReply from "../../../../../helpers/deferReply"; +import getCommandMetadata from "../../../../../helpers/getCommandMetadata"; +import * as cooldown from "../../../../../helpers/cooldown"; + +export default async (interaction: Interaction) => { + if (!interaction.isCommand()) return; + const { client, commandName } = interaction; + + const currentCommand = client.commands.get(commandName); + if (!currentCommand) throw new Error(`Unknown command ${commandName}`); + + const metadata = await getCommandMetadata(interaction, currentCommand); + await deferReply(interaction, metadata.ephemeral || false); + + if (metadata.guildOnly && !interaction.guild) + throw new Error("This command is guild only."); + + if ( + metadata.permissions && + metadata.guildOnly && + !interaction.memberPermissions?.has(metadata.permissions) + ) + throw new Error("You don't have the required permissions"); + + if (metadata.dmOnly && interaction.guild) + throw new Error("This command is only available in DM"); + + if (metadata.cooldown) await cooldown.command(interaction, metadata.cooldown); + + await currentCommand.execute(interaction); +}; diff --git a/src/plugins/events/interactionCreate/handlers/index.ts b/src/plugins/events/interactionCreate/handlers/index.ts new file mode 100644 index 0000000..c29bfc3 --- /dev/null +++ b/src/plugins/events/interactionCreate/handlers/index.ts @@ -0,0 +1,11 @@ +import { Interaction } from "discord.js"; + +import button from "./button"; +import command from "./command"; + +import logger from "../../../../logger"; + +export const execute = async (interaction: Interaction) => { + await button(interaction); + await command(interaction); +}; diff --git a/src/plugins/events/interactionCreate/index.ts b/src/plugins/events/interactionCreate/index.ts index f7365ec..aa6e763 100644 --- a/src/plugins/events/interactionCreate/index.ts +++ b/src/plugins/events/interactionCreate/index.ts @@ -2,8 +2,8 @@ import { CommandInteraction, MessageEmbed } from "discord.js"; // Dependencies -import isCommand from "../../events/interactionCreate/components/isCommand"; -import isButton from "../../events/interactionCreate/components/isButton"; +import * as handlers from "./handlers"; + import logger from "../../../logger"; import audits from "./audits"; import { IEventOptions } from "../../../interfaces/EventOptions"; @@ -27,11 +27,8 @@ export const execute = async (interaction: CommandInteraction) => { await audits.execute(interaction); - try { - await isCommand(interaction); - await isButton(interaction); - } catch (error) { - logger.debug(`${error}`); + await handlers.execute(interaction).catch(async (err) => { + logger.debug(`${err}`); return interaction.editReply({ embeds: [ @@ -41,11 +38,11 @@ export const execute = async (interaction: CommandInteraction) => { interaction.options.getSubcommand() )}` ) - .setDescription(`${"``"}${error}${"``"}`) + .setDescription(`${"``"}${err}${"``"}`) .setColor(errorColor) .setTimestamp(new Date()) .setFooter({ text: footerText, iconURL: footerIcon }), ], }); - } + }); }; From b3f3fb1727cf6c1f3631b0b1cf33ecc5e911843d Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 01:10:08 +0200 Subject: [PATCH 57/75] =?UTF-8?q?=E2=9C=A8=20prune=20command,=20fixes=20#3?= =?UTF-8?q?39=20#340?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/moderation/index.ts | 22 +++++ .../commands/moderation/modules/index.ts | 3 + .../moderation/modules/prune/index.ts | 91 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/plugins/commands/moderation/index.ts create mode 100644 src/plugins/commands/moderation/modules/index.ts create mode 100644 src/plugins/commands/moderation/modules/prune/index.ts diff --git a/src/plugins/commands/moderation/index.ts b/src/plugins/commands/moderation/index.ts new file mode 100644 index 0000000..73b4994 --- /dev/null +++ b/src/plugins/commands/moderation/index.ts @@ -0,0 +1,22 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { CommandInteraction } from "discord.js"; + +import modules from "./modules"; +export const moduleData = modules; + +export const builder = new SlashCommandBuilder() + .setName("moderation") + .setDescription("Moderation.") + + .addSubcommand(modules.prune.builder); + +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options.getSubcommand()) { + case "prune": + return modules.prune.execute(interaction); + default: + throw new Error( + `Unknown subcommand: ${interaction.options.getSubcommand()}` + ); + } +}; diff --git a/src/plugins/commands/moderation/modules/index.ts b/src/plugins/commands/moderation/modules/index.ts new file mode 100644 index 0000000..e7dd532 --- /dev/null +++ b/src/plugins/commands/moderation/modules/index.ts @@ -0,0 +1,3 @@ +import prune from "./prune"; + +export default { prune }; diff --git a/src/plugins/commands/moderation/modules/prune/index.ts b/src/plugins/commands/moderation/modules/prune/index.ts new file mode 100644 index 0000000..c847e47 --- /dev/null +++ b/src/plugins/commands/moderation/modules/prune/index.ts @@ -0,0 +1,91 @@ +// Dependencies +import { + CommandInteraction, + Permissions, +} from "discord.js"; + +// Configurations +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; + +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + metadata: { + guildOnly: true, + ephemeral: false, + permissions: [Permissions.FLAGS.MANAGE_MESSAGES], + }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("prune") + .setDescription("Prune messages!") + .addIntegerOption((option) => + option + .setName("count") + .setDescription("How many messages you want to prune.") + .setRequired(true) + ) + .addBooleanOption((option) => + option.setName("bots").setDescription("Include bots.") + ); + }, + execute: async (interaction: CommandInteraction) => { + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const count = interaction.options.getInteger("count"); + if (count == null) return; + const bots = interaction.options.getBoolean("bots"); + + if (count < 1 || count > 100) { + const interactionEmbed = { + title: "[:police_car:] Prune", + description: `You can only prune between 1 and 100 messages.`, + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + await interaction.editReply({ + embeds: [interactionEmbed], + }); + return; + } + + if (interaction?.channel?.type !== "GUILD_TEXT") return; + await interaction.channel.messages.fetch().then(async (messages) => { + const messagesToDelete = ( + bots + ? messages.filter((m) => m?.interaction?.id !== interaction.id) + : messages.filter( + (m) => + m?.interaction?.id !== interaction.id && m?.author?.bot !== true + ) + ).first(count); + + if (interaction?.channel?.type !== "GUILD_TEXT") return; + await interaction.channel + .bulkDelete(messagesToDelete, true) + .then(async () => { + const interactionEmbed = { + title: "[:police_car:] Prune", + description: `Successfully pruned \`${count}\` messages.`, + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + await interaction.editReply({ + embeds: [interactionEmbed], + }); + }); + }); + }, +}; From 8d6568c4fa56095499e10d464bea9411bb7b7193 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 12:14:21 +0200 Subject: [PATCH 58/75] =?UTF-8?q?=F0=9F=9A=9A=20utility/lookup=20=3D>=20dn?= =?UTF-8?q?s/lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/dns/index.ts | 22 +++ src/plugins/commands/dns/modules/index.ts | 3 + .../commands/dns/modules/lookup/index.ts | 133 ++++++++++++++++++ src/plugins/commands/utility/index.ts | 3 - src/plugins/commands/utility/modules/index.ts | 2 - .../commands/utility/modules/lookup/index.ts | 121 ---------------- 6 files changed, 158 insertions(+), 126 deletions(-) create mode 100644 src/plugins/commands/dns/index.ts create mode 100644 src/plugins/commands/dns/modules/index.ts create mode 100644 src/plugins/commands/dns/modules/lookup/index.ts delete mode 100644 src/plugins/commands/utility/modules/lookup/index.ts diff --git a/src/plugins/commands/dns/index.ts b/src/plugins/commands/dns/index.ts new file mode 100644 index 0000000..ee623ec --- /dev/null +++ b/src/plugins/commands/dns/index.ts @@ -0,0 +1,22 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { CommandInteraction } from "discord.js"; + +import modules from "./modules"; +export const moduleData = modules; + +export const builder = new SlashCommandBuilder() + .setName("dns") + .setDescription("DNS commands.") + + .addSubcommand(modules.lookup.builder); + +export const execute = async (interaction: CommandInteraction) => { + switch (interaction.options.getSubcommand()) { + case "lookup": + return modules.lookup.execute(interaction); + default: + throw new Error( + `Unknown subcommand: ${interaction.options.getSubcommand()}` + ); + } +}; diff --git a/src/plugins/commands/dns/modules/index.ts b/src/plugins/commands/dns/modules/index.ts new file mode 100644 index 0000000..92a80ac --- /dev/null +++ b/src/plugins/commands/dns/modules/index.ts @@ -0,0 +1,3 @@ +import lookup from "./lookup"; + +export default { lookup }; diff --git a/src/plugins/commands/dns/modules/lookup/index.ts b/src/plugins/commands/dns/modules/lookup/index.ts new file mode 100644 index 0000000..9dc0d1f --- /dev/null +++ b/src/plugins/commands/dns/modules/lookup/index.ts @@ -0,0 +1,133 @@ +import axios from "axios"; +import { CommandInteraction, MessageEmbed } from "discord.js"; + +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; + +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +import embedBuilder from "../../../../../helpers/embedBuilder"; + +export default { + metadata: { guildOnly: false, ephemeral: false }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command + .setName("lookup") + .setDescription( + "Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)" + ) + .addStringOption((option) => + option + .setName("query") + .setDescription("The query you want to look up.") + .setRequired(true) + ); + }, + execute: async (interaction: CommandInteraction) => { + const { errorColor, successColor, footerText, footerIcon } = + await getEmbedConfig(interaction.guild); + const embedTitle = "[:hammer:] Utility (Lookup)"; + + const { options } = interaction; + const query = options.getString("query"); + + await axios + .get(`http://ip-api.com/json/${query}`) + .then(async (response) => { + if (response.data.status !== "success") { + await interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle(embedTitle) + .setFooter({ + text: footerText, + iconURL: footerIcon, + }) + .setTimestamp(new Date()) + .setColor(errorColor) + .setFooter({ text: footerText, iconURL: footerIcon }) + .setDescription( + `${response?.data?.message}: ${response?.data?.query}` + ), + ], + }); + return; + } + + await interaction.editReply({ + embeds: [ + new MessageEmbed() + .setTitle(embedTitle) + .setFooter({ + text: footerText, + iconURL: footerIcon, + }) + .setTimestamp(new Date()) + .setColor(successColor) + .setFields([ + { + name: ":classical_building: AS", + value: `${response.data.as || "Unknown"}`, + inline: true, + }, + { + name: ":classical_building: ISP", + value: `${response.data.isp || "Unknown"}`, + inline: true, + }, + { + name: ":classical_building: Organization", + value: `${response.data.org || "Unknown"}`, + inline: true, + }, + { + name: ":compass: Latitude", + value: `${response.data.lat || "Unknown"}`, + inline: true, + }, + { + name: ":compass: Longitude", + value: `${response.data.lon || "Unknown"}`, + inline: true, + }, + { + name: ":clock4: Timezone", + value: `${response.data.timezone || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: Country", + value: `${response.data.country || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: Region", + value: `${response.data.regionName || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: City", + value: `${response.data.city || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: Country Code", + value: `${response.data.countryCode || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: Region Code", + value: `${response.data.region || "Unknown"}`, + inline: true, + }, + { + name: ":globe_with_meridians: ZIP", + value: `${response.data.zip || "Unknown"}`, + inline: true, + }, + ]), + ], + }); + }); + }, +}; diff --git a/src/plugins/commands/utility/index.ts b/src/plugins/commands/utility/index.ts index c97ef47..c9a5ce9 100644 --- a/src/plugins/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -8,15 +8,12 @@ export const builder = new SlashCommandBuilder() .setName("utility") .setDescription("Common utility.") - .addSubcommand(modules.lookup.builder) .addSubcommand(modules.about.builder) .addSubcommand(modules.stats.builder) .addSubcommand(modules.avatar.builder); export const execute = async (interaction: CommandInteraction) => { switch (interaction.options.getSubcommand()) { - case "lookup": - return modules.lookup.execute(interaction); case "about": return modules.about.execute(interaction); case "stats": diff --git a/src/plugins/commands/utility/modules/index.ts b/src/plugins/commands/utility/modules/index.ts index cd69316..29a60e0 100644 --- a/src/plugins/commands/utility/modules/index.ts +++ b/src/plugins/commands/utility/modules/index.ts @@ -1,11 +1,9 @@ import avatar from "./avatar"; import about from "./about"; -import lookup from "./lookup"; import stats from "./stats"; export default { avatar, about, - lookup, stats, }; diff --git a/src/plugins/commands/utility/modules/lookup/index.ts b/src/plugins/commands/utility/modules/lookup/index.ts deleted file mode 100644 index 44abe14..0000000 --- a/src/plugins/commands/utility/modules/lookup/index.ts +++ /dev/null @@ -1,121 +0,0 @@ -import axios from "axios"; -import { CommandInteraction } from "discord.js"; - -import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; - -import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; - -import embedBuilder from "../../../../../helpers/embedBuilder"; - -export default { - metadata: { guildOnly: false, ephemeral: false }, - - builder: (command: SlashCommandSubcommandBuilder) => { - return command - .setName("lookup") - .setDescription( - "Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)" - ) - .addStringOption((option) => - option - .setName("query") - .setDescription("The query you want to look up.") - .setRequired(true) - ); - }, - execute: async (interaction: CommandInteraction) => { - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(interaction.guild); - const embedTitle = "[:hammer:] Utility (Lookup)"; - - embedBuilder.setTitle(embedTitle); - - const { options } = interaction; - const query = options.getString("query"); - - await axios - .get(`http://ip-api.com/json/${query}`) - .then(async (response) => { - if (response.data.status !== "success") { - await interaction.editReply({ - embeds: [ - embedBuilder - .setColor(errorColor) - .setFooter({ text: footerText, iconURL: footerIcon }) - .setDescription( - `${response?.data?.message}: ${response?.data?.query}` - ), - ], - }); - return; - } - - await interaction.editReply({ - embeds: [ - embedBuilder.setColor(successColor).setFields([ - { - name: ":classical_building: AS", - value: `${response.data.as || "Unknown"}`, - inline: true, - }, - { - name: ":classical_building: ISP", - value: `${response.data.isp || "Unknown"}`, - inline: true, - }, - { - name: ":classical_building: Organization", - value: `${response.data.org || "Unknown"}`, - inline: true, - }, - { - name: ":compass: Latitude", - value: `${response.data.lat || "Unknown"}`, - inline: true, - }, - { - name: ":compass: Longitude", - value: `${response.data.lon || "Unknown"}`, - inline: true, - }, - { - name: ":clock4: Timezone", - value: `${response.data.timezone || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: Country", - value: `${response.data.country || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: Region", - value: `${response.data.regionName || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: City", - value: `${response.data.city || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: Country Code", - value: `${response.data.countryCode || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: Region Code", - value: `${response.data.region || "Unknown"}`, - inline: true, - }, - { - name: ":globe_with_meridians: ZIP", - value: `${response.data.zip || "Unknown"}`, - inline: true, - }, - ]), - ], - }); - }); - }, -}; From 0847ae205d0601552d47ce5dc88c925720bb61cc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 12:17:53 +0200 Subject: [PATCH 59/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20embedBuilder=20not?= =?UTF-8?q?=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/dns/modules/lookup/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/commands/dns/modules/lookup/index.ts b/src/plugins/commands/dns/modules/lookup/index.ts index 9dc0d1f..ea56b83 100644 --- a/src/plugins/commands/dns/modules/lookup/index.ts +++ b/src/plugins/commands/dns/modules/lookup/index.ts @@ -5,8 +5,6 @@ import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import embedBuilder from "../../../../../helpers/embedBuilder"; - export default { metadata: { guildOnly: false, ephemeral: false }, From 7d02cf9b8d2d4b587aa6695591747b38c197d9e4 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 12:27:35 +0200 Subject: [PATCH 60/75] =?UTF-8?q?=E2=9C=A8=20Add=20ping=20module=20to=20ut?= =?UTF-8?q?ility=20command=20#338?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/commands/utility/index.ts | 5 +- src/plugins/commands/utility/modules/index.ts | 2 + .../commands/utility/modules/ping/index.ts | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/plugins/commands/utility/modules/ping/index.ts diff --git a/src/plugins/commands/utility/index.ts b/src/plugins/commands/utility/index.ts index c9a5ce9..43da584 100644 --- a/src/plugins/commands/utility/index.ts +++ b/src/plugins/commands/utility/index.ts @@ -10,7 +10,8 @@ export const builder = new SlashCommandBuilder() .addSubcommand(modules.about.builder) .addSubcommand(modules.stats.builder) - .addSubcommand(modules.avatar.builder); + .addSubcommand(modules.avatar.builder) + .addSubcommand(modules.ping.builder); export const execute = async (interaction: CommandInteraction) => { switch (interaction.options.getSubcommand()) { @@ -20,6 +21,8 @@ export const execute = async (interaction: CommandInteraction) => { return modules.stats.execute(interaction); case "avatar": return modules.avatar.execute(interaction); + case "ping": + return modules.ping.execute(interaction); default: throw new Error( `Unknown subcommand: ${interaction.options.getSubcommand()}` diff --git a/src/plugins/commands/utility/modules/index.ts b/src/plugins/commands/utility/modules/index.ts index 29a60e0..33fa0f5 100644 --- a/src/plugins/commands/utility/modules/index.ts +++ b/src/plugins/commands/utility/modules/index.ts @@ -1,9 +1,11 @@ import avatar from "./avatar"; import about from "./about"; import stats from "./stats"; +import ping from "./ping"; export default { avatar, about, stats, + ping, }; diff --git a/src/plugins/commands/utility/modules/ping/index.ts b/src/plugins/commands/utility/modules/ping/index.ts new file mode 100644 index 0000000..666529b --- /dev/null +++ b/src/plugins/commands/utility/modules/ping/index.ts @@ -0,0 +1,51 @@ +// Dependencies +import { + CommandInteraction, + MessageActionRow, + MessageButton, +} from "discord.js"; + +// Configurations +import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; + +import { hosterName, hosterUrl } from "../../../../../config/other"; +import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; + +// Function +export default { + metadata: { guildOnly: false, ephemeral: false }, + + builder: (command: SlashCommandSubcommandBuilder) => { + return command.setName("ping").setDescription("Ping this bot"); + }, + execute: async (interaction: CommandInteraction) => { + const { successColor, footerText, footerIcon } = await getEmbedConfig( + interaction.guild + ); + + const interactionEmbed = { + title: "[:tools:] Ping", + fields: [ + { + name: "📦 Deliver Latency", + value: `${Math.abs(Date.now() - interaction.createdTimestamp)} ms`, + inline: true, + }, + { + name: "🤖 API Latency", + value: `${Math.round(interaction.client.ws.ping)} ms`, + inline: true, + }, + ], + color: successColor, + timestamp: new Date(), + footer: { + iconURL: footerIcon, + text: footerText, + }, + }; + await interaction.editReply({ + embeds: [interactionEmbed], + }); + }, +}; From eb2ead393a8bb75f321a19204f712ce7032358ba Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 12 Jun 2022 13:09:00 +0200 Subject: [PATCH 61/75] =?UTF-8?q?=F0=9F=9A=B8=20better=20issue=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug_report.md | 32 ----------- .github/ISSUE_TEMPLATE/bug_report.yaml | 60 +++++++++++++++++++++ .github/ISSUE_TEMPLATE/command_request.yaml | 48 +++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ------- 4 files changed, 108 insertions(+), 52 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yaml create mode 100644 .github/ISSUE_TEMPLATE/command_request.yaml delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 6debbd7..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "" -labels: "bug" -assignees: "VermiumSifell" ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: - -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Environment (please complete the following information):** - -- Commit: [git rev-parse HEAD] -- Branch: [git branch --show-current] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml new file mode 100644 index 0000000..dab3c2f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -0,0 +1,60 @@ +name: 🐞 Bug +description: File a bug/issue +title: "[BUG]: " +labels: ["bug"] +body: + - type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true + - type: textarea + attributes: + label: Current Behavior + description: A concise description of what you're experiencing. + validations: + required: false + - type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: false + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. In this environment... + 2. Run '...' + 3. See error... + validations: + required: false + - type: textarea + attributes: + label: Environment + description: | + examples: + - **OS**: Ubuntu 20.04 + - **Node**: 13.14.0 + - **npm**: 7.6.3 + - **xyter**: 7d02cf9 + value: | + - OS: `lsb_release -d` + - Node: `node -v` + - npm: `npm -v` + - xyter: `git rev-parse --short HEAD` + render: markdown + validations: + required: true + - type: textarea + attributes: + label: Anything else? + description: | + Links? References? Anything that will give us more context about the issue you are encountering! + + Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/command_request.yaml b/.github/ISSUE_TEMPLATE/command_request.yaml new file mode 100644 index 0000000..e6d047c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/command_request.yaml @@ -0,0 +1,48 @@ +name: 🤖 Request a new command +description: Suggest an command for this project +title: "[New Command]: / [command_group] " +labels: ["enhancement", "new-command"] + +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! We will use `/manage credits give` as an example for our placeholders. + - type: input + id: category + attributes: + label: Category + description: Where should we put this command? + placeholder: ex. manage + validations: + required: true + - type: input + id: group + attributes: + label: Group + description: Does this command belong to this group? + placeholder: ex. credits + - type: input + id: command + attributes: + label: Command + description: What should we call this command? + placeholder: ex. give + validations: + required: true + - type: textarea + id: description + attributes: + label: What should the command do? + description: Please tell us your concept, how it should work, and if there should be any additional features. + placeholder: "I would like to have a command to give users credits, that would make it easier for me to administrate credits! I would like it to add a specified amount of credits to specified user, without taking credits from the executer. Command should require Manage Guild permission. When successful, it should return something like: Added credits to !" + validations: + required: true + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 36014cd..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: 'enhancement' -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. From 1c56ff9bcbe71e819b559a65231f1d3514402bfc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 13 Jun 2022 13:43:09 +0200 Subject: [PATCH 62/75] =?UTF-8?q?=F0=9F=94=A7=20renovate=20now=20opens=20P?= =?UTF-8?q?Rs=20to=20dev=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renovate.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/renovate.json b/renovate.json index 4f39080..57d1542 100644 --- a/renovate.json +++ b/renovate.json @@ -1,3 +1,4 @@ { - "extends": ["config:base"] + "extends": ["config:base"], + "baseBranches": ["dev"] } From a42f277b82246653d0e274c6fffecc7c48b7d438 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 11:43:56 +0000 Subject: [PATCH 63/75] Update dependency @discordjs/builders to ^0.15.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..75e3864 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "email": "vermium@zyner.org" }, "dependencies": { - "@discordjs/builders": "^0.13.0", + "@discordjs/builders": "^0.15.0", "@discordjs/rest": "^0.4.0", "@types/i18next-fs-backend": "^1.1.2", "axios": "^0.27.2", From a0289bb7384d1896b5acb9c5baf4b8548036d1b6 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 11:48:54 +0000 Subject: [PATCH 64/75] Update dependency @discordjs/rest to ^0.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..b1b2025 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "@discordjs/builders": "^0.13.0", - "@discordjs/rest": "^0.4.0", + "@discordjs/rest": "^0.5.0", "@types/i18next-fs-backend": "^1.1.2", "axios": "^0.27.2", "chance": "^1.1.8", From 47f9a2086fe4562398ce2c1930068b34368d9032 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 11:51:31 +0000 Subject: [PATCH 65/75] Update dependency jest to v28.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..a106250 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "eslint-plugin-no-loops": "^0.3.0", "eslint-plugin-prettier": "^4.0.0", "husky": "8.0.1", - "jest": "28.0.0", + "jest": "28.1.1", "lint-staged": "^12.3.7", "prettier": "^2.6.0" }, From 23a1b33a6ca5dfaff0d6232f0c023002d93af052 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 11:55:58 +0000 Subject: [PATCH 66/75] Update dependency eslint to v8.17.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..fc718ef 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.15.0", "@typescript-eslint/parser": "^5.15.0", - "eslint": "8.15.0", + "eslint": "8.17.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", From ef9a7944f86e826689d003527a3145e01685276b Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 11:57:06 +0000 Subject: [PATCH 67/75] Update dependency lint-staged to v13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..87f46c0 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "eslint-plugin-prettier": "^4.0.0", "husky": "8.0.1", "jest": "28.0.0", - "lint-staged": "^12.3.7", + "lint-staged": "13.0.1", "prettier": "^2.6.0" }, "lint-staged": { From 9a11af4c1e0844288717747c2bdd3e878be708ba Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 13 Jun 2022 14:06:01 +0200 Subject: [PATCH 68/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20remove=20unused=20va?= =?UTF-8?q?riables=20(JS-0356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/cooldown/index.ts | 1 - src/plugins/buttons/primary/index.ts | 6 +++--- src/plugins/commands/counters/index.ts | 1 - src/plugins/commands/manage/index.ts | 1 - src/plugins/commands/manage/modules/credits/index.ts | 1 - src/plugins/commands/reputation/index.ts | 1 - src/plugins/commands/reputation/modules/give/index.ts | 5 +++-- src/plugins/commands/shop/modules/cpgg/index.ts | 1 - src/plugins/commands/utility/modules/ping/index.ts | 7 +------ src/plugins/events/guildMemberAdd/audits.ts | 2 +- src/plugins/events/guildMemberRemove/audits.ts | 2 +- src/plugins/events/interactionCreate/handlers/index.ts | 2 -- src/plugins/events/messageCreate/modules/points/index.ts | 3 --- src/plugins/events/rateLimit/index.ts | 2 +- 14 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/helpers/cooldown/index.ts b/src/helpers/cooldown/index.ts index 45d2729..f574f57 100644 --- a/src/helpers/cooldown/index.ts +++ b/src/helpers/cooldown/index.ts @@ -3,7 +3,6 @@ import { CommandInteraction, ButtonInteraction, Message } from "discord.js"; import logger from "../../logger"; -import getEmbedConfig from "../../helpers/getEmbedConfig"; import timeoutSchema from "../../models/timeout"; import addSeconds from "../../helpers/addSeconds"; diff --git a/src/plugins/buttons/primary/index.ts b/src/plugins/buttons/primary/index.ts index c1441db..83162a6 100644 --- a/src/plugins/buttons/primary/index.ts +++ b/src/plugins/buttons/primary/index.ts @@ -1,8 +1,8 @@ -import { CommandInteraction } from "discord.js"; +import { ButtonInteraction } from "discord.js"; import logger from "../../../logger"; export const metadata = { guildOnly: false, ephemeral: false }; -export const execute = async (interaction: CommandInteraction) => { - logger.debug("primary button clicked!"); +export const execute = async (interaction: ButtonInteraction) => { + logger.debug(interaction.customId, "primary button clicked!"); }; diff --git a/src/plugins/commands/counters/index.ts b/src/plugins/commands/counters/index.ts index eca16dc..9626b99 100644 --- a/src/plugins/commands/counters/index.ts +++ b/src/plugins/commands/counters/index.ts @@ -1,6 +1,5 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandBuilder } from "@discordjs/builders"; -import logger from "../../../logger"; import modules from "../../commands/counters/modules"; diff --git a/src/plugins/commands/manage/index.ts b/src/plugins/commands/manage/index.ts index 1f914bb..1b61f39 100644 --- a/src/plugins/commands/manage/index.ts +++ b/src/plugins/commands/manage/index.ts @@ -4,7 +4,6 @@ import { CommandInteraction } from "discord.js"; // Groups import modules from "../../commands/manage/modules"; -import logger from "../../../logger"; export const moduleData = modules; diff --git a/src/plugins/commands/manage/modules/credits/index.ts b/src/plugins/commands/manage/modules/credits/index.ts index b4673ff..92efd12 100644 --- a/src/plugins/commands/manage/modules/credits/index.ts +++ b/src/plugins/commands/manage/modules/credits/index.ts @@ -1,6 +1,5 @@ import { CommandInteraction } from "discord.js"; import { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; -import logger from "../../../../../logger"; import modules from "./modules"; diff --git a/src/plugins/commands/reputation/index.ts b/src/plugins/commands/reputation/index.ts index ae1876e..d667343 100644 --- a/src/plugins/commands/reputation/index.ts +++ b/src/plugins/commands/reputation/index.ts @@ -6,7 +6,6 @@ import { CommandInteraction } from "discord.js"; import modules from "./modules"; // Handlers -import logger from "../../../logger"; export const moduleData = modules; diff --git a/src/plugins/commands/reputation/modules/give/index.ts b/src/plugins/commands/reputation/modules/give/index.ts index eb58abe..f9970df 100644 --- a/src/plugins/commands/reputation/modules/give/index.ts +++ b/src/plugins/commands/reputation/modules/give/index.ts @@ -37,8 +37,9 @@ export default { execute: async (interaction: CommandInteraction) => { const { options, user, guild } = interaction; - const { errorColor, successColor, footerText, footerIcon } = - await getEmbedConfig(guild); // Destructure + const { successColor, footerText, footerIcon } = await getEmbedConfig( + guild + ); // Destructure const optionTarget = options?.getUser("target"); const optionType = options?.getString("type"); diff --git a/src/plugins/commands/shop/modules/cpgg/index.ts b/src/plugins/commands/shop/modules/cpgg/index.ts index 90dbe70..365753f 100644 --- a/src/plugins/commands/shop/modules/cpgg/index.ts +++ b/src/plugins/commands/shop/modules/cpgg/index.ts @@ -16,7 +16,6 @@ import pluralize from "../../../../../helpers/pluralize"; import apiSchema from "../../../../../models/api"; import fetchUser from "../../../../../helpers/fetchUser"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; -import { message } from "../../../../../helpers/cooldown/index"; export default { metadata: { guildOnly: true, ephemeral: true }, diff --git a/src/plugins/commands/utility/modules/ping/index.ts b/src/plugins/commands/utility/modules/ping/index.ts index 666529b..420329e 100644 --- a/src/plugins/commands/utility/modules/ping/index.ts +++ b/src/plugins/commands/utility/modules/ping/index.ts @@ -1,14 +1,9 @@ // Dependencies -import { - CommandInteraction, - MessageActionRow, - MessageButton, -} from "discord.js"; +import { CommandInteraction } from "discord.js"; // Configurations import getEmbedConfig from "../../../../../helpers/getEmbedConfig"; -import { hosterName, hosterUrl } from "../../../../../config/other"; import { SlashCommandSubcommandBuilder } from "@discordjs/builders"; // Function diff --git a/src/plugins/events/guildMemberAdd/audits.ts b/src/plugins/events/guildMemberAdd/audits.ts index 89c0384..9f94282 100644 --- a/src/plugins/events/guildMemberAdd/audits.ts +++ b/src/plugins/events/guildMemberAdd/audits.ts @@ -1,5 +1,5 @@ import logger from "../../../logger"; -import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; +import { GuildMember, MessageEmbed } from "discord.js"; import guildSchema from "../../../models/guild"; diff --git a/src/plugins/events/guildMemberRemove/audits.ts b/src/plugins/events/guildMemberRemove/audits.ts index a940ca3..5ce4849 100644 --- a/src/plugins/events/guildMemberRemove/audits.ts +++ b/src/plugins/events/guildMemberRemove/audits.ts @@ -1,5 +1,5 @@ import logger from "../../../logger"; -import { GuildMember, MessageEmbed, TextChannel } from "discord.js"; +import { GuildMember, MessageEmbed } from "discord.js"; import guildSchema from "../../../models/guild"; diff --git a/src/plugins/events/interactionCreate/handlers/index.ts b/src/plugins/events/interactionCreate/handlers/index.ts index c29bfc3..85f1e7a 100644 --- a/src/plugins/events/interactionCreate/handlers/index.ts +++ b/src/plugins/events/interactionCreate/handlers/index.ts @@ -3,8 +3,6 @@ import { Interaction } from "discord.js"; import button from "./button"; import command from "./command"; -import logger from "../../../../logger"; - export const execute = async (interaction: Interaction) => { await button(interaction); await command(interaction); diff --git a/src/plugins/events/messageCreate/modules/points/index.ts b/src/plugins/events/messageCreate/modules/points/index.ts index 4a4496b..ed18003 100644 --- a/src/plugins/events/messageCreate/modules/points/index.ts +++ b/src/plugins/events/messageCreate/modules/points/index.ts @@ -14,9 +14,6 @@ export default { if (author.bot) return; if (channel?.type !== "GUILD_TEXT") return; - const { id: guildId } = guild; - const { id: userId } = author; - const guildData = await fetchGuild(guild); const userData = await fetchUser(author, guild); diff --git a/src/plugins/events/rateLimit/index.ts b/src/plugins/events/rateLimit/index.ts index 8886c1a..ca9aab5 100644 --- a/src/plugins/events/rateLimit/index.ts +++ b/src/plugins/events/rateLimit/index.ts @@ -10,5 +10,5 @@ export const options: IEventOptions = { }; export const execute = async (client: Client) => { - logger.warn("Discord's API client is rate-limited!"); + logger.warn(`Discord's API client (${client?.user?.tag}) is rate-limited!`); }; From 410442e17bfc0cc593a6b23cf7de7b1868f376cc Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 13 Jun 2022 14:17:21 +0200 Subject: [PATCH 69/75] Detected usage of the `any` type (JS-0323) --- src/plugins/events/messageUpdate/modules/counter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/events/messageUpdate/modules/counter.ts b/src/plugins/events/messageUpdate/modules/counter.ts index 03c60b9..4a01749 100644 --- a/src/plugins/events/messageUpdate/modules/counter.ts +++ b/src/plugins/events/messageUpdate/modules/counter.ts @@ -29,7 +29,7 @@ export default async (message: Message) => { await channel?.send(`${author} said **${word}**.`); logger?.silly(`${author} said ${word} in ${channel}`); }) - ?.catch(async (error: any) => { + ?.catch(async (error) => { logger?.error(error); }); }; From 092778b22dab1eccf3361b72e9bb353a84098d74 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 13 Jun 2022 14:29:30 +0200 Subject: [PATCH 70/75] =?UTF-8?q?=F0=9F=94=8A=20change=20interactionCreate?= =?UTF-8?q?=20log=20to=20debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/events/interactionCreate/audits.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/events/interactionCreate/audits.ts b/src/plugins/events/interactionCreate/audits.ts index 7c71f80..183ff5a 100644 --- a/src/plugins/events/interactionCreate/audits.ts +++ b/src/plugins/events/interactionCreate/audits.ts @@ -52,7 +52,7 @@ export default { ], }) .then(async () => { - logger.info( + logger.debug( `Audit log sent for event interactionCreate in guild ${interaction?.guild?.name} (${interaction?.guild?.id})` ); }) From ef7d6476857c30c73de2548c75186472e8979e5e Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 13 Jun 2022 16:53:09 +0000 Subject: [PATCH 71/75] Update dependency discord-api-types to ^0.34.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..064f3a3 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "chance": "^1.1.8", "common": "^0.2.5", "crypto": "^1.0.1", - "discord-api-types": "^0.33.0", + "discord-api-types": "^0.34.0", "discord.js": "^13.6.0", "i18n": "^0.14.2", "i18next": "^21.6.13", From 4e4c4b06166d64c4612dcc43b4e8182164df5971 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Wed, 15 Jun 2022 00:11:10 +0200 Subject: [PATCH 72/75] =?UTF-8?q?=F0=9F=92=AC=20Drops=20=3D>=20Giveaway?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/manage/modules/credits/modules/giveaway/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts index acb73cb..5c08048 100644 --- a/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts +++ b/src/plugins/commands/manage/modules/credits/modules/giveaway/index.ts @@ -64,7 +64,7 @@ export default { if (!channel) throw new Error("Channel is required."); const embed = new MessageEmbed() - .setTitle("[:toolbox:] Drop") + .setTitle("[:toolbox:] Giveaway") .setFooter({ text: footerText, iconURL: footerIcon }); const code = uuidv4(); From ef6c9b3563c8589c976cf9d8efc5b526bcb25ab9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 17 Jun 2022 21:08:11 +0000 Subject: [PATCH 73/75] Update dependency eslint to v8.18.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 216f2fb..72be826 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.15.0", "@typescript-eslint/parser": "^5.15.0", - "eslint": "8.15.0", + "eslint": "8.18.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", From 805bd5c4aa5fecd3383fabb7147a5dba9c85298e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 20 Jun 2022 13:24:13 +0200 Subject: [PATCH 74/75] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20tsconfig-paths=20not?= =?UTF-8?q?=20in=20use=20anymore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index ef3cab7..4327353 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,3 @@ -import "tsconfig-paths/register"; // Allows using tsconfig.json paths during runtime - import { token, intents } from "./config/discord"; import { Client } from "discord.js"; // discord.js From 023589f9d093818a38815635a7135aa75d45ec6e Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Mon, 20 Jun 2022 13:24:56 +0200 Subject: [PATCH 75/75] =?UTF-8?q?=F0=9F=9A=9A=20fixed=20ICommand=20path=20?= =?UTF-8?q?in=20discord.d.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/types/common/discord.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/common/discord.d.ts b/src/types/common/discord.d.ts index e83d22f..b354c9d 100644 --- a/src/types/common/discord.d.ts +++ b/src/types/common/discord.d.ts @@ -1,5 +1,5 @@ import { Collection } from "discord.js"; -import ICommand from "../interfaces/Command"; +import ICommand from "../../interfaces/Command"; declare module "discord.js" { export interface Client extends DJSClient {