Make wrapped year ambiguous
This commit is contained in:
parent
c4e0c9371b
commit
d9feef56c4
|
@ -9,23 +9,30 @@ let companies = [];
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('wrapped')
|
.setName('wrapped')
|
||||||
.setDescription('Get your 2024 summary.')
|
.setDescription('Get your yearly summary.')
|
||||||
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
.addUserOption(option => option.setName('user').setDescription('The user to check'))
|
||||||
|
.addIntegerOption(option => option.setName('year').setDescription('The year to check').addChoices({ name: '2024', value: 2024 }, { name: '2025', value: 2025 })),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
let user = interaction.user;
|
let user = interaction.user;
|
||||||
const userOption = interaction.options.getUser('user');
|
const userOption = interaction.options.getUser('user');
|
||||||
|
let year = new Date().getFullYear();
|
||||||
|
const yearOption = interaction.options.getInteger('year');
|
||||||
|
|
||||||
if (userOption) {
|
if (userOption) {
|
||||||
user = userOption;
|
user = userOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (yearOption) {
|
||||||
|
year = yearOption;
|
||||||
|
}
|
||||||
|
|
||||||
const userDatabaseEntry = await getUserRegistration(user);
|
const userDatabaseEntry = await getUserRegistration(user);
|
||||||
if (!userDatabaseEntry) return interaction.followUp({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
if (!userDatabaseEntry) return interaction.followUp({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
||||||
|
|
||||||
await GetBeatenGamesForYear(userDatabaseEntry, 2024);
|
await GetBeatenGamesForYear(userDatabaseEntry, year);
|
||||||
|
|
||||||
if (!userBeatenGamesDatabaseEntries || userBeatenGamesDatabaseEntries.length === 0) {
|
if (!userBeatenGamesDatabaseEntries || userBeatenGamesDatabaseEntries.length === 0) {
|
||||||
return interaction.followUp({ content: `${user.username} hasn't beaten any games in this time frame.`, ephemeral: false });
|
return interaction.followUp({ content: `${user.username} hasn't beaten any games in this time frame.`, ephemeral: false });
|
||||||
|
@ -35,8 +42,8 @@ module.exports = {
|
||||||
await GetDevelopers();
|
await GetDevelopers();
|
||||||
|
|
||||||
const numberOfGamesBeat = await GetNumberOfGamesBeat();
|
const numberOfGamesBeat = await GetNumberOfGamesBeat();
|
||||||
const averageBeatGameInterval = await GetAverageBeatInterval();
|
const averageBeatGameInterval = await GetAverageBeatInterval(year);
|
||||||
const mostActiveMonth = await GetMostActiveMonth(userDatabaseEntry);
|
const mostActiveMonth = await GetMostActiveMonth(userDatabaseEntry, year);
|
||||||
const oldestGameBeat = await GetOldestGameBeat();
|
const oldestGameBeat = await GetOldestGameBeat();
|
||||||
const newestGameBeat = await GetNewestGameBeat();
|
const newestGameBeat = await GetNewestGameBeat();
|
||||||
const averageGameAge = await GetAverageGameAge();
|
const averageGameAge = await GetAverageGameAge();
|
||||||
|
@ -44,13 +51,13 @@ module.exports = {
|
||||||
const favouriteGameDevs = await GetFavouriteDevelopers();
|
const favouriteGameDevs = await GetFavouriteDevelopers();
|
||||||
const favouriteGamePublishers = await GetFavouritePublishers();
|
const favouriteGamePublishers = await GetFavouritePublishers();
|
||||||
const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry);
|
const numberOfGamesDropped = await GetNumberOfDroppedGames(userDatabaseEntry);
|
||||||
const yearLeaderboardPlace = await GetYearLeaderboardPosition(userDatabaseEntry);
|
const yearLeaderboardPlace = await GetYearLeaderboardPosition(userDatabaseEntry, year);
|
||||||
const currentLeaderboardPlace = await GetLeaderboardPosition(userDatabaseEntry);
|
const currentLeaderboardPlace = await GetLeaderboardPosition(userDatabaseEntry);
|
||||||
|
|
||||||
const embed = new EmbedBuilder();
|
const embed = new EmbedBuilder();
|
||||||
embed.setColor(0x3BA55C);
|
embed.setColor(0x3BA55C);
|
||||||
embed.setTitle('The 100 Games Challenge: 2024 Wrapped');
|
embed.setTitle(`The 100 Games Challenge: ${year} Wrapped`);
|
||||||
embed.setDescription(`Here are the stats for the games you played for the 100 Games Challenge in 2024 ${user.displayName}`);
|
embed.setDescription(`Here are the stats for the games you played for the 100 Games Challenge in ${year} ${user.displayName}`);
|
||||||
embed.setThumbnail(user.avatarURL());
|
embed.setThumbnail(user.avatarURL());
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
embed.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() });
|
embed.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() });
|
||||||
|
@ -135,10 +142,10 @@ async function GetNumberOfGamesBeat() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetAverageBeatInterval() {
|
async function GetAverageBeatInterval(year) {
|
||||||
if (userBeatenGamesDatabaseEntries && userBeatenGamesDatabaseEntries.length > 0) {
|
if (userBeatenGamesDatabaseEntries && userBeatenGamesDatabaseEntries.length > 0) {
|
||||||
const today = new Date(2025, 0, 1);
|
const today = new Date(year, 0, 1);
|
||||||
const start = new Date(2024, 0, 1);
|
const start = new Date(year, 0, 1);
|
||||||
const days = (today - start) / (1000 * 60 * 60 * 24);
|
const days = (today - start) / (1000 * 60 * 60 * 24);
|
||||||
const timepergame = days / userBeatenGamesDatabaseEntries.length;
|
const timepergame = days / userBeatenGamesDatabaseEntries.length;
|
||||||
return Math.round(timepergame);
|
return Math.round(timepergame);
|
||||||
|
@ -147,22 +154,22 @@ async function GetAverageBeatInterval() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetMostActiveMonth(userDatabaseEntry) {
|
async function GetMostActiveMonth(userDatabaseEntry, year) {
|
||||||
if (userBeatenGamesDatabaseEntries && userBeatenGamesDatabaseEntries.length > 0) {
|
if (userBeatenGamesDatabaseEntries && userBeatenGamesDatabaseEntries.length > 0) {
|
||||||
|
|
||||||
const results = [];
|
const results = [];
|
||||||
results.push(['January', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-01-01', '2024-02-01')]);
|
results.push(['January', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-01-01`, `${year}-02-01`)]);
|
||||||
results.push(['February', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-02-01', '2024-03-01')]);
|
results.push(['February', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-02-01`, `${year}-03-01`)]);
|
||||||
results.push(['March', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-03-01', '2024-04-01')]);
|
results.push(['March', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-03-01`, `${year}-04-01`)]);
|
||||||
results.push(['April', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-04-01', '2024-05-01')]);
|
results.push(['April', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-04-01`, `${year}-05-01`)]);
|
||||||
results.push(['May', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-05-01', '2024-06-01')]);
|
results.push(['May', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-05-01`, `${year}-06-01`)]);
|
||||||
results.push(['June', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-06-01', '2024-07-01')]);
|
results.push(['June', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-06-01`, `${year}-07-01`)]);
|
||||||
results.push(['July', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-07-01', '2024-08-01')]);
|
results.push(['July', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-07-01`, `${year}-08-01`)]);
|
||||||
results.push(['August', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-08-01', '2024-09-01')]);
|
results.push(['August', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-08-01`, `${year}-09-01`)]);
|
||||||
results.push(['September', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-09-01', '2024-10-01')]);
|
results.push(['September', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-09-01`, `${year}-10-01`)]);
|
||||||
results.push(['October', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-10-01', '2024-11-01')]);
|
results.push(['October', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-10-01`, `${year}-11-01`)]);
|
||||||
results.push(['November', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-11-01', '2024-12-01')]);
|
results.push(['November', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-11-01`, `${year}-12-01`)]);
|
||||||
results.push(['December', await getBeatenGamesForYear(userDatabaseEntry.id, '2024-12-01', '2025-01-01')]);
|
results.push(['December', await getBeatenGamesForYear(userDatabaseEntry.id, `${year}-12-01`, `${year + 1}-01-01`)]);
|
||||||
|
|
||||||
const sorted = Object.entries(results).sort((a, b) => b[1][1] - a[1][1]);
|
const sorted = Object.entries(results).sort((a, b) => b[1][1] - a[1][1]);
|
||||||
|
|
||||||
|
@ -365,8 +372,8 @@ async function GetNumberOfDroppedGames(userDatabaseEntry) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function GetYearLeaderboardPosition(userDatabaseEntry) {
|
async function GetYearLeaderboardPosition(userDatabaseEntry, year) {
|
||||||
const leaderboard = await getLeaderboardEntriesBetweenDates('2024-01-01', '2024-12-31');
|
const leaderboard = await getLeaderboardEntriesBetweenDates(`${year}-01-01`, `${year}-12-31`);
|
||||||
await leaderboard.sort((a, b) => parseInt(b.count) - parseInt(a.count));
|
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);
|
||||||
|
|
Loading…
Reference in New Issue