Skip to content

Commit

Permalink
Fix recently killed monster list (#5876)
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert authored May 13, 2024
1 parent 8329ced commit 4c58e31
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/mahoji/commands/k.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ export const autocompleteMonsters = [
];

async function fetchUsersRecentlyKilledMonsters(userID: string) {
const res = await prisma.$queryRawUnsafe<{ mon_id: string }[]>(
`SELECT DISTINCT((data->>'monsterID')) AS mon_id
const res = await prisma.$queryRawUnsafe<{ mon_id: string; last_killed: Date }[]>(
`SELECT DISTINCT((data->>'monsterID')) AS mon_id, MAX(start_date) as last_killed
FROM activity
WHERE user_id = $1
AND type = 'MonsterKilling'
AND finish_date > now() - INTERVAL '31 days'
GROUP BY 1
ORDER BY 2 DESC
LIMIT 10;`,
BigInt(userID)
);
return new Set(res.map(i => Number(i.mon_id)));
return res.map(i => Number(i.mon_id));
}

export const minionKCommand: OSBMahojiCommand = {
Expand All @@ -73,15 +75,17 @@ export const minionKCommand: OSBMahojiCommand = {
: [m.name.toLowerCase(), ...m.aliases].some(str => str.includes(value.toLowerCase()))
)
.sort((a, b) => {
const hasA = recentlyKilled.has(a.id);
const hasB = recentlyKilled.has(b.id);
if (hasA && hasB) return 0;
const hasA = recentlyKilled.includes(a.id);
const hasB = recentlyKilled.includes(b.id);
if (hasA && hasB) {
return recentlyKilled.indexOf(a.id) < recentlyKilled.indexOf(b.id) ? -1 : 1;
}
if (hasA) return -1;
if (hasB) return 1;
return 0;
})
.map(i => ({
name: `${i.name}${recentlyKilled.has(i.id) ? ' (Recently killed)' : ''}`,
name: `${i.name}${recentlyKilled.includes(i.id) ? ' (Recently killed)' : ''}`,
value: i.name
}));
}
Expand Down

0 comments on commit 4c58e31

Please sign in to comment.