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