mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Bug fixes, change illegal back to static image
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 616 KiB |
@@ -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(/<div class="body-text"><span class="timeline-year">(.+)<\/span>: (.+)<\/div>/);
|
||||
return msg.say(stripIndents`
|
||||
**${time}**
|
||||
${desc[1]}: ${desc[2].replace(/<a href="(?:.+)">(.+)<\/a>/g, '$1').replace(/<\/div>/g, '')}
|
||||
`);
|
||||
const { text } = await request.get('https://thebulletin.org/doomsday-clock/past-announcements/');
|
||||
const time = text.match(/<h3 class="uabb-infobox-title">(.+)<\/h3>/)[1];
|
||||
const year = text.match(/<h5 class="uabb-infobox-title-prefix">(.+)<\/h5>/)[1];
|
||||
const description = text.match(/<div class="uabb-infobox-text uabb-text-editor"><p>(.+)<\/p>/)[1];
|
||||
const image = text.match(/<img class="uabb-photo-img wp-image-[0-9]+" src="(.+)" alt=/)[1];
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle(`${year}: ${time}`)
|
||||
.setColor(0x000000)
|
||||
.setThumbnail(image)
|
||||
.setAuthor('Bulletin of the Atomic Scientists', undefined, 'https://thebulletin.org/')
|
||||
.setDescription(description.replace(/<a href="(.+)">(.+)<\/a>/, '[$2]($1)'));
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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!`);
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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)</);
|
||||
const url = `https://items.jellyneo.net/item/${id[1]}/`;
|
||||
const details = await request.get(url);
|
||||
const detailsText = details.text;
|
||||
|
||||
@@ -42,7 +42,7 @@ module.exports = class WattpadCommand extends Command {
|
||||
.setDescription(shorten(data.description))
|
||||
.setThumbnail(data.cover)
|
||||
.addField('❯ Creation Date', new Date(data.createDate).toDateString(), true)
|
||||
.addField('❯ Author', data.user, true)
|
||||
.addField('❯ Author', data.user.name, true)
|
||||
.addField('❯ Chapters', data.numParts, true)
|
||||
.addField('❯ Reads', data.readCount, true)
|
||||
.addField('❯ Votes', data.voteCount, true)
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = class WeatherCommand 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()
|
||||
.addField('❯ City', data.location.city, true)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "81.0.0",
|
||||
"version": "81.0.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user