Skip to content

Commit 60b3f4f

Browse files
authored
🌟 feat: update configuration structure to group roles and channels for better organization (#34)
1 parent 96ff69c commit 60b3f4f

File tree

5 files changed

+24
-33
lines changed

5 files changed

+24
-33
lines changed

src/commands/moderation/repel.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
} from 'discord.js';
1515
import { HOUR, MINUTE, timeToString } from '../../constants/time.js';
1616
import { config } from '../../env.js';
17-
import { logToChannel } from '../../util/channel-logging.js';
1817
import { getPublicChannels } from '../../util/channel.js';
18+
import { logToChannel } from '../../util/channel-logging.js';
1919
import { buildCommandString, createCommand } from '../../util/commands.js';
2020

2121
const DEFAULT_LOOK_BACK_MS = 10 * MINUTE;
@@ -287,11 +287,9 @@ const logRepelAction = async ({
287287

288288
const modMessage = interaction.options.getString(RepelOptions.MESSAGE_FOR_MODS) ?? false;
289289
const mentionText = modMessage
290-
? `${config.moderatorsRoleIds.map((id) => `<@&${id}>`)} - ${modMessage}`
290+
? `${config.roleIds.moderators.map((id) => `<@&${id}>`)} - ${modMessage}`
291291
: undefined;
292-
const channel = interaction.client.channels.cache.get(
293-
config.repel.repelLogChannelId
294-
) as TextChannel;
292+
const channel = interaction.client.channels.cache.get(config.channelIds.repelLogs) as TextChannel;
295293

296294
const embed =
297295
failedChannelsEmbed !== null
@@ -390,7 +388,7 @@ export const repelCommand = createCommand({
390388
}
391389
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
392390

393-
const repelRole = interaction.guild.roles.cache.get(config.repel.repelRoleId);
391+
const repelRole = interaction.guild.roles.cache.get(config.roleIds.repel);
394392
if (!repelRole) {
395393
await interaction.editReply({
396394
content: '❌ Repel role is not configured correctly. Please contact an administrator.',

src/env.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,22 @@ export const config = {
2020
token: requireEnv('DISCORD_TOKEN'),
2121
clientId: requireEnv('CLIENT_ID'),
2222
},
23-
repel: {
24-
repelLogChannelId: requireEnv('REPEL_LOG_CHANNEL_ID'),
25-
repelRoleId: requireEnv('REPEL_ROLE_ID'),
26-
},
27-
fetchAndSyncMessages: true,
2823
serverId: requireEnv('SERVER_ID'),
29-
moderatorsRoleIds: requireEnv('MODERATORS_ROLE_IDS')
30-
? requireEnv('MODERATORS_ROLE_IDS').split(',')
31-
: [],
32-
guides: {
33-
channelId: requireEnv('GUIDES_CHANNEL_ID'),
34-
trackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
24+
fetchAndSyncMessages: true,
25+
guidesTrackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
26+
roleIds: {
27+
moderators: requireEnv('MODERATORS_ROLE_IDS')
28+
? requireEnv('MODERATORS_ROLE_IDS').split(',')
29+
: [],
30+
repel: requireEnv('REPEL_ROLE_ID'),
31+
a: requireEnv('ROLE_A_ID'),
32+
b: requireEnv('ROLE_B_ID'),
33+
c: requireEnv('ROLE_C_ID'),
34+
},
35+
channelIds: {
36+
repelLogs: requireEnv('REPEL_LOG_CHANNEL_ID'),
37+
guides: requireEnv('GUIDES_CHANNEL_ID'),
3538
},
36-
// roleA: requireEnv('ROLE_A_ID'),
37-
// roleB: requireEnv('ROLE_B_ID'),
38-
// roleC: requireEnv('ROLE_C_ID'),
39-
// Add more config sections as needed:
40-
// database: {
41-
// url: requireEnv('DATABASE_URL'),
42-
// },
43-
// api: {
44-
// openaiKey: optionalEnv('OPENAI_API_KEY'),
45-
// },
4639
};
4740

4841
export type Config = typeof config;

src/events/auto-roles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export const autoRoleEvent = createEvent(
88
name: Events.GuildMemberUpdate,
99
},
1010
async (_, newMember) => {
11-
const hasRoleC = hasRoles(newMember, config.roleC);
11+
const hasRoleC = hasRoles(newMember, config.roleIds.c);
1212
if (!hasRoleC) {
13-
const hasRequiredRoles = hasRoles(newMember, config.roleA, config.roleB);
13+
const hasRequiredRoles = hasRoles(newMember, config.roleIds.a, config.roleIds.b);
1414
if (hasRequiredRoles) {
1515
try {
16-
await newMember.roles.add(config.roleC);
16+
await newMember.roles.add(config.roleIds.c);
1717
} catch (error) {
1818
console.error(`Failed to add roleC to ${newMember.user.tag}:`, error);
1919
}

src/events/ready.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const readyEvent = createEvent(
2727

2828
// Sync guides to channel
2929
try {
30-
console.log(`🔄 Starting guide sync to channel ${config.guides.channelId}...`);
31-
await syncGuidesToChannel(client, config.guides.channelId);
30+
console.log(`🔄 Starting guide sync to channel ${config.channelIds.guides}...`);
31+
await syncGuidesToChannel(client, config.channelIds.guides);
3232
} catch (error) {
3333
if (error && typeof error === 'object' && 'code' in error) {
3434
const discordError = error as { code: number; message?: string };

src/util/post-guides.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type GuideTracker = {
3333

3434
const GUIDES_DIR = fileURLToPath(new URL('../commands/guides/subjects/', import.meta.url));
3535

36-
const TRACKER_FILE = config.guides.trackerPath ?? 'guides-tracker.json';
36+
const TRACKER_FILE = config.guidesTrackerPath ?? 'guides-tracker.json';
3737

3838
const calculateHash = (content: string): string => {
3939
return createHash('sha256').update(content, 'utf8').digest('hex');

0 commit comments

Comments
 (0)