mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 00:12:32 +02:00
Face Analyze, Analyze group
This commit is contained in:
@@ -4,7 +4,7 @@ module.exports = class CoolnessCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'coolness',
|
||||
group: 'other',
|
||||
group: 'analyze',
|
||||
memberName: 'coolness',
|
||||
description: 'Determines a user\'s coolness.',
|
||||
args: [
|
||||
@@ -0,0 +1,44 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { KAIROS_KEY, KAIROS_ID } = process.env;
|
||||
const races = ['asian', 'black', 'hispanic', 'other', 'white'];
|
||||
|
||||
module.exports = class FaceAnalyzeCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'face-analyze',
|
||||
aliases: ['analyze-face', 'face'],
|
||||
group: 'analyze',
|
||||
memberName: 'face',
|
||||
description: 'Determines the age, gender, and race of a face.',
|
||||
args: [
|
||||
{
|
||||
key: 'face',
|
||||
prompt: 'What face do you want to scan?',
|
||||
type: 'image',
|
||||
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { face }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.post('https://api.kairos.com/detect')
|
||||
.set({
|
||||
app_id: KAIROS_ID,
|
||||
app_key: KAIROS_KEY
|
||||
})
|
||||
.send({ image: face });
|
||||
if (!body.images) return msg.say('There are no faces in this image.');
|
||||
if (body.images[0].faces.length > 1) return msg.say('Please provide only one face in the image.');
|
||||
const data = body.images[0].faces[0].attributes;
|
||||
const race = races.sort((a, b) => data[b] - data[a])[0];
|
||||
const gender = data.gender.maleConfidence > data.gender.femaleConfidence ? 'man' : 'woman';
|
||||
return msg.reply(`I think this is a photo of a ${data.age} year old ${race} ${gender}.`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -5,8 +5,8 @@ module.exports = class GenderGuessCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'gender-guess',
|
||||
aliases: ['gender', 'guess-gender'],
|
||||
group: 'other',
|
||||
aliases: ['gender', 'guess-gender', 'analyze-gender', 'gender-analyze'],
|
||||
group: 'analyze',
|
||||
memberName: 'gender',
|
||||
description: 'Determines the gender of a name.',
|
||||
args: [
|
||||
@@ -7,7 +7,7 @@ module.exports = class SevereToxicityCommand extends Command {
|
||||
super(client, {
|
||||
name: 'severe-toxicity',
|
||||
aliases: ['severe-perspective', 'severe-comment-toxicity'],
|
||||
group: 'other',
|
||||
group: 'analyze',
|
||||
memberName: 'severe-toxicity',
|
||||
description: 'Determines the toxicity of text, but less sensitive to milder language.',
|
||||
args: [
|
||||
@@ -7,7 +7,7 @@ module.exports = class ToxicityCommand extends Command {
|
||||
super(client, {
|
||||
name: 'toxicity',
|
||||
aliases: ['perspective', 'comment-toxicity'],
|
||||
group: 'other',
|
||||
group: 'analyze',
|
||||
memberName: 'toxicity',
|
||||
description: 'Determines the toxicity of text.',
|
||||
args: [
|
||||
@@ -34,7 +34,9 @@ module.exports = class ContrastCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
contrast(ctx, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'contrast.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: 'contrast.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ module.exports = class DistortCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
distort(ctx, level, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'distort.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: 'distort.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ module.exports = class GlitchCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
distort(ctx, 20, 0, 0, data.width, data.height, 5);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'glitch.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: 'glitch.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ module.exports = class GreyscaleCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
greyscale(ctx, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'greyscale.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: 'greyscale.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ module.exports = class IfunnyCommand extends Command {
|
||||
ctx.fillStyle = '#181619';
|
||||
ctx.fillRect(0, canvas.height - base.height, canvas.width, base.height);
|
||||
ctx.drawImage(base, canvas.width - base.width, canvas.height - base.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'ifunny.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: 'ifunny.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ module.exports = class InvertCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
invert(ctx, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'invert.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: 'invert.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ module.exports = class SepiaCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
sepia(ctx, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'sepia.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: 'sepia.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ module.exports = class SilhouetteCommand extends Command {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(data, 0, 0);
|
||||
silhouette(ctx, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'silhouette.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: 'silhouette.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,9 @@ module.exports = class TintCommand extends Command {
|
||||
const canvas = createCanvas(data.width, data.height);
|
||||
const ctx = canvas.getContext('2d');
|
||||
drawImageWithTint(ctx, data, color, 0, 0, data.width, data.height);
|
||||
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'tint.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: 'tint.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user