Skip to content

Commit 6fd1101

Browse files
committed
fetch latest version from github repo
1 parent 5730c19 commit 6fd1101

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

commands/core/version.js

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
export async function getLatestVersion() {
2-
try {
3-
const latestVersion = "0.1.0";
4-
console.log(latestVersion);
5-
return latestVersion;
6-
} catch (error) {
7-
console.error(`Error while retrieving the latest version. No release found.\n ${error}`);
8-
}
9-
}
1+
import { SlashCommandBuilder } from 'discord.js';
2+
import { checkVersion } from '../../utils.js';
3+
4+
export const data = new SlashCommandBuilder().setName('version').setDescription('Display version info');
5+
6+
export async function execute(interaction) {
7+
await interaction.deferReply({ ephemeral: true });
8+
9+
const currentVersion = '0.1.0';
10+
const version = await checkVersion(currentVersion);
1011

11-
export function checkVersion(currentVersion) {
12-
getLatestVersion().then((latestVersion) => {
13-
if (currentVersion < latestVersion) {
14-
console.log(`A new update is available: ${latestVersion}`);
15-
} else {
16-
console.log(`You have the latest version of the code.`);
17-
}
18-
});
12+
await interaction.followUp({ content: version, ephemeral: true });
1913
}

utils.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ export function splitString(str, length) {
1212
}
1313

1414
export const sleep = (ms) => {
15-
console.log("Sleeping " + ms + "ms");
15+
console.log('Sleeping ' + ms + 'ms');
1616
return new Promise(resolve => setTimeout(resolve, ms));
1717
}
18+
19+
export async function getLatestVersion() {
20+
try {
21+
const latestVersion = '1.0.0';
22+
console.log(latestVersion);
23+
24+
const response = await fetch('https://github.com/jmhayes3/binksjs/releases/latest');
25+
console.log(response);
26+
console.log(response.data.tag_name);
27+
28+
return latestVersion;
29+
} catch (error) {
30+
console.error(`Error while retrieving the latest version. No release found.\n ${error}`);
31+
}
32+
}
33+
34+
export async function checkVersion(currentVersion) {
35+
let reply = `You already have the latest version.`;
36+
37+
const latestVersion = await getLatestVersion();
38+
if (currentVersion < latestVersion) {
39+
reply = `The latest version is ${latestVersion}. You are currently using version ${currentVersion}.`;
40+
}
41+
42+
return reply;
43+
}

0 commit comments

Comments
 (0)