parent
d9feef56c4
commit
c1efae3b69
|
@ -12,7 +12,6 @@ module.exports = {
|
||||||
|
|
||||||
if (!leaderboard) return interaction.editReply({ content: 'There was a problem!', ephemeral: true });
|
if (!leaderboard) return interaction.editReply({ content: 'There was a problem!', ephemeral: true });
|
||||||
|
|
||||||
await leaderboard.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
|
||||||
let desc = '';
|
let desc = '';
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
|
@ -374,14 +374,12 @@ async function GetNumberOfDroppedGames(userDatabaseEntry) {
|
||||||
|
|
||||||
async function GetYearLeaderboardPosition(userDatabaseEntry, year) {
|
async function GetYearLeaderboardPosition(userDatabaseEntry, year) {
|
||||||
const leaderboard = await getLeaderboardEntriesBetweenDates(`${year}-01-01`, `${year}-12-31`);
|
const leaderboard = await getLeaderboardEntriesBetweenDates(`${year}-01-01`, `${year}-12-31`);
|
||||||
await leaderboard.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
|
||||||
const index = leaderboard.findIndex(item => item.username === userDatabaseEntry.username) + 1;
|
const index = leaderboard.findIndex(item => item.username === userDatabaseEntry.username) + 1;
|
||||||
return await appendOrdinalSuffix(index);
|
return await appendOrdinalSuffix(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetLeaderboardPosition(userDatabaseEntry) {
|
async function GetLeaderboardPosition(userDatabaseEntry) {
|
||||||
const leaderboard = await getLeaderboardEntries();
|
const leaderboard = await getLeaderboardEntries();
|
||||||
await leaderboard.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
|
||||||
const index = leaderboard.findIndex(item => item.username === userDatabaseEntry.username) + 1;
|
const index = leaderboard.findIndex(item => item.username === userDatabaseEntry.username) + 1;
|
||||||
return await appendOrdinalSuffix(index);
|
return await appendOrdinalSuffix(index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,7 +291,14 @@ async function getLeaderboardEntries() {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
for (let i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
const count = await LoggedGames.count({ where: { userId: users[i].id, status: 'beat' } });
|
const games = await LoggedGames.findAll({ where: { userId: users[i].id, status: 'beat' } });
|
||||||
|
const count = games.length;
|
||||||
|
let dateLastBeat = new Date();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
const lastGame = games.at(-1);
|
||||||
|
dateLastBeat = lastGame.statusLastChanged;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await Users.findOne({ where: { id: users[i].id } })
|
const res = await Users.findOne({ where: { id: users[i].id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -299,10 +306,13 @@ async function getLeaderboardEntries() {
|
||||||
});
|
});
|
||||||
const username = res.username;
|
const username = res.username;
|
||||||
|
|
||||||
const fun = { username, count };
|
const result = { username, count, dateLastBeat };
|
||||||
results.push(fun);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await results.sort((a, b) => parseInt(b.dateLastBeat) - parseInt(a.dateLastBeat));
|
||||||
|
await results.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +328,14 @@ async function getLeaderboardEntriesBetweenDates(start, end) {
|
||||||
const endDate = new Date(end);
|
const endDate = new Date(end);
|
||||||
|
|
||||||
for (let i = 0; i < users.length; i++) {
|
for (let i = 0; i < users.length; i++) {
|
||||||
const count = await LoggedGames.count({ where: { userId: users[i].id, status: 'beat', statusLastChanged: { [ Op.between ]: [startDate, endDate] } } });
|
const games = await LoggedGames.findAll({ where: { userId: users[i].id, status: 'beat', statusLastChanged: { [ Op.between ]: [startDate, endDate] } } });
|
||||||
|
const count = games.length;
|
||||||
|
let dateLastBeat = new Date();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
const lastGame = games.at(-1);
|
||||||
|
dateLastBeat = lastGame.statusLastChanged;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await Users.findOne({ where: { id: users[i].id } })
|
const res = await Users.findOne({ where: { id: users[i].id } })
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -326,10 +343,13 @@ async function getLeaderboardEntriesBetweenDates(start, end) {
|
||||||
});
|
});
|
||||||
const username = res.username;
|
const username = res.username;
|
||||||
|
|
||||||
const fun = { username, count };
|
const result = { username, count, dateLastBeat };
|
||||||
results.push(fun);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await results.sort((a, b) => parseInt(b.dateLastBeat) - parseInt(a.dateLastBeat));
|
||||||
|
await results.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue