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
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const config = {
clientId: requireEnv('CLIENT_ID'),
serverId: requireEnv('SERVER_ID'),
},
fetchAndSyncMessages: true,
fetchAndSyncMessages: optionalEnv('FETCH_AND_SYNC_MESSAGES') !== 'false',
Comment thread
hmd-ali marked this conversation as resolved.
guidesTrackerPath: optionalEnv('GUIDES_TRACKER_PATH'),
adventOfCodeTrackerPath: requireEnv('ADVENT_OF_CODE_TRACKER_PATH'),
roleIds: {
Expand Down
30 changes: 15 additions & 15 deletions src/features/archive-channels/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export async function syncArchiveCategoryChannels(guild: Guild) {
const errorMessages = failedReasons
.map((reason) => reason.message || reason)
.join('; ');
console.error(`Failed to archive some channels: ${errorMessages}`);
throw new Error(`Failed to archive some channels: ${errorMessages}`);
}
}
Expand Down Expand Up @@ -75,7 +74,14 @@ export function hasArchivedPermissions(channel: GuildChannel) {
return false;
}

return PUBLIC_PERMISSIONS.every((permission) =>
// non-vc channels don't have the Connect permission, so we filter it out for those channels
const relevantPermissions = PUBLIC_PERMISSIONS.filter((permission) =>
channel.type === ChannelType.GuildVoice
? true
: permission !== PermissionFlagsBits.Connect
);

return relevantPermissions.every((permission) =>
overwrite.deny.has(permission)
);
}
Expand All @@ -92,12 +98,9 @@ export async function unarchiveChannel(channel: GuildChannel) {

try {
await setArchivedPermissions(channel, false);
await channel.setName(newChannelName);
} catch (error) {
console.error(
`Error unarchiving channel ${channelName}:`,
(error as Error).message
);
if (newChannelName !== channelName) {
await channel.setName(newChannelName);
}
} finally {
processingChannels.delete(channel.id);
}
Expand All @@ -116,13 +119,10 @@ export async function archiveChannel(channel: GuildChannel) {
processingChannels.add(channel.id);

try {
const renamedChannel = await channel.setName(archivedChannelName);
await setArchivedPermissions(renamedChannel, true);
} catch (error) {
// console.error(`Error archiving channel ${channelName}:`, error);
throw new Error(
`Error archiving channel ${channelName}: ${(error as Error).message}`
);
if (archivedChannelName !== channelName) {
await channel.setName(archivedChannelName);
}
await setArchivedPermissions(channel, true);
} finally {
processingChannels.delete(channel.id);
}
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { ActivityType, Client, GatewayIntentBits } from 'discord.js';
import { loadEvents } from './common/events/load-events.js';
import { config } from './env.js';
import { isArchiveRateLimit } from './util/rate-limits.js';

const client = new Client({
rest: {
timeout: 60_000,
rejectOnRateLimit: (rateLimitData) => {
return isArchiveRateLimit(rateLimitData);
},
Comment thread
hmd-ali marked this conversation as resolved.
},
intents: [
GatewayIntentBits.Guilds,
Expand Down
9 changes: 9 additions & 0 deletions src/util/rate-limits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RateLimitData } from 'discord.js';

export function isArchiveRateLimit(rateLimitData: RateLimitData) {
return (
rateLimitData.route === '/channels/:id' &&
rateLimitData.method === 'PATCH' &&
rateLimitData.scope === 'shared'
);
}
Loading