Skip to content

Commit

Permalink
fetch latest version from github repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhayes3 committed Aug 25, 2024
1 parent 5730c19 commit 6fd1101
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
28 changes: 11 additions & 17 deletions commands/core/version.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
export async function getLatestVersion() {
try {
const latestVersion = "0.1.0";
console.log(latestVersion);
return latestVersion;
} catch (error) {
console.error(`Error while retrieving the latest version. No release found.\n ${error}`);
}
}
import { SlashCommandBuilder } from 'discord.js';
import { checkVersion } from '../../utils.js';

export const data = new SlashCommandBuilder().setName('version').setDescription('Display version info');

export async function execute(interaction) {
await interaction.deferReply({ ephemeral: true });

const currentVersion = '0.1.0';
const version = await checkVersion(currentVersion);

export function checkVersion(currentVersion) {
getLatestVersion().then((latestVersion) => {
if (currentVersion < latestVersion) {
console.log(`A new update is available: ${latestVersion}`);
} else {
console.log(`You have the latest version of the code.`);
}
});
await interaction.followUp({ content: version, ephemeral: true });
}
28 changes: 27 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ export function splitString(str, length) {
}

export const sleep = (ms) => {
console.log("Sleeping " + ms + "ms");
console.log('Sleeping ' + ms + 'ms');
return new Promise(resolve => setTimeout(resolve, ms));
}

export async function getLatestVersion() {
try {
const latestVersion = '1.0.0';
console.log(latestVersion);

const response = await fetch('https://github.com/jmhayes3/binksjs/releases/latest');
console.log(response);
console.log(response.data.tag_name);

return latestVersion;
} catch (error) {
console.error(`Error while retrieving the latest version. No release found.\n ${error}`);
}
}

export async function checkVersion(currentVersion) {
let reply = `You already have the latest version.`;

const latestVersion = await getLatestVersion();
if (currentVersion < latestVersion) {
reply = `The latest version is ${latestVersion}. You are currently using version ${currentVersion}.`;
}

return reply;
}

0 comments on commit 6fd1101

Please sign in to comment.