diff --git a/commands/Public/help.js b/commands/Public/help.js index 943eaad..e83eabc 100644 --- a/commands/Public/help.js +++ b/commands/Public/help.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); const { EmbedBuilder } = require("discord.js"); const { colors, Embed } = require("../../config.json"); +const { Octokit } = require("@octokit/rest"); const data = new SlashCommandBuilder() .setName("help") @@ -11,8 +12,48 @@ module.exports = { name: "help", async execute(client, interaction) { + // Get from GitHub latest Release + const octokit = new Octokit(); + let release = await octokit.repos.getLatestRelease({ + owner: "Rabenherz112", + repo: "Gamey", + }); + let version = release.data.tag_name; + let releaseDate = release.data.published_at; + // Calculate time since release + let date = new Date(releaseDate); + let now = new Date(); + let diff = now.getTime() - date.getTime(); + let diffMonths = Math.floor(diff / (1000 * 3600 * 24 * 30)); + let diffWeeks = Math.floor(diff / (1000 * 3600 * 24 * 7)); + let diffDays = Math.floor(diff / (1000 * 3600 * 24)); + let diffHours = Math.floor(diff / (1000 * 3600)); + let diffMinutes = Math.floor(diff / (1000 * 60)); + let diffSeconds = Math.floor(diff / 1000); + let time; + if (diffMonths > 0) { + time = `${diffMonths} month(s) ago`; + } else if (diffWeeks > 0) { + time = `${diffWeeks} week(s) ago`; + } else if (diffDays > 0) { + time = `${diffDays} day(s) ago`; + } else if (diffHours > 0) { + time = `${diffHours} hour(s) ago`; + } else if (diffMinutes > 0) { + time = `${diffMinutes} minute(s) ago`; + } else if (diffSeconds > 0) { + time = `${diffSeconds} second(s) ago`; + } + let releaseLink = release.data.html_url; + let releaseName = release.data.name; + // Check which version is used locally + let localVersion = require("../../package.json").version; + if (version != "v"+localVersion) { + version = `${version} (Local: ${localVersion})`; + } + // Create Embed let embed = new EmbedBuilder() - .setTitle("Gamey - Your free Game Finder") + .setTitle(`Gamey ${version} - Your free Game Finder`) .setDescription( `Gamey is a Discord Bot that notifies you when a new free game is available and gives you all Informations you need to claim it.\n To get started use the command \`/set-channel\` to set the channel where the bot will post the free games. If you want to recieve a ping for every new free game use \`/set-notification\`.\n @@ -33,6 +74,11 @@ module.exports = { name: "Source Code", value: "[Click here](https://github.com/Rabenherz112/Gamey)", inline: true + }, + { + name: "Latest Update", + value: `[${releaseName} - ${time}](${releaseLink})`, + inline: true } ) .setColor(colors.Embed_Info) diff --git a/functions/util_checkReddit.js b/functions/util_checkReddit.js index 26981dd..cf63a1c 100644 --- a/functions/util_checkReddit.js +++ b/functions/util_checkReddit.js @@ -8,7 +8,6 @@ async function getSubredditData() { let response = await fetch("https://www.reddit.com/"); if (response.status !== 200) { console.log(`[REDDIT] Reddit is currently down, trying again in ${lookuptime} minutes`); - return; } // Get all new Posts from Subreddits let allPosts = []; diff --git a/package.json b/package.json index 5b922f4..24ada49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-bot-free-games-finder", - "version": "1.1.0", + "version": "1.1.1", "description": "Find your free Games and let them send you to Discord", "main": "index.js", "scripts": { @@ -24,6 +24,7 @@ }, "homepage": "https://github.com/Rabenherz112/Discord-Bot-Free-Games-Finder#readme", "dependencies": { + "@octokit/rest": "^19.0.5", "better-sqlite3": "^8.0.1", "discord-api-types": "^0.37.24", "discord.js": "^14.7.1",