Skip to content

Commit

Permalink
add versioncheck on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
FaiThiX committed Aug 10, 2024
1 parent a9d885a commit b759a71
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
21 changes: 21 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
const Discord = require('discord.js');
const Fs = require('fs');
const Path = require('path');
const axios = require('axios');

const DiscordBot = require('./src/structures/DiscordBot');

createMissingDirectories();
checkForUpdates();

const client = new DiscordBot({
intents: [
Expand Down Expand Up @@ -58,6 +60,25 @@ function createMissingDirectories() {
}
}

function checkForUpdates() {
const remote = 'https://raw.githubusercontent.com/alexemanuelol/rustplusplus/main/package.json';
const local = require('./package.json');

axios.get(remote).then((response: { data: any; }) => {
const remote = response.data;

if (remote.version !== local.version) {
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, 'UpdateInfo', {
current: local.version,
new: remote.version
}), 'warn');
}
}).catch((error: any) => {
console.log(error);
});
}


process.on('unhandledRejection', error => {
client.log(client.intlGet(null, 'errorCap'), client.intlGet(null, 'unhandledRejection', {
error: error
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@
"unknownInteraction": "Unknown Interaction...",
"unmutedCap": "UNMUTED",
"updateCap": "UPDATE",
"UpdateInfo": "A new version of RustPlusPlus is available. Current Version: {current}, New Version: {new}.",
"upkeep": "Upkeep",
"upkeepForItem": "Upkeep for {item} is {cost}.",
"userAddedToBlacklist": "{user} was added to blacklist.",
Expand Down
15 changes: 10 additions & 5 deletions src/structures/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ class Logger {
message: `${time} | ${text}`
});

console.log(
Colors.green(`${time} `) +
((level === 'error') ? Colors.red(text) : Colors.yellow(text))
);

if (level === 'info') {
console.log(Colors.green(`${time} `) + Colors.yellow(text));
}
if (level === 'warn') {
console.log(Colors.green(`${time} `) + Colors.blue(text));
}
if (level === 'error') {
console.log(Colors.green(`${time} `) + Colors.red(text));
}
if (level === 'error' && Config.general.showCallStackError) {
for (let line of (new Error().stack.split(/\r?\n/))) {
this.logger.log({ level: level, message: `${time} | ${line}` });
console.log(Colors.green(`${time} `) + Colors.red(line));
}
}

} break;

case 'guild': {
Expand Down

0 comments on commit b759a71

Please sign in to comment.