Skip to content

Commit

Permalink
Merge branch 'fix/version'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhayes3 committed Aug 25, 2024
2 parents 8037d6d + 34ca7f9 commit 4eab27f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
26 changes: 21 additions & 5 deletions commands/core/version.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { SlashCommandBuilder } from 'discord.js';
import { checkVersion } from '../../utils.js';
import { getLatestVersion } from '../../utils.js';

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

export const data = new SlashCommandBuilder().setName('version').setDescription('Display version info').addBooleanOption((option) => option.setName('check').setDescription('Check for update').setRequired(false));

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

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

let reply = `You already have the latest version (${current}).`;

const { options } = interaction;

await interaction.followUp({ content: version, ephemeral: true });
const check = options.getBoolean('check');
if (check) {
console.log('Checking for updates...')
const latest = await getLatestVersion();
if (current < latest) {
reply = `The latest version is ${latest}. You are using version ${current}.`;
}
}
else {
console.log('Not checking for updates')
}
await interaction.followUp({ content: reply, ephemeral: true });
}
26 changes: 10 additions & 16 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ export const sleep = (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}`);
}
}
const url = response.url;
console.log(url);

export async function checkVersion(currentVersion) {
let reply = `You already have the latest version.`;
const tag = response.url.split('/').at(-1);
console.log(tag);

const latestVersion = await getLatestVersion();
if (currentVersion < latestVersion) {
reply = `The latest version is ${latestVersion}. You are currently using version ${currentVersion}.`;
}
const cleaned = tag.split('v').at(-1);
console.log(cleaned);

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

0 comments on commit 4eab27f

Please sign in to comment.