Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/commands/about.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EmbedBuilder, MessageFlags, SlashCommandBuilder } from "discord.js";
import { EmbedBuilder, SlashCommandBuilder } from "discord.js";

import type { Client, CommandInteraction, User } from "discord.js";

import env from "../utils/env.js";
import logger from "../utils/logger.js";
import { safeErrorReply } from "../utils/commandErrors.js";

export const slashCommand = new SlashCommandBuilder()
.setName("about")
Expand Down Expand Up @@ -76,12 +77,7 @@ export async function execute(client: Client, interaction: CommandInteraction) {
command: "about",
});

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/commands/admin/activity/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { CommandInteractionOptionResolver } from "discord.js";
import type { DiscordActivityType } from "../../../database/schema.js";

import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { discordActivities } from "../../../database/schema.js";
Expand Down Expand Up @@ -73,11 +74,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/admin/activity/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { desc } from "drizzle-orm";
import type { DiscordActivity } from "../../../database/schema.js";

import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { discordActivities } from "../../../database/schema.js";
Expand Down Expand Up @@ -68,11 +69,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
9 changes: 2 additions & 7 deletions src/commands/admin/activity/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { CommandInteractionOptionResolver } from "discord.js";
import { eq } from "drizzle-orm";

import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { discordActivities } from "../../../database/schema.js";
Expand Down Expand Up @@ -71,12 +72,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content:
"An error occurred while deleting the activity. Please try again.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
CommandInteractionOptionResolver,
} from "discord.js";
import logger from "../../utils/logger.js";
import { safeErrorReply } from "../../utils/commandErrors.js";

