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: 4 additions & 6 deletions src/commands/moderation/repel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from 'discord.js';
import { HOUR, MINUTE, timeToString } from '../../constants/time.js';
import { config } from '../../env.js';
import { logToChannel } from '../../util/channel-logging.js';
import { getPublicChannels } from '../../util/channel.js';
import { logToChannel } from '../../util/channel-logging.js';
import { buildCommandString, createCommand } from '../../util/commands.js';

const DEFAULT_LOOK_BACK_MS = 10 * MINUTE;
Expand Down Expand Up @@ -287,11 +287,9 @@ const logRepelAction = async ({

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

const embed =
failedChannelsEmbed !== null
Expand Down Expand Up @@ -390,7 +388,7 @@ export const repelCommand = createCommand({
}
await interaction.deferReply({ flags: MessageFlags.Ephemeral });

const repelRole = interaction.guild.roles.cache.get(config.repel.repelRoleId);
const repelRole = interaction.guild.roles.cache.get(config.roleIds.repel);
if (!repelRole) {
await interaction.editReply({
content: '❌ Repel role is not configured correctly. Please contact an administrator.',
Expand Down
35 changes: 14 additions & 21 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,22 @@ export const config = {
token: requireEnv('DISCORD_TOKEN'),
clientId: requireEnv('CLIENT_ID'),
},
repel: {
repelLogChannelId: requireEnv('REPEL_LOG_CHANNEL_ID'),
repelRoleId: requireEnv('REPEL_ROLE_ID'),
},
fetchAndSyncMessages: true,
serverId: requireEnv('SERVER_ID'),
moderatorsRoleIds: requireEnv('MODERATORS_ROLE_IDS')
? requireEnv('MODERATORS_ROLE_IDS').split(',')
: [],
guides: {
channelId: requireEnv('GUIDES_CHANNEL_ID'),
trackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
fetchAndSyncMessages: true,
guidesTrackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
roleIds: {
moderators: requireEnv('MODERATORS_ROLE_IDS')
? requireEnv('MODERATORS_ROLE_IDS').split(',')
: [],
repel: requireEnv('REPEL_ROLE_ID'),
a: requireEnv('ROLE_A_ID'),
b: requireEnv('ROLE_B_ID'),
c: requireEnv('ROLE_C_ID'),
},
channelIds: {
repelLogs: requireEnv('REPEL_LOG_CHANNEL_ID'),
guides: requireEnv('GUIDES_CHANNEL_ID'),
},
// roleA: requireEnv('ROLE_A_ID'),
// roleB: requireEnv('ROLE_B_ID'),
// roleC: requireEnv('ROLE_C_ID'),
// Add more config sections as needed:
// database: {
// url: requireEnv('DATABASE_URL'),
// },
// api: {
// openaiKey: optionalEnv('OPENAI_API_KEY'),
// },
};

export type Config = typeof config;
Expand Down
6 changes: 3 additions & 3 deletions src/events/auto-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const autoRoleEvent = createEvent(
name: Events.GuildMemberUpdate,
},
async (_, newMember) => {
const hasRoleC = hasRoles(newMember, config.roleC);
const hasRoleC = hasRoles(newMember, config.roleIds.c);
if (!hasRoleC) {
const hasRequiredRoles = hasRoles(newMember, config.roleA, config.roleB);
const hasRequiredRoles = hasRoles(newMember, config.roleIds.a, config.roleIds.b);
if (hasRequiredRoles) {
try {
await newMember.roles.add(config.roleC);
await newMember.roles.add(config.roleIds.c);
} catch (error) {
console.error(`Failed to add roleC to ${newMember.user.tag}:`, error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const readyEvent = createEvent(

// Sync guides to channel
try {
console.log(`🔄 Starting guide sync to channel ${config.guides.channelId}...`);
await syncGuidesToChannel(client, config.guides.channelId);
console.log(`🔄 Starting guide sync to channel ${config.channelIds.guides}...`);
await syncGuidesToChannel(client, config.channelIds.guides);
} catch (error) {
if (error && typeof error === 'object' && 'code' in error) {
const discordError = error as { code: number; message?: string };
Expand Down
2 changes: 1 addition & 1 deletion src/util/post-guides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type GuideTracker = {

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

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

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