diff --git a/commands/rautil/genachnews.js b/commands/rautil/genachnews.js index c19441f..4112393 100644 --- a/commands/rautil/genachnews.js +++ b/commands/rautil/genachnews.js @@ -68,13 +68,34 @@ module.exports = class GenerateAchievementNewsCommand extends Command { return date1 >= date2 ? d1 : d2; }); + // 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; + } + } + gameInfo = { id: gameId, title: json.Title, consoleName: json.ConsoleName, genre: json.Genre, developer: json.Developer, - releaseDate: json.Released, + releaseDate, achievementSetDate, }; } catch (error) { @@ -96,7 +117,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 +125,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}'}