DiscordTickets/src/modules/updater.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
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');
module.exports = () => {
if(!config.updater)
return;
fetch('https://api.github.com/repos/eartharoid/DiscordTickets/releases')
.then(res => res.json())
.then(json => {
const update = json[0];
2020-08-17 16:46:23 +03:00
let notice = [];
if (version !== update.tag_name) {
2020-08-17 16:46:23 +03:00
log.notice(log.f(`There is an update available for Discord Tickets (${version} -> ${update.tag_name})`));
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/'));
console.log(
boxen(log.f(notice.join('\n')), {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
})
);
}
});
};