Skip to content

Commit

Permalink
馃悰 Hopefully fix catch-up script
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusOtter committed Mar 29, 2023
1 parent 0830929 commit a1ac453
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/eventListeners/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,33 @@ export default class ReadyEventListener extends NeedleEventListener {
if (!guild) continue;

for (const autoThreadChannel of config.threadChannels) {
const channel = await guild.channels.fetch(autoThreadChannel.channelId);
if (!channel || !channel.isTextBased()) continue;

const lastMessage = (await channel.messages.fetch({ limit: 1 })).first();
if (!lastMessage) continue;

const shouldHaveThread = await this.threadCreator.shouldHaveThread(lastMessage);
if (!shouldHaveThread) continue;

const latestTenMessages = await channel.messages.fetch({ limit: 10 });
await Promise.all(
latestTenMessages.map(async m => {
// In the future if we have prerequisites we need to check those here
const createThread = await this.threadCreator.shouldHaveThread(m);
if (!createThread) return Promise.resolve();

const { author, member } = m;
const messageVariables = new MessageVariables().setChannel(channel).setUser(member ?? author);
return this.threadCreator.createThreadOnMessage(m, messageVariables);
})
);
try {
const channel = await guild.channels.fetch(autoThreadChannel.channelId);
if (!channel || !channel.isTextBased()) continue;

const lastMessage = (await channel.messages.fetch({ limit: 1 })).first();
if (!lastMessage) continue;

const shouldHaveThread = await this.threadCreator.shouldHaveThread(lastMessage);
if (!shouldHaveThread) continue;

const latestTenMessages = await channel.messages.fetch({ limit: 10 });
await Promise.all(
latestTenMessages.map(async m => {
// In the future if we have prerequisites we need to check those here
const createThread = await this.threadCreator.shouldHaveThread(m);
if (!createThread) return Promise.resolve();

const { author, member } = m;
const messageVariables = new MessageVariables()
.setChannel(channel)
.setUser(member ?? author);
return this.threadCreator.createThreadOnMessage(m, messageVariables);
})
);
} catch {
continue;
}
}
}
}
Expand Down

0 comments on commit a1ac453

Please sign in to comment.