Make Achievements ourselves

This commit is contained in:
Daniel Odendahl Jr
2017-10-15 15:32:21 +00:00
parent 1c951c0850
commit 0b2664c1f8
5 changed files with 23 additions and 21 deletions
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+19 -18
View File
@@ -1,5 +1,7 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Minecraftia.ttf'), { family: 'Minecraftia' });
module.exports = class AchievementCommand extends Command {
constructor(client) {
@@ -9,34 +11,33 @@ module.exports = class AchievementCommand extends Command {
group: 'image-edit',
memberName: 'achievement',
description: 'Sends a Minecraft achievement with the text of your choice.',
throttling: {
usages: 1,
duration: 15
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'text',
prompt: 'What should the text of the achievement be?',
type: 'string',
validate: text => {
if (text.length < 25) return true;
return 'Invalid text, please keep the text under 25 characters.';
}
type: 'string'
}
]
});
}
async run(msg, { text }) {
try {
const { body } = await snekfetch
.get('https://www.minecraftskinstealer.com/achievement/a.php')
.query({
i: 1,
h: 'Achievement Get!',
t: text
});
return msg.say({ files: [{ attachment: body, name: 'achievement.png' }] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'achievement.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.font = '17px Minecraftia';
ctx.fillText('Achievement Get!', 60, 14);
let shorten;
if (ctx.measureText(text).width > 230) shorten = true;
while (ctx.measureText(text).width > 230) text = text.substr(0, text.length - 1);
ctx.fillText(shorten ? `${text}...` : text, 60, 36);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'achievement.png' }] });
}
};
+3 -2
View File
@@ -26,8 +26,9 @@ module.exports = class NASACommand extends Command {
const { body } = await snekfetch
.get('https://images-api.nasa.gov/search')
.query({ q: query });
if (!body.collection.items.length) return msg.say('Could not find any results.');
const data = body.collection.items[Math.floor(Math.random() * body.collection.items.length)];
const filtered = body.collection.items.filter(item => item.data[0].media_type === 'image');
if (!filtered.length) return msg.say('Could not find any results.');
const data = filtered[Math.floor(Math.random() * filtered.length)];
return msg.say(shorten(data.data[0].description), { files: [data.links[0].href] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "47.4.1",
"version": "47.4.2",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {