mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 08:22:22 +02:00
Sip and Choccy support users
This commit is contained in:
@@ -8,9 +8,9 @@ module.exports = class ChocolateMilkCommand extends Command {
|
|||||||
super(client, {
|
super(client, {
|
||||||
name: 'chocolate-milk',
|
name: 'chocolate-milk',
|
||||||
aliases: ['milk', 'sip-milk', 'sip-chocolate-milk', 'choccy', 'sip-choccy'],
|
aliases: ['milk', 'sip-milk', 'sip-chocolate-milk', 'choccy', 'sip-choccy'],
|
||||||
group: 'edit-avatar',
|
group: 'edit-image',
|
||||||
memberName: 'chocolate-milk',
|
memberName: 'chocolate-milk',
|
||||||
description: 'Draws a user\'s avatar holding chocolate milk.',
|
description: 'Draws an image or user\'s avatar holding chocolate milk.',
|
||||||
throttling: {
|
throttling: {
|
||||||
usages: 2,
|
usages: 2,
|
||||||
duration: 10
|
duration: 10
|
||||||
@@ -18,10 +18,10 @@ module.exports = class ChocolateMilkCommand extends Command {
|
|||||||
clientPermissions: ['ATTACH_FILES'],
|
clientPermissions: ['ATTACH_FILES'],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'user',
|
key: 'image',
|
||||||
prompt: 'Which user would you like to edit the avatar of?',
|
prompt: 'What image would you like to edit?',
|
||||||
type: 'user',
|
type: 'image-or-avatar',
|
||||||
default: msg => msg.author
|
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'direction',
|
key: 'direction',
|
||||||
@@ -35,23 +35,26 @@ module.exports = class ChocolateMilkCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { user, direction }) {
|
async run(msg, { image, direction }) {
|
||||||
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
|
|
||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'chocolate-milk.png'));
|
const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'chocolate-milk.png'));
|
||||||
const { body } = await request.get(avatarURL);
|
const { body } = await request.get(image);
|
||||||
const avatar = await loadImage(body);
|
const base = await loadImage(body);
|
||||||
const canvas = createCanvas(base.width, base.height);
|
const canvas = createCanvas(base.width, base.height);
|
||||||
|
const scaleH = overlay.width / base.width;
|
||||||
|
const height = Math.round(base.height * scaleH);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.fillRect(0, 0, base.width, base.height);
|
ctx.fillRect(0, 0, overlay.width, overlay.height);
|
||||||
if (direction === 'right') {
|
if (direction === 'right') {
|
||||||
ctx.translate(base.width, 0);
|
ctx.translate(overlay.width, 0);
|
||||||
ctx.scale(-1, 1);
|
ctx.scale(-1, 1);
|
||||||
}
|
}
|
||||||
ctx.drawImage(avatar, 0, 0, 512, 512);
|
ctx.drawImage(base, 0, 0, overlay.width, height);
|
||||||
if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
|
if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
ctx.drawImage(base, 0, 0);
|
ctx.drawImage(overlay, 0, 0);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'chocolate-milk.png' }] });
|
const attachment = canvas.toBuffer();
|
||||||
|
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||||
|
return msg.say({ files: [{ attachment, name: 'chocolate-milk.png' }] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
@@ -26,10 +26,10 @@ module.exports = class SipCommand extends Command {
|
|||||||
],
|
],
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'user',
|
key: 'image',
|
||||||
prompt: 'Which user would you like to edit the avatar of?',
|
prompt: 'What image would you like to edit?',
|
||||||
type: 'user',
|
type: 'image-or-avatar',
|
||||||
default: msg => msg.author
|
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 1024 })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'direction',
|
key: 'direction',
|
||||||
@@ -43,23 +43,26 @@ module.exports = class SipCommand extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { user, direction }) {
|
async run(msg, { image, direction }) {
|
||||||
const avatarURL = user.displayAvatarURL({ format: 'png', size: 512 });
|
|
||||||
try {
|
try {
|
||||||
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sip.png'));
|
const overlay = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'sip.png'));
|
||||||
const { body } = await request.get(avatarURL);
|
const { body } = await request.get(avatarURL);
|
||||||
const avatar = await loadImage(body);
|
const base = await loadImage(body);
|
||||||
const canvas = createCanvas(base.width, base.height);
|
const canvas = createCanvas(base.width, base.height);
|
||||||
|
const scaleH = overlay.width / base.width;
|
||||||
|
const height = Math.round(base.height * scaleH);
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
ctx.fillRect(0, 0, base.width, base.height);
|
ctx.fillRect(0, 0, overlay.width, overlay.height);
|
||||||
if (direction === 'right') {
|
if (direction === 'right') {
|
||||||
ctx.translate(base.width, 0);
|
ctx.translate(overlay.width, 0);
|
||||||
ctx.scale(-1, 1);
|
ctx.scale(-1, 1);
|
||||||
}
|
}
|
||||||
ctx.drawImage(avatar, 0, 0, 512, 512);
|
ctx.drawImage(base, 0, 0, overlay.width, height);
|
||||||
if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
|
if (direction === 'right') ctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||||
ctx.drawImage(base, 0, 0);
|
ctx.drawImage(overlay, 0, 0);
|
||||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sip.png' }] });
|
const attachment = canvas.toBuffer();
|
||||||
|
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||||
|
return msg.say({ files: [{ attachment, name: 'sip.png' }] });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "134.4.0",
|
"version": "134.4.1",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user