mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Snapchat Command
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { createCanvas, loadImage } = require('canvas');
|
||||
const request = require('node-superfetch');
|
||||
const visualCenter = require('visual-center');
|
||||
|
||||
module.exports = class SnapchatCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'snapchat',
|
||||
aliases: ['snap'],
|
||||
group: 'edit-image',
|
||||
memberName: 'snapchat',
|
||||
description: 'Creates a fake Snap from Snapchat with the image and text you provide.',
|
||||
throttling: {
|
||||
usages: 2,
|
||||
duration: 10
|
||||
},
|
||||
clientPermissions: ['ATTACH_FILES'],
|
||||
credit: [
|
||||
{
|
||||
name: 'Google',
|
||||
url: 'https://www.google.com/',
|
||||
reason: 'Noto Font',
|
||||
reasonURL: 'https://www.google.com/get/noto/'
|
||||
},
|
||||
{
|
||||
name: 'Snapchat',
|
||||
url: 'https://www.snapchat.com/',
|
||||
reason: 'Design'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text should the snap say?',
|
||||
type: 'string',
|
||||
max: 32
|
||||
},
|
||||
{
|
||||
key: 'image',
|
||||
prompt: 'What image would you like to edit?',
|
||||
type: 'image-or-avatar',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { text, image }) {
|
||||
const { body } = await request.get(image);
|
||||
const base = await loadImage(body);
|
||||
const canvas = createCanvas(base.width, base.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(base, 0, 0);
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'top';
|
||||
ctx.font = this.client.fonts.get('Noto-Regular.ttf').toCanvasString(base.height / 24);
|
||||
const barHeight = (base.height / 24) * 2;
|
||||
const { visualTop } = await this.visualCenter(body);
|
||||
const moveCenter = visualTop > 0.5 ? 1 - visualTop - 0.5 : visualTop < 0.5 ? 1 + (visualTop - 0.5) : 1;
|
||||
const barPosition = base.height - (base.height * moveCenter);
|
||||
ctx.globalAlpha = 0.3;
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, barPosition - barHeight, base.width, barHeight);
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.fillText(text, base.width / 2, (barPosition - barHeight) * 0.4);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'snapchat.png' }] });
|
||||
}
|
||||
|
||||
visualCenter(image) {
|
||||
return new Promise((res, rej) => {
|
||||
visualCenter(image.toString('base64'), (err, data) => {
|
||||
if (err) return rej(err);
|
||||
return res(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,6 @@ module.exports = class SnapcodeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'snapcode',
|
||||
aliases: ['snapchat'],
|
||||
group: 'edit-image',
|
||||
memberName: 'snapcode',
|
||||
description: 'Responds with the Snapcode of a Snapchat user.',
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "134.2.0",
|
||||
"version": "134.3.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
@@ -79,6 +79,7 @@
|
||||
"tictactoe-minimax-ai": "^1.2.1",
|
||||
"user-agents": "^1.0.602",
|
||||
"valid-url": "^1.0.9",
|
||||
"visual-center": "^0.1.1",
|
||||
"wavefile": "^11.0.0",
|
||||
"winston": "^3.3.3",
|
||||
"ytdl-core": "^4.5.0"
|
||||
|
||||
Reference in New Issue
Block a user