mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 14:19:11 +02:00
Silhouette
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { silhouette } = require('../../util/Util');
|
||||
|
||||
module.exports = class SilhouetteCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'silhouette',
|
||||
group: 'avatar-edit',
|
||||
memberName: 'silhouette',
|
||||
description: 'Draws a silhouette of a user\'s avatar.',
|
||||
throttling: {
|
||||
usages: 1,
|
||||
duration: 15
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'user',
|
||||
prompt: 'Which user would you like to edit the avatar of?',
|
||||
type: 'user',
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { user }) {
|
||||
if (!user) user = msg.author;
|
||||
const avatarURL = user.displayAvatarURL({
|
||||
format: 'png',
|
||||
size: 512
|
||||
});
|
||||
try {
|
||||
const { body } = await snekfetch.get(avatarURL);
|
||||
const avatar = await loadImage(body);
|
||||
const canvas = createCanvas(avatar.width, avatar.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(avatar, 0, 0);
|
||||
silhouette(ctx, 0, 0, avatar.width, avatar.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'silhouette.png' }] });
|
||||
} catch (err) {
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { filterPkmn, pad } = require('../../util/Util');
|
||||
const { filterPkmn, pad, silhouette } = require('../../util/Util');
|
||||
|
||||
module.exports = class WhosThatPokemonCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -10,18 +11,35 @@ module.exports = class WhosThatPokemonCommand extends Command {
|
||||
group: 'games',
|
||||
memberName: 'whos-that-pokemon',
|
||||
description: 'Guess who that Pokémon is.',
|
||||
clientPermissions: ['ATTACH_FILES']
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
args: [
|
||||
{
|
||||
key: 'hide',
|
||||
prompt: 'Do you want to silhouette the Pokémon\'s image?',
|
||||
type: 'boolean',
|
||||
default: false
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
async run(msg, { hide }) {
|
||||
const pokemon = Math.floor(Math.random() * 721) + 1;
|
||||
try {
|
||||
const { body } = await snekfetch.get(`https://pokeapi.co/api/v2/pokemon-species/${pokemon}/`);
|
||||
const names = body.names.map(name => name.name.toLowerCase());
|
||||
const displayName = filterPkmn(body.names).name;
|
||||
const image = `https://www.serebii.net/sunmoon/pokemon/${pad(body.id.toString(), '000')}.png`;
|
||||
await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [image] });
|
||||
const id = pad(body.id.toString(), '000');
|
||||
const image = await snekfetch.get(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
|
||||
let attachment = image.body;
|
||||
if (hide) {
|
||||
const base = await loadImage(image.body);
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
silhouette(ctx, 0, 0, base.width, base.height);
|
||||
attachment = canvas.toBuffer();
|
||||
}
|
||||
await msg.say('**You have 15 seconds, who\'s that Pokémon?**', { files: [{ attachment, name: `${id}.png` }] });
|
||||
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||
max: 1,
|
||||
time: 15000
|
||||
|
||||
Reference in New Issue
Block a user