diff --git a/assets/images/illegal.png b/assets/images/illegal.png new file mode 100644 index 00000000..e407d1cc Binary files /dev/null and b/assets/images/illegal.png differ diff --git a/commands/events/doomsday-clock.js b/commands/events/doomsday-clock.js index a741f3d5..a19dd4cc 100644 --- a/commands/events/doomsday-clock.js +++ b/commands/events/doomsday-clock.js @@ -1,6 +1,6 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); -const { stripIndents } = require('common-tags'); +const { MessageEmbed } = require('discord.js'); module.exports = class DoomsdayClockCommand extends Command { constructor(client) { @@ -14,13 +14,18 @@ module.exports = class DoomsdayClockCommand extends Command { async run(msg) { try { - const { text } = await request.get('https://thebulletin.org/timeline'); - const time = text.match(/IT IS (.+) MINUTES TO MIDNIGHT/)[0]; - const desc = text.match(/
(.+)<\/span>: (.+)<\/div>/); - return msg.say(stripIndents` - **${time}** - ${desc[1]}: ${desc[2].replace(/(.+)<\/a>/g, '$1').replace(/<\/div>/g, '')} - `); + const { text } = await request.get('https://thebulletin.org/doomsday-clock/past-announcements/'); + const time = text.match(/

(.+)<\/h3>/)[1]; + const year = text.match(/

(.+)<\/h5>/)[1]; + const description = text.match(/

(.+)<\/p>/)[1]; + const image = text.match(//)[1];(.+)<\/a>/, '[$2]($1)')); + return msg.embed(embed); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/image-edit/illegal.js b/commands/image-edit/illegal.js index b8531941..0fb6fb14 100644 --- a/commands/image-edit/illegal.js +++ b/commands/image-edit/illegal.js @@ -1,6 +1,11 @@ -const Command = require('../../structures/Command'); -const request = require('node-superfetch'); -const { delay } = require('../../util/Util'); +const { Command } = require('discord.js-commando'); +const { createCanvas, loadImage, registerFont } = require('canvas'); +const { stripIndents } = require('common-tags'); +const path = require('path'); +const { shortenText } = require('../../util/Canvas'); +registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' }); +registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' }); +registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' }); module.exports = class IllegalCommand extends Command { constructor(client) { @@ -20,45 +25,32 @@ module.exports = class IllegalCommand extends Command { key: 'text', prompt: 'What should the text of the bill be?', type: 'string', - validate: text => { - if (/^[a-zA-Z0-9 ]+$/g.test(text) && text.length < 11) return true; - return 'Invalid text, please enter 10 or fewer basic unicode characters (A-Z, 0-9).'; - }, parse: text => text.toUpperCase() + }, + { + key: 'verb', + prompt: 'Should the text use is, are, or am?', + type: 'string', + default: 'IS', + oneOf: ['is', 'are', 'am'], + parse: verb => verb.toUpperCase() } ] }); } - async run(msg, { text }) { - try { - let gif = await this.fetchGIF(text); - if (!gif) { - await msg.say('Trump is busy signing the bill, please wait a moment...'); - await this.createGIF(text); - gif = await this.fetchGIF(text); - if (!gif) return msg.reply('Hmm... It seems Trump couldn\'t sign that bill...'); - } - return msg.say({ files: [gif] }); - } catch (err) { - return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); - } - } - - async createGIF(text) { - const { body } = await request - .post('https://is-now-illegal.firebaseio.com/queue/tasks.json') - .send({ - task: 'gif', - word: text - }); - await delay(5000); - return body; - } - - async fetchGIF(text) { - const { body } = await request.get(`https://is-now-illegal.firebaseio.com/gifs/${text}.json`); - if (!body) return null; - return body.url; + async run(msg, { text, verb }) { + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'illegal.png')); + const canvas = createCanvas(base.width, base.height); + const ctx = canvas.getContext('2d'); + ctx.drawImage(base, 0, 0); + ctx.rotate(7 * (Math.PI / 180)); + ctx.font = '45px Noto'; + ctx.fillText(stripIndents` + ${shortenText(ctx, text, 200)} + ${verb} NOW + ILLEGAL. + `, 750, 290); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] }); } }; diff --git a/commands/number-edit/currency.js b/commands/number-edit/currency.js index cbd96298..d33abcc9 100644 --- a/commands/number-edit/currency.js +++ b/commands/number-edit/currency.js @@ -43,7 +43,7 @@ module.exports = class CurrencyCommand extends Command { if (!target) return msg.say('Invalid target.'); if (base.id === target.id) return msg.say(`Converting ${base.id} to ${target.id} is the same value, dummy.`); const rate = await this.fetchRate(base, target); - return msg.say(`${amount} ${base.id} is ${amount * rate} ${target.id}.`); + return msg.say(`${amount} ${base.id} is ${(amount * rate).toFixed(2)} ${target.id}.`); } catch (err) { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } diff --git a/commands/other/strawpoll.js b/commands/other/strawpoll.js index 8437d6c4..fd3a9115 100644 --- a/commands/other/strawpoll.js +++ b/commands/other/strawpoll.js @@ -35,7 +35,11 @@ module.exports = class StrawpollCommand extends Command { const { body } = await request .post('https://www.strawpoll.me/api/v2/polls') .set({ 'Content-Type': 'application/json' }) - .send({ title, options }); + .send({ + title, + options, + captcha: true + }); return msg.say(stripIndents` ${body.title} http://www.strawpoll.me/${body.id} diff --git a/commands/search/forecast.js b/commands/search/forecast.js index eb1440b8..2623d06b 100644 --- a/commands/search/forecast.js +++ b/commands/search/forecast.js @@ -35,7 +35,7 @@ module.exports = class ForecastCommand extends Command { const data = body.query.results.channel; const embed = new MessageEmbed() .setColor(0x0000FF) - .setAuthor(data.title, 'https://i.imgur.com/B9MMbtB.png', 'https://www.yahoo.com/news/weather') + .setAuthor(data.title, 'https://i.imgur.com/IYF2Pfa.jpg', 'https://www.yahoo.com/news/weather') .setURL(data.link) .setTimestamp(); for (let i = 0; i < 7; i++) { diff --git a/commands/search/neopets-item.js b/commands/search/neopets-item.js index 2a14a929..bf29ceb0 100644 --- a/commands/search/neopets-item.js +++ b/commands/search/neopets-item.js @@ -48,7 +48,7 @@ module.exports = class NeopetsItemCommand extends Command { }); const id = text.match(/\/item\/([0-9]+)/); if (!id) return null; - const price = text.match(/([0-9,]+) (NP|NC)/); + const price = text.match(/>([0-9,]+) (NP|NC)