From 5498d7f685820bcc26d48a9f990114d705daec80 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Sun, 26 Jul 2020 00:54:47 -0500 Subject: [PATCH 1/2] Improve startup logging --- lib/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index e76a943..c0892bd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,10 +20,12 @@ let settings = settingsUtil.DEFAULT_SETTINGS; // Start bot // ========================= -bot.login(process.env.BOT_TOKEN); +bot.login(process.env.BOT_TOKEN) + .then(() => console.log(`${bot.user.username} logged in`)) + .catch(err => console.error(err)); bot.on('ready', async () => { - console.log(bot.user.username + ' successfully started'); + console.log(`${bot.user.username} successfully started`); bot.user.setPresence({ activity: { type: 'WATCHING', name: `for ${C_DEALS}` }}); From d0ac3f5bc19f6003c8a66c0f12f3cfd7276f8850 Mon Sep 17 00:00:00 2001 From: Adam Davies Date: Sun, 26 Jul 2020 01:43:43 -0500 Subject: [PATCH 2/2] Add store links, add review stats, improve fields --- lib/commands/deals.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/commands/deals.js b/lib/commands/deals.js index 7096e26..95e6810 100644 --- a/lib/commands/deals.js +++ b/lib/commands/deals.js @@ -31,10 +31,8 @@ module.exports = async (msg, game, ignoredSellers) => { } // Can't rely on user input for the formal game name. - // Formal name also isn't returned with game data - // in the next step. + // Formal name also isn't returned with game data in the next step. const gameInfo = await apiUtil.getGameInfo(gameId); - const gameName = gameInfo.title; const gameData = await apiUtil.getGameData(gameId, ignoredSellers); const list = gameData.list.filter(x => x.price_new < x.price_old); @@ -43,14 +41,11 @@ module.exports = async (msg, game, ignoredSellers) => { return; } - const sellers = list.map(x => x.shop.name); + const sellers = list.map(x => `[${x.shop.name}](${x.url})`); const newPrices = list.map(x => `${toCurrency(x.price_new)} (-${x.price_cut}%)`); const oldPrices = list.map(x => toCurrency(x.price_old)); const histLowData = await apiUtil.getHistoricalLow(gameId); - const historicalLow = histLowData ? `${histLowData.shop.name} @ ${toCurrency(histLowData.price)} (-${histLowData.cut}%)` : 'None'; - - const steamReview = gameInfo.reviews && gameInfo.reviews.steam.text; const embed = new Discord.MessageEmbed({ author: { @@ -59,7 +54,7 @@ module.exports = async (msg, game, ignoredSellers) => { image: { url: gameInfo.image }, - title: gameName || gameId, + title: gameInfo.title || gameId, url: gameData.urls.game, color: 0x23B2D5, fields: [ @@ -77,20 +72,26 @@ module.exports = async (msg, game, ignoredSellers) => { name: 'Old Price', value: oldPrices.join('\n'), inline: true - }, - { - name: 'Historical Low', - value: historicalLow } - ], timestamp: new Date() }); - steamReview && embed.addFields( - { - name: 'Steam Review', - value: steamReview + + if (histLowData) { + embed.addFields({ + name: 'Historical Low', + value: `${toCurrency(histLowData.price)} (-${histLowData.cut}%) from ${histLowData.shop.name}` }); + } + + if (gameInfo.reviews && gameInfo.reviews.steam) { + const steamReview = gameInfo.reviews.steam; + + embed.addFields({ + name: 'Steam User Review', + value: `${steamReview.text} (${steamReview.perc_positive}% from ${steamReview.total} users)` + }); + } msg.channel.send({ embed }); } catch (e) { @@ -108,5 +109,7 @@ module.exports = async (msg, game, ignoredSellers) => { * @returns {string} */ function toCurrency(num) { - return `$${Number.parseFloat(num).toFixed(2)}`; + const price = Number.parseFloat(num).toFixed(2); + + return price > 0 ? `$${price}` : 'FREE'; } \ No newline at end of file