File tree 2 files changed +38
-18
lines changed
2 files changed +38
-18
lines changed Original file line number Diff line number Diff line change 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 ) ;
10
11
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 } ) ;
19
13
}
Original file line number Diff line number Diff line change @@ -12,6 +12,32 @@ export function splitString(str, length) {
12
12
}
13
13
14
14
export const sleep = ( ms ) => {
15
- console . log ( " Sleeping " + ms + "ms" ) ;
15
+ console . log ( ' Sleeping ' + ms + 'ms' ) ;
16
16
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
17
17
}
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
+ }
You can’t perform that action at this time.
0 commit comments