Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update gan output code block format and coloring #141

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions commands/rautil/genachnews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -96,18 +117,21 @@ 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(
`${gameInfo.title.replace(/~/g, '')} ${gameInfo.consoleName}`,
);

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}'}
Expand Down
Loading