Skip to content

Commit

Permalink
Fix past job post loading on startup (#436)
Browse files Browse the repository at this point in the history
* Fix isStaff check

* Filter staff messages out of job board startup

* Fix message loading

* Track post time when deleted, as intended
  • Loading branch information
vcarl authored Jan 17, 2025
1 parent ca15ef6 commit 73a4aa2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/features/jobs-moderation/job-mod-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ export const loadJobs = async (bot: Client, channel: TextChannel) => {
!oldestMessage ||
differenceInDays(now, oldestMessage.createdAt) < DAYS_OF_POSTS
) {
const messages = await channel.messages.fetch({
...(oldestMessage ? { after: oldestMessage.message.id } : {}),
});
const messages = await channel.messages.fetch(
oldestMessage ? { before: oldestMessage.message.id } : {},
);
console.log(
"[DEBUG] loadJobs()",
`Oldest message: ${oldestMessage ? oldestMessage.createdAt : "none"}.`,
Expand Down Expand Up @@ -135,18 +135,19 @@ export const loadJobs = async (bot: Client, channel: TextChannel) => {
}
oldestMessage = newMessages
.sort((a, b) => compareAsc(a.createdAt, b.createdAt))
.at(-1);
.at(0);
if (!oldestMessage) break;

const humanMessages = newMessages.filter(
const humanNonStaffMessages = newMessages.filter(
(m) =>
differenceInDays(now, m.createdAt) < DAYS_OF_POSTS &&
!m.message.system &&
!isStaff(m.message.member) &&
m.authorId !== bot.user?.id,
);
const [hiring, forHire] = partition(
(m) => m.type === PostType.hiring,
humanMessages,
humanNonStaffMessages,
);

jobBoardMessageCache = { hiring, forHire };
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
export const difference = <T>(a: Set<T>, b: Set<T>) =>
new Set(Array.from(a).filter((x) => !b.has(x)));

const staffRoles = ["mvp", "moderator", "admin", "admins"];
const staffRoles = ["moderator", "admin", "admins"];
const helpfulRoles = ["mvp", "star helper"];

const hasRole = (member: GuildMember, roles: string | string[]) =>
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/modLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ${reportedMessage}
${reportedMessage}`;
case ReportReasons.jobAge:
return `${preface}, for hire post expired.`;
return `${preface}, for hire post expired. ${extra}`;
case ReportReasons.jobFrequency:
return `${preface}, posting too frequently.`;

Expand Down

0 comments on commit 73a4aa2

Please sign in to comment.