Skip to content

Commit

Permalink
Hotfix: Fix Reddit check to stop Bot crashing
Browse files Browse the repository at this point in the history
Fix Reddit Check & Added Git check for help command
  • Loading branch information
Rabenherz112 authored Dec 27, 2022
2 parents 90c5ee5 + 07835eb commit 500c51d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
48 changes: 47 additions & 1 deletion commands/Public/help.js
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion functions/util_checkReddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down

0 comments on commit 500c51d

Please sign in to comment.