feat: ♻️ centralized error classes
I have cleaned up some code by moving some regular used throw new messages to a error class file
This commit is contained in:
parent
0c3f53950c
commit
a816129dd2
25 changed files with 151 additions and 182 deletions
|
@ -9,6 +9,10 @@ import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import prisma from "../../../../../../handlers/prisma";
|
import prisma from "../../../../../../handlers/prisma";
|
||||||
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import {
|
||||||
|
GuildNotFoundError,
|
||||||
|
UserNotFoundError,
|
||||||
|
} from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const cooldownManager = new CooldownManager();
|
const cooldownManager = new CooldownManager();
|
||||||
|
@ -22,18 +26,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { guild, user } = interaction;
|
const { guild, user } = interaction;
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
if (!guild) {
|
if (!user) throw new UserNotFoundError();
|
||||||
throw new Error(
|
|
||||||
"Oops! It looks like you're not part of a guild. Join a guild to embark on this adventure!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new Error(
|
|
||||||
"Oops! We couldn't find your user information. Please try again or contact support for assistance."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
||||||
where: { id: guild.id },
|
where: { id: guild.id },
|
||||||
|
|
|
@ -9,6 +9,10 @@ import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import prisma from "../../../../../../handlers/prisma";
|
import prisma from "../../../../../../handlers/prisma";
|
||||||
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import {
|
||||||
|
GuildNotFoundError,
|
||||||
|
UserNotFoundError,
|
||||||
|
} from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const cooldownManager = new CooldownManager();
|
const cooldownManager = new CooldownManager();
|
||||||
|
@ -25,17 +29,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
|
|
||||||
if (!guild) {
|
if (!guild) throw new GuildNotFoundError();
|
||||||
throw new Error(
|
if (!user) throw new UserNotFoundError();
|
||||||
"Oops! It looks like you're not part of a guild. Join a guild to embark on this adventure!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new Error(
|
|
||||||
"Oops! We couldn't find your user information. Please try again or contact support for assistance."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
||||||
where: { id: guild.id },
|
where: { id: guild.id },
|
||||||
|
|
|
@ -9,6 +9,10 @@ import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import prisma from "../../../../../../handlers/prisma";
|
import prisma from "../../../../../../handlers/prisma";
|
||||||
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../../../helpers/generateCooldownName";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import {
|
||||||
|
GuildNotFoundError,
|
||||||
|
UserNotFoundError,
|
||||||
|
} from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const cooldownManager = new CooldownManager();
|
const cooldownManager = new CooldownManager();
|
||||||
|
@ -24,18 +28,8 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { guild, user } = interaction;
|
const { guild, user } = interaction;
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
if (!guild) {
|
if (!user) throw new UserNotFoundError();
|
||||||
throw new Error(
|
|
||||||
"Oops! It looks like you're not part of a guild. Join a guild to embark on this adventure!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new Error(
|
|
||||||
"Oops! We couldn't find your user information. Please try again or contact support for assistance."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
const guildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
||||||
where: { id: guild.id },
|
where: { id: guild.id },
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import CreditsManager from "../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../handlers/CreditsManager";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -26,11 +27,9 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { options, user, guild } = interaction;
|
const { options, user, guild } = interaction;
|
||||||
await deferReply(interaction, false);
|
|
||||||
|
|
||||||
if (!guild) {
|
await deferReply(interaction, false);
|
||||||
throw new Error("This command can only be used in guild environments. ❌");
|
if (!guild) throw new GuildNotFoundError();
|
||||||
}
|
|
||||||
|
|
||||||
const checkAccount = options.getUser("account") || user;
|
const checkAccount = options.getUser("account") || user;
|
||||||
const creditAccount = await creditsManager.balance(guild, checkAccount);
|
const creditAccount = await creditsManager.balance(guild, checkAccount);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
import CreditsManager from "../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../handlers/CreditsManager";
|
||||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -39,17 +40,15 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
const { options, user, guild } = interaction;
|
const { options, user, guild } = interaction;
|
||||||
const recipient = options.getUser("account");
|
|
||||||
|
await deferReply(interaction, true);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
|
const recipient = options.getUser("account", true);
|
||||||
const amount = options.getInteger("amount");
|
const amount = options.getInteger("amount");
|
||||||
const message = options.getString("message");
|
const message = options.getString("message");
|
||||||
|
|
||||||
if (!guild || !user || !recipient) {
|
|
||||||
throw new Error("Invalid interaction data");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof amount !== "number" || amount < 1) {
|
if (typeof amount !== "number" || amount < 1) {
|
||||||
throw new Error("Please enter a valid number of credits to gift");
|
throw new Error("Please enter a valid number of credits to gift");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import CreditsManager from "../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../handlers/CreditsManager";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -20,10 +21,7 @@ export const execute = async (interaction: CommandInteraction) => {
|
||||||
const { guild, client, user } = interaction;
|
const { guild, client, user } = interaction;
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
if (!guild) {
|
|
||||||
throw new Error("Unable to find the guild.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const topTen = await creditsManager.topUsers(guild, 10);
|
const topTen = await creditsManager.topUsers(guild, 10);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import CreditsManager from "../../../../handlers/CreditsManager";
|
||||||
import prisma from "../../../../handlers/prisma";
|
import prisma from "../../../../handlers/prisma";
|
||||||
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
import jobs from "./jobs";
|
import jobs from "./jobs";
|
||||||
|
|
||||||
|
@ -28,18 +29,7 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { guild, user } = interaction;
|
const { guild, user } = interaction;
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
if (!guild) {
|
|
||||||
throw new Error(
|
|
||||||
"Oops! It seems like you're not part of a guild. Join a guild to use this command!"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new Error(
|
|
||||||
"Oops! It looks like we couldn't find your user information. Please try again or contact support for assistance."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const chance = new Chance();
|
const chance = new Chance();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import checkPermission from "../../../../../../utils/checkPermission";
|
import checkPermission from "../../../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -40,19 +41,11 @@ export const execute = async (
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
if (!guild) {
|
|
||||||
throw new Error("We could not get the current guild from Discord.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const discordReceiver = options.getUser("user", true);
|
const discordReceiver = options.getUser("user", true);
|
||||||
const creditsAmount = options.getInteger("amount", true);
|
const creditsAmount = options.getInteger("amount", true);
|
||||||
|
|
||||||
if (!discordReceiver || typeof creditsAmount !== "number") {
|
|
||||||
await sendResponse(interaction, "Invalid user or credit amount provided.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const embedSuccess = new EmbedBuilder()
|
const embedSuccess = new EmbedBuilder()
|
||||||
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
||||||
.setAuthor({ name: "💳 Credits Manager" })
|
.setAuthor({ name: "💳 Credits Manager" })
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||||
import CtrlPanelAPI from "../../../../../../services/CtrlPanelAPI";
|
import CtrlPanelAPI from "../../../../../../services/CtrlPanelAPI";
|
||||||
import checkPermission from "../../../../../../utils/checkPermission";
|
import checkPermission from "../../../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
|
@ -47,18 +48,13 @@ export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
|
|
||||||
await deferReply(interaction, true);
|
await deferReply(interaction, true);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
if (!guild) throw new Error("This command can only be used in guilds");
|
|
||||||
const ctrlPanelAPI = new CtrlPanelAPI(guild);
|
const ctrlPanelAPI = new CtrlPanelAPI(guild);
|
||||||
|
|
||||||
const uses = options?.getInteger("uses");
|
const uses = options?.getInteger("uses", true);
|
||||||
const creditAmount = options?.getInteger("credit");
|
const creditAmount = options?.getInteger("credit", true);
|
||||||
const channel = options?.getChannel("channel");
|
const channel = options?.getChannel("channel", true);
|
||||||
|
|
||||||
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.");
|
|
||||||
if (!guild) throw new Error("Guild is required.");
|
|
||||||
|
|
||||||
const embedSuccess = new EmbedBuilder()
|
const embedSuccess = new EmbedBuilder()
|
||||||
.setTitle(":toolbox:︱Giveaway")
|
.setTitle(":toolbox:︱Giveaway")
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import checkPermission from "../../../../../../utils/checkPermission";
|
import checkPermission from "../../../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -38,18 +39,10 @@ export const execute = async (
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
if (!guild) {
|
const discordReceiver = options.getUser("user", true);
|
||||||
throw new Error("We could not get the current guild from Discord.");
|
const creditsAmount = options.getInteger("amount", true);
|
||||||
}
|
|
||||||
|
|
||||||
const discordReceiver = options.getUser("user");
|
|
||||||
const creditsAmount = options.getInteger("amount");
|
|
||||||
|
|
||||||
if (!discordReceiver || typeof creditsAmount !== "number") {
|
|
||||||
await sendResponse(interaction, "Invalid user or credit amount provided.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const embedSuccess = new EmbedBuilder()
|
const embedSuccess = new EmbedBuilder()
|
||||||
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import checkPermission from "../../../../../../utils/checkPermission";
|
import checkPermission from "../../../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -38,18 +39,10 @@ export const execute = async (
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
if (!guild) {
|
const discordReceiver = options.getUser("user", true);
|
||||||
throw new Error("We could not get the current guild from Discord.");
|
const creditsAmount = options.getInteger("amount", true);
|
||||||
}
|
|
||||||
|
|
||||||
const discordReceiver = options.getUser("user");
|
|
||||||
const creditsAmount = options.getInteger("amount");
|
|
||||||
|
|
||||||
if (!discordReceiver || typeof creditsAmount !== "number") {
|
|
||||||
await sendResponse(interaction, "Invalid user or credit amount provided.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const embedSuccess = new EmbedBuilder()
|
const embedSuccess = new EmbedBuilder()
|
||||||
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
.setColor(process.env.EMBED_COLOR_SUCCESS)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
import CreditsManager from "../../../../../../handlers/CreditsManager";
|
||||||
import checkPermission from "../../../../../../utils/checkPermission";
|
import checkPermission from "../../../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../../../utils/deferReply";
|
import deferReply from "../../../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../../../utils/errors";
|
||||||
import sendResponse from "../../../../../../utils/sendResponse";
|
import sendResponse from "../../../../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -44,18 +45,11 @@ export const execute = async (
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
if (!guild) {
|
const fromUser = options.getUser("from-user", true);
|
||||||
throw new Error("We could not get the current guild from Discord.");
|
const toUser = options.getUser("to-user", true);
|
||||||
}
|
const creditsAmount = options.getInteger("amount", true);
|
||||||
|
|
||||||
const fromUser = options.getUser("from-user");
|
|
||||||
const toUser = options.getUser("to-user");
|
|
||||||
const creditsAmount = options.getInteger("amount");
|
|
||||||
|
|
||||||
if (!fromUser || !toUser || typeof creditsAmount !== "number") {
|
|
||||||
throw new Error("Invalid user(s) or credit amount provided.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const transactionResult = await creditsManager.transfer(
|
const transactionResult = await creditsManager.transfer(
|
||||||
guild,
|
guild,
|
||||||
|
|
|
@ -8,6 +8,10 @@ import {
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import checkPermission from "../../../../utils/checkPermission";
|
import checkPermission from "../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import {
|
||||||
|
ChannelNotFoundError,
|
||||||
|
GuildNotFoundError,
|
||||||
|
} from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
|
@ -31,23 +35,23 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { user, options, channel } = interaction;
|
const { guild, user, options, channel } = interaction;
|
||||||
if (!channel) {
|
|
||||||
throw new Error("The bot failed to find the channel to prune messages in.");
|
|
||||||
}
|
|
||||||
|
|
||||||
await deferReply(interaction, false);
|
await deferReply(interaction, false);
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageMessages);
|
checkPermission(interaction, PermissionsBitField.Flags.ManageMessages);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
if (!channel) throw new ChannelNotFoundError();
|
||||||
|
|
||||||
const count = options.getInteger("count");
|
const count = options.getInteger("count", true);
|
||||||
const bots = options.getBoolean("bots");
|
const bots = options.getBoolean("bots");
|
||||||
if (!count || count < 1 || count > 99) {
|
if (count < 1 || count > 99) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Please provide a number between 1 and 99 for the prune command."
|
"Please provide a number between 1 and 99 for the prune command."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel.type !== ChannelType.GuildText) return;
|
if (channel.type !== ChannelType.GuildText)
|
||||||
|
throw new Error("This channel is not a text channel in a guild!");
|
||||||
|
|
||||||
const messagesToDelete = await channel.messages
|
const messagesToDelete = await channel.messages
|
||||||
.fetch({ limit: count + 1 }) // Fetch count + 1 messages to exclude the interaction message itself
|
.fetch({ limit: count + 1 }) // Fetch count + 1 messages to exclude the interaction message itself
|
||||||
|
|
|
@ -10,6 +10,10 @@ import prisma from "../../../../handlers/prisma";
|
||||||
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
||||||
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
import upsertGuildMember from "../../../../helpers/upsertGuildMember";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import {
|
||||||
|
ChannelNotFoundError,
|
||||||
|
GuildNotFoundError,
|
||||||
|
} from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
const cooldownManager = new CooldownManager();
|
const cooldownManager = new CooldownManager();
|
||||||
|
@ -35,10 +39,10 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
export const execute = async (
|
export const execute = async (
|
||||||
interaction: ChatInputCommandInteraction
|
interaction: ChatInputCommandInteraction
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
const { options, guild, user } = interaction;
|
const { options, guild, user } = interaction;
|
||||||
if (!guild) throw new Error("A guild is required.");
|
|
||||||
|
await deferReply(interaction, true);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
const quoteUser = options.getUser("user", true);
|
const quoteUser = options.getUser("user", true);
|
||||||
const quoteString = options.getString("message", true);
|
const quoteString = options.getString("message", true);
|
||||||
|
@ -61,7 +65,7 @@ export const execute = async (
|
||||||
guildQuotesSettings.quoteChannelId
|
guildQuotesSettings.quoteChannelId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!channel) throw new Error("No channel found.");
|
if (!channel) throw new ChannelNotFoundError();
|
||||||
|
|
||||||
if (channel.type !== ChannelType.GuildText)
|
if (channel.type !== ChannelType.GuildText)
|
||||||
throw new Error("The channel is not a text channel.");
|
throw new Error("The channel is not a text channel.");
|
||||||
|
|
|
@ -22,14 +22,11 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, false);
|
|
||||||
|
|
||||||
const { options, user } = interaction;
|
const { options, user } = interaction;
|
||||||
|
|
||||||
|
await deferReply(interaction, false);
|
||||||
const checkUser = options.getUser("user") || user;
|
const checkUser = options.getUser("user") || user;
|
||||||
|
|
||||||
if (!user) throw new Error("User unavailable");
|
|
||||||
|
|
||||||
const userReputation = await reputationManager.check(checkUser);
|
const userReputation = await reputationManager.check(checkUser);
|
||||||
|
|
||||||
const interactionEmbed = new EmbedBuilder()
|
const interactionEmbed = new EmbedBuilder()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import CooldownManager from "../../../../handlers/CooldownManager";
|
||||||
import ReputationManager from "../../../../handlers/ReputationManager";
|
import ReputationManager from "../../../../handlers/ReputationManager";
|
||||||
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
import generateCooldownName from "../../../../helpers/generateCooldownName";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
const cooldownManager = new CooldownManager();
|
const cooldownManager = new CooldownManager();
|
||||||
|
@ -37,21 +38,13 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
const { options, user, guild } = interaction;
|
const { options, user, guild } = interaction;
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
if (!guild) {
|
await deferReply(interaction, true);
|
||||||
throw new Error("This command can only be used in guilds");
|
if (!guild) throw new GuildNotFoundError();
|
||||||
}
|
|
||||||
|
|
||||||
const targetUser = options.getUser("user", true);
|
const targetUser = options.getUser("user", true);
|
||||||
const reputationType = options.getString("type", true);
|
const reputationType = options.getString("type", true);
|
||||||
|
|
||||||
if (!targetUser) {
|
|
||||||
throw new Error(
|
|
||||||
"Sorry, we were unable to find the user you are trying to give reputation to."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reputationType !== "positive" && reputationType !== "negative") {
|
if (reputationType !== "positive" && reputationType !== "negative") {
|
||||||
throw new Error("Invalid reputation type");
|
throw new Error("Invalid reputation type");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import prisma from "../../../../handlers/prisma";
|
import prisma from "../../../../handlers/prisma";
|
||||||
import checkPermission from "../../../../utils/checkPermission";
|
import checkPermission from "../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
@ -32,26 +33,14 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
|
||||||
|
|
||||||
const { guild, options, user } = interaction;
|
const { guild, options, user } = interaction;
|
||||||
|
|
||||||
const workBonusChance = options.getNumber("work-bonus-chance");
|
await deferReply(interaction, true);
|
||||||
const workPenaltyChance = options.getNumber("work-penalty-chance");
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
if (!guild) {
|
const workBonusChance = options.getNumber("work-bonus-chance", true);
|
||||||
throw new Error("Guild not found.");
|
const workPenaltyChance = options.getNumber("work-penalty-chance", true);
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof workBonusChance !== "number") {
|
|
||||||
throw new Error("Work Bonus Chance must be a number.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof workPenaltyChance !== "number") {
|
|
||||||
throw new Error("Work Penalty Chance must be a number.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const upsertGuildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
const upsertGuildCreditsSettings = await prisma.guildCreditsSettings.upsert({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import CtrlPanelAPI, {
|
||||||
} from "../../../../services/CtrlPanelAPI";
|
} from "../../../../services/CtrlPanelAPI";
|
||||||
import checkPermission from "../../../../utils/checkPermission";
|
import checkPermission from "../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import logger from "../../../../utils/logger";
|
import logger from "../../../../utils/logger";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
|
@ -35,12 +36,11 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
|
||||||
|
|
||||||
const { guild, options, user } = interaction;
|
const { guild, options, user } = interaction;
|
||||||
if (!guild) throw new Error("Guild unavailable");
|
|
||||||
|
await deferReply(interaction, true);
|
||||||
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
const scheme = options.getString("scheme", true);
|
const scheme = options.getString("scheme", true);
|
||||||
const domain = options.getString("domain", true);
|
const domain = options.getString("domain", true);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import prisma from "../../../../handlers/prisma";
|
import prisma from "../../../../handlers/prisma";
|
||||||
import checkPermission from "../../../../utils/checkPermission";
|
import checkPermission from "../../../../utils/checkPermission";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
@ -22,19 +23,15 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
|
||||||
|
|
||||||
const { guild, options, user } = interaction;
|
const { guild, options, user } = interaction;
|
||||||
|
|
||||||
|
await deferReply(interaction, true);
|
||||||
|
checkPermission(interaction, PermissionsBitField.Flags.ManageGuild);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
const quoteStatus = options.getBoolean("status", true);
|
const quoteStatus = options.getBoolean("status", true);
|
||||||
const quoteChannel = options.getChannel("channel", true);
|
const quoteChannel = options.getChannel("channel", true);
|
||||||
|
|
||||||
if (!guild) {
|
|
||||||
throw new Error("Guild not found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const upsertGuildQuotesSettings = await prisma.guildQuotesSettings.upsert({
|
const upsertGuildQuotesSettings = await prisma.guildQuotesSettings.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: guild.id,
|
id: guild.id,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||||
import CreditsManager from "../../../handlers/CreditsManager";
|
import CreditsManager from "../../../handlers/CreditsManager";
|
||||||
import CtrlPanelAPI from "../../../services/CtrlPanelAPI";
|
import CtrlPanelAPI from "../../../services/CtrlPanelAPI";
|
||||||
import deferReply from "../../../utils/deferReply";
|
import deferReply from "../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../utils/errors";
|
||||||
import sendResponse from "../../../utils/sendResponse";
|
import sendResponse from "../../../utils/sendResponse";
|
||||||
|
|
||||||
const creditsManager = new CreditsManager();
|
const creditsManager = new CreditsManager();
|
||||||
|
@ -30,15 +31,13 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
export const execute = async (interaction: ChatInputCommandInteraction) => {
|
||||||
await deferReply(interaction, true);
|
|
||||||
|
|
||||||
const { options, guild, user, client } = interaction;
|
const { options, guild, user, client } = interaction;
|
||||||
if (!guild) throw new Error("This command can only be executed in a guild");
|
|
||||||
|
await deferReply(interaction, true);
|
||||||
|
if (!guild) throw new GuildNotFoundError();
|
||||||
|
|
||||||
const ctrlPanelAPI = new CtrlPanelAPI(guild);
|
const ctrlPanelAPI = new CtrlPanelAPI(guild);
|
||||||
|
|
||||||
const withdrawalAmount = options.getInteger("withdraw", true);
|
const withdrawalAmount = options.getInteger("withdraw", true);
|
||||||
|
|
||||||
await creditsManager.take(guild, user, withdrawalAmount);
|
await creditsManager.take(guild, user, withdrawalAmount);
|
||||||
|
|
||||||
const voucherCode = uuidv4();
|
const voucherCode = uuidv4();
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
SlashCommandSubcommandBuilder,
|
SlashCommandSubcommandBuilder,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import deferReply from "../../../../utils/deferReply";
|
import deferReply from "../../../../utils/deferReply";
|
||||||
|
import { GuildNotFoundError } from "../../../../utils/errors";
|
||||||
import sendResponse from "../../../../utils/sendResponse";
|
import sendResponse from "../../../../utils/sendResponse";
|
||||||
|
|
||||||
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
|
@ -17,13 +18,10 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: CommandInteraction) => {
|
export const execute = async (interaction: CommandInteraction) => {
|
||||||
await deferReply(interaction, false);
|
|
||||||
|
|
||||||
const { user, guild, client } = interaction;
|
const { user, guild, client } = interaction;
|
||||||
|
|
||||||
if (!guild) {
|
await deferReply(interaction, false);
|
||||||
throw new Error("This command is only available in guilds");
|
if (!guild) throw new GuildNotFoundError();
|
||||||
}
|
|
||||||
|
|
||||||
const guildCount = client.guilds.cache.size;
|
const guildCount = client.guilds.cache.size;
|
||||||
const memberCount = client.guilds.cache.reduce(
|
const memberCount = client.guilds.cache.reduce(
|
||||||
|
|
|
@ -18,12 +18,10 @@ export const builder = (command: SlashCommandSubcommandBuilder) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const execute = async (interaction: CommandInteraction) => {
|
export const execute = async (interaction: CommandInteraction) => {
|
||||||
await deferReply(interaction, false);
|
|
||||||
|
|
||||||
const { options, user } = interaction;
|
const { options, user } = interaction;
|
||||||
|
|
||||||
|
await deferReply(interaction, false);
|
||||||
const userOption = options.getUser("user");
|
const userOption = options.getUser("user");
|
||||||
|
|
||||||
const targetUser = userOption || user;
|
const targetUser = userOption || user;
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
|
10
src/utils/ensureGuildExists.ts
Normal file
10
src/utils/ensureGuildExists.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Guild, Interaction } from "discord.js";
|
||||||
|
|
||||||
|
export default function ensureGuildExists(interaction: Interaction): Guild {
|
||||||
|
if (!interaction.guild) {
|
||||||
|
throw new Error(
|
||||||
|
"Oops! It looks like you're not part of a guild. Join a guild to embark on this adventure!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return interaction.guild;
|
||||||
|
}
|
10
src/utils/ensureUserExists.ts
Normal file
10
src/utils/ensureUserExists.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Interaction, User } from "discord.js";
|
||||||
|
|
||||||
|
export default function ensureUserExists(interaction: Interaction): User {
|
||||||
|
if (!interaction.user) {
|
||||||
|
throw new Error(
|
||||||
|
"Oops! We couldn't find your user information. Please try again or contact support for assistance."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return interaction.user;
|
||||||
|
}
|
32
src/utils/errors.ts
Normal file
32
src/utils/errors.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
class CustomError extends Error {
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GuildNotFoundError extends CustomError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"Guild not found: You are not part of a guild. Join a guild to embark on this adventure."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserNotFoundError extends CustomError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"User not found: We couldn't retrieve your user information. Please try again or contact support for assistance."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChannelNotFoundError extends CustomError {
|
||||||
|
constructor() {
|
||||||
|
super(
|
||||||
|
"Channel not found: We couldn't retrieve the channel. Please try again or contact support for assistance."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { GuildNotFoundError, UserNotFoundError, ChannelNotFoundError };
|
Loading…
Add table
Reference in a new issue