From e93dc30fc455c6ce673acd0478519841999cdfd8 Mon Sep 17 00:00:00 2001 From: MrOwnership Date: Fri, 30 Aug 2024 22:23:24 -0400 Subject: [PATCH 1/5] Updates the gan command output to use an ansi code blocks with coloring that is commonly used by devs when posting into the achievement news channel. --- commands/rautil/genachnews.js | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index c19441f..3a46d7d 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -68,13 +68,32 @@ module.exports = class GenerateAchievementNewsCommand extends Command { return date1 >= date2 ? d1 : d2; }); + // Convert date to a human readable string based on the granularity + const [year, month, day] = json.Released.split('-').map(Number); + const date = new Date(year, month - 1, day); + let releaseDate = null; + switch (json.ReleasedAtGranularity) + { + case "day": + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; + break; + case "month": + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; + break; + case "year": + releaseDate = `${year}`; + break; + default: + releaseDate = json.Released; + } + gameInfo = { id: gameId, title: json.Title, consoleName: json.ConsoleName, genre: json.Genre, developer: json.Developer, - releaseDate: json.Released, + releaseDate, achievementSetDate, }; } catch (error) { @@ -96,7 +115,7 @@ module.exports = class GenerateAchievementNewsCommand extends Command { const gameInfo = await this.getGameInfo(id); if (!gameInfo) { - return sentMsg.edit(`Unable to get info from the game ID \`${id}\`... :frowning:`); + return sentMsg.edit(`Unable to get info from the game ID \`${id}\`... :frowning:. This command only works if the set has published achievements.`); } const youtubeLink = await this.getLongplayLink( @@ -104,10 +123,13 @@ module.exports = class GenerateAchievementNewsCommand extends Command { ); const template = ` -\\\`\\\`\\\`md -\`\`\`md -< ${gameInfo.title} > -[${gameInfo.consoleName}, ${gameInfo.genre}](${gameInfo.developer})< ${gameInfo.releaseDate} > +\\\`\\\`\\\`ansi +\`\`\`ansi +Title: ${gameInfo.title} +Console: ${gameInfo.consoleName} +Developer: ${gameInfo.developer} +Genre: ${gameInfo.genre} +Released: ${gameInfo.releaseDate} \`\`\`\\\`\\\`\\\` A new set was published by @{AUTHOR_NAME} on ${gameInfo.achievementSetDate} ${youtubeLink || '{LONGPLAY-LINK}'} From 1596a5a4f614f75340aec5af5c2026de349bc625 Mon Sep 17 00:00:00 2001 From: MrOwnership Date: Fri, 30 Aug 2024 22:37:15 -0400 Subject: [PATCH 2/5] Fix spacing. --- commands/rautil/genachnews.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index 3a46d7d..b52362f 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -76,13 +76,13 @@ module.exports = class GenerateAchievementNewsCommand extends Command { { case "day": releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; - break; + break; case "month": releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; - break; + break; case "year": releaseDate = `${year}`; - break; + break; default: releaseDate = json.Released; } From 8f599984448dd55a6a1d8629ec799421500d9861 Mon Sep 17 00:00:00 2001 From: MrOwnership Date: Fri, 30 Aug 2024 22:42:31 -0400 Subject: [PATCH 3/5] linter fixes. --- commands/rautil/genachnews.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index b52362f..e925320 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -72,15 +72,14 @@ module.exports = class GenerateAchievementNewsCommand extends Command { const [year, month, day] = json.Released.split('-').map(Number); const date = new Date(year, month - 1, day); let releaseDate = null; - switch (json.ReleasedAtGranularity) - { - case "day": + switch (json.ReleasedAtGranularity) { + case 'day': releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; break; - case "month": + case 'month': releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; break; - case "year": + case 'year': releaseDate = `${year}`; break; default: From 11a8c48fe5beb3a3fbc0aecf053e586765b1b632 Mon Sep 17 00:00:00 2001 From: MrOwnership Date: Fri, 30 Aug 2024 23:31:30 -0400 Subject: [PATCH 4/5] Added null check for json.Released. --- commands/rautil/genachnews.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index e925320..5da0d6a 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -69,21 +69,24 @@ module.exports = class GenerateAchievementNewsCommand extends Command { }); // Convert date to a human readable string based on the granularity - const [year, month, day] = json.Released.split('-').map(Number); - const date = new Date(year, month - 1, day); - let releaseDate = null; - switch (json.ReleasedAtGranularity) { - case 'day': - releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; - break; - case 'month': - releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; - break; - case 'year': - releaseDate = `${year}`; - break; - default: - releaseDate = json.Released; + let releaseDate = ''; + if (json.Released !== null) { + const [year, month, day] = json.Released.split('-').map(Number); + const date = new Date(year, month - 1, day); + + switch (json.ReleasedAtGranularity) { + case 'day': + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; + break; + case 'month': + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; + break; + case 'year': + releaseDate = `${year}`; + break; + default: + releaseDate = json.Released; + } } gameInfo = { From 6b1d1a9dbce99cdf381e99bc7b6e4d840561afc4 Mon Sep 17 00:00:00 2001 From: MrOwnership Date: Fri, 30 Aug 2024 23:33:05 -0400 Subject: [PATCH 5/5] More linter fixes. --- commands/rautil/genachnews.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index 5da0d6a..4112393 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -71,22 +71,22 @@ module.exports = class GenerateAchievementNewsCommand extends Command { // Convert date to a human readable string based on the granularity let releaseDate = ''; if (json.Released !== null) { - const [year, month, day] = json.Released.split('-').map(Number); - const date = new Date(year, month - 1, day); - - switch (json.ReleasedAtGranularity) { - case 'day': - releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; - break; - case 'month': - releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; - break; - case 'year': - releaseDate = `${year}`; - break; - default: - releaseDate = json.Released; - } + const [year, month, day] = json.Released.split('-').map(Number); + const date = new Date(year, month - 1, day); + + switch (json.ReleasedAtGranularity) { + case 'day': + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${day}, ${year}`; + break; + case 'month': + releaseDate = `${date.toLocaleString('en-us', { month: 'long' })} ${year}`; + break; + case 'year': + releaseDate = `${year}`; + break; + default: + releaseDate = json.Released; + } } gameInfo = {