mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Merge branch 'master' of https://bitbucket.org/dragonfire535/xiaobot
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -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' }] });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "47.4.1",
|
||||
"version": "47.4.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user