/**
* Import subcommands
Expand Down Expand Up @@ -290,12 +291,7 @@ export async function execute(client: Client, interaction: CommandInteraction) {
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}

Expand Down
23 changes: 4 additions & 19 deletions src/commands/admin/quote/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import type { CommandInteractionOptionResolver } from "discord.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { motivationQuotes } from "../../../database/schema.js";
import env from "../../../utils/env.js";
import logger from "../../../utils/logger.js";
import { sendToMainChannel } from "../../../utils/mainChannel.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";

export default async function (
client: Client,
Expand Down Expand Up @@ -83,18 +84,7 @@ export default async function (
})
.setTimestamp();

if (env.MAIN_CHANNEL_ID) {
const channel = await client.channels.fetch(env.MAIN_CHANNEL_ID);
if (channel?.isTextBased() && !channel.isDMBased()) {
await channel.send({ embeds: [embed] });
} else {
logger.warn("Admin", "Main channel not found or not text-based", {
channelId: env.MAIN_CHANNEL_ID,
});
}
} else {
logger.warn("Admin", "MAIN_CHANNEL_ID not configured");
}
await sendToMainChannel(client, { embeds: [embed] });

await interaction.reply({
content: `Quote created with id: ${newQuote.id}`,
Expand All @@ -114,11 +104,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/admin/quote/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { desc } from "drizzle-orm";
import type { MotivationQuote } from "../../../database/schema.js";

import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { motivationQuotes } from "../../../database/schema.js";
Expand Down Expand Up @@ -67,11 +68,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
23 changes: 7 additions & 16 deletions src/commands/admin/quote/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import logger from "../../../utils/logger.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { motivationQuotes } from "../../../database/schema.js";
import env from "../../../utils/env.js";
import { sendToMainChannel } from "../../../utils/mainChannel.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";

export default async function (
client: Client,
Expand Down Expand Up @@ -49,15 +50,10 @@ export default async function (

await db.delete(motivationQuotes).where(eq(motivationQuotes.id, quoteId));

// send message to main channel
if (env.MAIN_CHANNEL_ID) {
const mainChannel = await client.channels.fetch(env.MAIN_CHANNEL_ID);
if (mainChannel?.isTextBased() && !mainChannel.isDMBased()) {
await mainChannel.send(
`Quote deleted by ${interaction.user.username} with id: ${quoteId}`
);
}
}
await sendToMainChannel(
client,
`Quote deleted by ${interaction.user.username} with id: ${quoteId}`
);

await interaction.reply({
content: `Quote deleted with id: ${quoteId}`,
Expand All @@ -77,11 +73,6 @@ export default async function (
err
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
17 changes: 4 additions & 13 deletions src/commands/admin/suggestion/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { eq } from "drizzle-orm";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { motivationQuotes, suggestionQuotes } from "../../../database/schema.js";
import env from "../../../utils/env.js";
import logger from "../../../utils/logger.js";
import { sendToMainChannel } from "../../../utils/mainChannel.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";

export default async function (
client: Client,
Expand Down Expand Up @@ -88,12 +89,7 @@ export default async function (
.setFooter({ text: `Suggestion ID: ${suggestionId}` })
.setTimestamp();

if (env.MAIN_CHANNEL_ID) {
const channel = await client.channels.fetch(env.MAIN_CHANNEL_ID);
if (channel?.isTextBased() && !channel.isDMBased()) {
await channel.send({ embeds: [embed] });
}
}
await sendToMainChannel(client, { embeds: [embed] });

try {
const submitter = await client.users.fetch(suggestion.addedBy);
Expand Down Expand Up @@ -135,11 +131,6 @@ export default async function (
err,
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/admin/suggestion/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { eq, desc } from "drizzle-orm";
import type { SuggestionQuote } from "../../../database/schema.js";

import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { suggestionQuotes } from "../../../database/schema.js";
Expand Down Expand Up @@ -73,11 +74,6 @@ export default async function (
err,
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
17 changes: 4 additions & 13 deletions src/commands/admin/suggestion/reject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { eq, and } from "drizzle-orm";
import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { suggestionQuotes } from "../../../database/schema.js";
import env from "../../../utils/env.js";
import logger from "../../../utils/logger.js";
import { sendToMainChannel } from "../../../utils/mainChannel.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";

export default async function (
client: Client,
Expand Down Expand Up @@ -98,12 +99,7 @@ export default async function (
.setFooter({ text: `Suggestion ID: ${suggestionId}` })
.setTimestamp();

if (env.MAIN_CHANNEL_ID) {
const channel = await client.channels.fetch(env.MAIN_CHANNEL_ID);
if (channel?.isTextBased() && !channel.isDMBased()) {
await channel.send({ embeds: [embed] });
}
}
await sendToMainChannel(client, { embeds: [embed] });

try {
const submitter = await client.users.fetch(suggestion.addedBy);
Expand Down Expand Up @@ -148,11 +144,6 @@ export default async function (
err,
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/admin/suggestion/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isUserPermitted } from "../../../utils/permissions.js";
import { db } from "../../../database/index.js";
import { suggestionQuotes } from "../../../database/schema.js";
import logger from "../../../utils/logger.js";
import { safeErrorReply } from "../../../utils/commandErrors.js";

export default async function (
_client: Client,
Expand Down Expand Up @@ -71,11 +72,6 @@ export default async function (
err,
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}
8 changes: 2 additions & 6 deletions src/commands/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SlashCommandBuilder, EmbedBuilder, MessageFlags } from "discord.js";
import type { Client, CommandInteraction } from "discord.js";

import logger from "../utils/logger.js";
import { safeErrorReply } from "../utils/commandErrors.js";

export const slashCommand = new SlashCommandBuilder()
.setName("changelog")
Expand Down Expand Up @@ -81,12 +82,7 @@ export async function execute(_client: Client, interaction: CommandInteraction)
}
);

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Client, CommandInteraction } from "discord.js";
import { SlashCommandBuilder, MessageFlags } from "discord.js";

import logger from "../utils/logger.js";
import { safeErrorReply } from "../utils/commandErrors.js";

export const slashCommand = new SlashCommandBuilder()
.setName("help")
Expand Down Expand Up @@ -47,12 +48,7 @@ export async function execute(_client: Client, interaction: CommandInteraction)
command: "help",
});

if (!interaction.replied && !interaction.deferred) {
await interaction.reply({
content: "An error occurred while processing your request.",
flags: MessageFlags.Ephemeral,
});
}
await safeErrorReply(interaction);
}
}

Expand Down
Loading
Loading