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
7 changes: 5 additions & 2 deletions src/common/events/load-events.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import type { Client } from 'discord.js';
import { events } from './index.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('events');

export const loadEvents = (client: Client) => {
for (const event of events) {
console.log(`Loading event: ${event.name}`);
logger.log(`Loading event: ${event.name}`);
client[event.once ? 'once' : 'on'](event.name, async (...args) => {
try {
await event.execute(...args);
} catch (error) {
console.error(`Error executing event ${event.name}:`, error);
logger.error(`Error executing event ${event.name}:`, error);
}
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/common/interactions/autocomplete-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { AutocompleteInteraction } from 'discord.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('interactions');

export type AutoCompleteSubmitInteraction = {
commandName: string;
Expand All @@ -13,7 +16,7 @@ export const autoCompleteInteractions = new Map<
export const registerAutocompleteInteraction = (
interaction: AutoCompleteSubmitInteraction
) => {
console.log(
logger.log(
`Registering autocomplete interaction: ${interaction.commandName}`
);
autoCompleteInteractions.set(interaction.commandName, interaction);
Expand Down
5 changes: 4 additions & 1 deletion src/common/interactions/button-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ButtonInteraction } from 'discord.js';
import { parseCustomId } from '@/util/custom-id.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('interactions');

export type ButtonSubmitInteraction = {
commandName: string;
Expand All @@ -14,7 +17,7 @@ export const buttonSubmitInteractions = new Map<
export const registerButtonSubmitInteraction = (
interaction: ButtonSubmitInteraction
) => {
console.log(
logger.log(
`Registering button submit interaction: ${interaction.commandName}`
);
buttonSubmitInteractions.set(interaction.commandName, interaction);
Expand Down
5 changes: 4 additions & 1 deletion src/common/interactions/modal-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ModalSubmitInteraction as ModalInteraction } from 'discord.js';
import { parseCustomId } from '@/util/custom-id.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('interactions');

export type ModalSubmitInteraction = {
commandName: string;
Expand All @@ -14,7 +17,7 @@ export const modalSubmitInteractions = new Map<
export const registerModalSubmitInteraction = (
interaction: ModalSubmitInteraction
) => {
console.log(
logger.log(
`Registering modal submit interaction: ${interaction.commandName}`
);
modalSubmitInteractions.set(interaction.commandName, interaction);
Expand Down
5 changes: 4 additions & 1 deletion src/common/interactions/select-menu-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { StringSelectMenuInteraction } from 'discord.js';
import { parseCustomId } from '@/util/custom-id.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('interactions');

export type SelectMenuSubmitInteraction = {
commandName: string;
Expand All @@ -14,7 +17,7 @@ export const selectMenuSubmitInteractions = new Map<
export const registerSelectMenuSubmitInteraction = (
interaction: SelectMenuSubmitInteraction
) => {
console.log(
logger.log(
`Registering select menu submit interaction: ${interaction.commandName}`
);
selectMenuSubmitInteractions.set(interaction.commandName, interaction);
Expand Down
13 changes: 8 additions & 5 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// oxlint-disable id-length
import '@/loadEnvFile.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('env');

function optionalEnv(key: string): string | undefined {
return process.env[key];
Expand All @@ -8,8 +11,8 @@ function optionalEnv(key: string): string | undefined {
function requireEnv(key: string): string {
const value = process.env[key];
if (!value) {
console.error(`❌ Required environment variable ${key} is not set`);
console.error('Please check your .env file or CI/CD configuration');
logger.error(`❌ Required environment variable ${key} is not set`);
logger.error('Please check your .env file or CI/CD configuration');
process.exit(1);
}
return value;
Expand Down Expand Up @@ -57,10 +60,10 @@ export const config = {

export type Config = typeof config;

console.log('✅ Configuration loaded successfully');
console.log(
logger.log('✅ Configuration loaded successfully');
logger.log(
`📋 Client ID: ${config.discord.clientId ? config.discord.clientId : '❌ missing'}`
);
console.log(
logger.log(
`🔑 Token: ${config.discord.token ? '***configured***' : '❌ missing'}`
);
5 changes: 4 additions & 1 deletion src/features/auto-roles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Events } from 'discord.js';
import { createEvent } from '@/common/events/create-event.js';
import { config } from '@/env.js';
import { hasAllRoles } from '@/util/member.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('auto-roles');

export const autoRoleEvent = createEvent(
{
Expand All @@ -22,7 +25,7 @@ export const autoRoleEvent = createEvent(
try {
await newMember.roles.add(config.roleIds.c);
} catch (error) {
console.error(`Failed to add roleC to ${newMember.user.tag}:`, error);
logger.error(`Failed to add roleC to ${newMember.user.tag}:`, error);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/features/docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { type CommandInteraction, MessageFlags } from 'discord.js';
import { logToChannel } from '@/util/channel-logging.js';
import type { FeatureData } from './baseline.js';
import type { ProviderConfig } from './types.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('docs');

export const SEARCH_TERM = '%SEARCH%';
export const TERM = '%TERM%';
Expand Down Expand Up @@ -31,7 +34,7 @@ export const executeDocCommand = async (
try {
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
} catch (error) {
console.error(`deferReply FAILED:`, error);
logger.error(`deferReply FAILED:`, error);
return;
}

Expand Down Expand Up @@ -90,12 +93,12 @@ export const executeDocCommand = async (
},
});
} else if (componentInteraction.isButton()) {
console.log('Documentation command cancelled by user.');
logger.log('Documentation command cancelled by user.');
await interaction.deleteReply();
}
});
} catch (error) {
console.error(`executeDocCommand FAILED:`, error);
logger.error(`executeDocCommand FAILED:`, error);
await interaction.editReply({ content: `Error: ${String(error)}` });
}
};
Expand Down
13 changes: 8 additions & 5 deletions src/features/interaction-create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import { handleButtonInteraction } from '@/common/interactions/button-interactio
import { handleModalInteraction } from '@/common/interactions/modal-interaction.js';
import { handleSelectMenuInteraction } from '@/common/interactions/select-menu-interaction.js';
import { isAllowedServer } from '@/util/server-guard.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('interactions');

export const interactionCreateEvent = createEvent(
{
name: Events.InteractionCreate,
},
async (interaction) => {
if (!interaction.guildId || !isAllowedServer(interaction.guildId)) {
console.log(
logger.log(
`⚠️ Command blocked from unauthorized server: ${interaction.guildId}`
);
if (interaction.isRepliable()) {
Expand All @@ -25,31 +28,31 @@ export const interactionCreateEvent = createEvent(
return;
}
if (interaction.isButton()) {
console.log(
logger.log(
`Received button interaction with custom ID: ${interaction.customId}`
);
await handleButtonInteraction(interaction);
return;
}

if (interaction.isModalSubmit()) {
console.log(
logger.log(
`Received modal submit interaction with custom ID: ${interaction.customId}`
);
await handleModalInteraction(interaction);
return;
}

if (interaction.isStringSelectMenu()) {
console.log(
logger.log(
`Received select menu interaction with custom ID: ${interaction.customId}`
);
await handleSelectMenuInteraction(interaction);
return;
}

if (interaction.isAutocomplete()) {
console.log(
logger.log(
`Received autocomplete interaction with custom ID: ${interaction.commandName}`
);
await handleAutoCompleteInteraction(interaction);
Expand Down
15 changes: 9 additions & 6 deletions src/features/moderation/repel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { buildCommandString } from '../../util/build-command-string.js';
import { getPublicChannels } from '../../util/channel.js';
import { logToChannel } from '../../util/channel-logging.js';
import { SERVER_CHANNELS } from '@/constants/channels.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('moderation');

const DEFAULT_LOOK_BACK_MS = 10 * MINUTE;
const DEFAULT_TIMEOUT_DURATION_MS = 1 * HOUR;
Expand Down Expand Up @@ -149,7 +152,7 @@ const getTargetFromInteraction = async (
try {
target = await interaction.guild.members.fetch(targetFromOption.id);
} catch (error) {
console.error('Error fetching target as guild member:', error);
logger.error('Error fetching target as guild member:', error);
target = targetFromOption;
}
return target;
Expand All @@ -173,14 +176,14 @@ const handleTimeout = async ({
await target.timeout(durationInMilliseconds, 'Repel command executed');
return durationInMilliseconds;
} catch (error) {
console.error('Error applying timeout to user:', error);
logger.error('Error applying timeout to user:', error);
return 0;
}
};

const getTextChannels = (interaction: ChatInputCommandInteraction) => {
if (!interaction.inGuild() || !interaction.guild) {
console.error('Interaction is not in a guild');
logger.error('Interaction is not in a guild');
return [];
}
const channels = Array.from(getPublicChannels(interaction.guild).values());
Expand Down Expand Up @@ -254,7 +257,7 @@ const handleDeleteMessages = async ({
await channel.bulkDelete(messagesToDelete, true);
deleted += messagesToDelete.length;
} catch (error) {
console.error(
logger.error(
`Error deleting messages in channel ${channel.name}:`,
error
);
Expand All @@ -264,7 +267,7 @@ const handleDeleteMessages = async ({
})
);
if (failedChannels.length > 0) {
console.error(
logger.error(
`Failed to delete messages in ${failedChannels.length} channel(s).`
);
}
Expand Down Expand Up @@ -565,7 +568,7 @@ export const repelCommand = createSlashCommand({
content: `Deleted ${deleted} message(s).`,
});
} catch (error) {
console.error('Error executing repel command:', error);
logger.error('Error executing repel command:', error);
}
},
});
5 changes: 4 additions & 1 deletion src/features/onboarding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { createSlashCommand } from '../../common/commands/create-commands.js';
import { config } from '../../env.js';
import { addRoleToUser } from '../../util/add-role-to-user.js';
import { containerComponent } from './component.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('onboarding');

export const onboardingCommand = createSlashCommand({
data: {
Expand Down Expand Up @@ -64,7 +67,7 @@ export const onboardingCommand = createSlashCommand({
content: `Failed to add role. Please contact an administrator.`,
flags: MessageFlags.Ephemeral,
});
console.error('Error adding role:\n', error);
logger.error('Error adding role:\n', error);
}
}
});
Expand Down
5 changes: 4 additions & 1 deletion src/features/public-guides/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
initializeGuidesChannel,
syncGuidesToChannel,
} from '@/util/post-guides.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('guides');

export const publicGuidesCommand = createSlashCommand({
data: {
Expand Down Expand Up @@ -49,7 +52,7 @@ export const publicGuidesCommand = createSlashCommand({
'✅ Guides have been synchronized successfully.'
);
} catch (error) {
console.error('Error synchronizing guides:', error);
logger.error('Error synchronizing guides:', error);
await interaction.editReply(
'❌ An error occurred while synchronizing guides. Please check the logs for details.'
);
Expand Down
5 changes: 4 additions & 1 deletion src/features/quote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Client, Events, type Message } from 'discord.js';
import { createEvent } from '@/common/events/create-event.js';
import { UserBotMessagesService } from '@/services/user-bot-messages/user-bot-messages-service.js';
import { createQuoteEmbed } from './embed.js';
import { createLogger } from '@/util/logger.js';

const logger = createLogger('quote');

export const quoteEvent = createEvent(
{
Expand Down Expand Up @@ -91,7 +94,7 @@ export const quoteEvent = createEvent(

for (const result of results) {
if (result.status === 'rejected') {
console.error('Failed to send quote message:', result.reason);
logger.error('Failed to send quote message:', result.reason);
}
}

Expand Down
Loading
Loading