DiscordTickets/src/modules/updater.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
2020-10-03 17:08:10 +03:00
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
2020-10-03 17:08:10 +03:00
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const fetch = require('node-fetch');
2020-08-24 00:01:21 +03:00
const config = require('../../user/' + require('../').config);
let {version} = require('../../package.json');
version = 'v' + version;
2020-08-17 16:46:23 +03:00
const boxen = require('boxen');
const link = require('terminal-link');
2020-10-03 17:08:10 +03:00
module.exports = async () => {
2020-10-03 19:18:07 +03:00
if (!config.updater) return;
2020-10-03 17:08:10 +03:00
const json = await (await fetch('https://api.github.com/repos/eartharoid/DiscordTickets/releases')).json();
const update = json[0];
let notice = [];
2020-10-03 17:08:10 +03:00
if (version !== update.tag_name) {
log.notice(log.f(`There is an update available for Discord Tickets (${version} -> ${update.tag_name})`));
2020-08-17 16:46:23 +03:00
2020-10-03 17:08:10 +03:00
notice.push(`&6You are currently using &c${version}&6, the latest is &a${update.tag_name}&6.`);
notice.push(`&6Download "&f${update.name}&6" from`);
notice.push(link('&6the GitHub releases page', 'https://github.com/eartharoid/DiscordTickets/releases/'));
2020-08-17 16:46:23 +03:00
2020-10-03 17:08:10 +03:00
console.log(
boxen(log.f(notice.join('\n')), {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
})
);
}
};