Skip to content

Commit

Permalink
Add some image commands!
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jan 11, 2025
1 parent e996424 commit 233996f
Show file tree
Hide file tree
Showing 17 changed files with 1,203 additions and 1,822 deletions.
5 changes: 4 additions & 1 deletion commands/General/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Help extends Command {
category: 'General',
usage: 'help <category | command>',
examples: ['help games', 'help user-info'],
aliases: ['h'],
aliases: ['h', 'commands', 'cmds'],
});
}

Expand All @@ -21,6 +21,7 @@ class Help extends Command {
'games',
'general',
'giveaways',
'images',
'information',
'minecraft',
'music',
Expand All @@ -43,6 +44,8 @@ class Help extends Command {
mc: 'minecraft',
mod: 'moderator',
mods: 'moderator',
giveaway: 'giveaways',
image: 'images',
info: 'information',
ticket: 'tickets',
};
Expand Down
77 changes: 77 additions & 0 deletions commands/Images/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const Command = require('../../base/Command.js');
const { createCanvas, loadImage } = require('canvas');
const path = require('path');

class Delete extends Command {
constructor(client) {
super(client, {
name: 'delete',
description: "Displays you or the mentioned user's avatar with windows deletion menu.",
category: 'Images',
usage: 'delete [user]',
});
}

async run(msg, args) {
let infoMem; // Will store the GuildMember or User object
let fetchedUser; // Will store the User object

// If text is provided, try to get the member from the guild
if (args?.length > 0) {
infoMem = await this.client.util.getMember(msg, args.join(' ').toLowerCase());
}

if (!infoMem) {
// If no member is found, try to fetch the user by ID
const findId = args.join(' ').toLowerCase().replace(/<@|>/g, '');

try {
// Fetch the user object using the ID
fetchedUser = await this.client.users.fetch(findId, { force: true });
} catch (err) {
// If the user cannot be fetched, default to the message author
infoMem = msg.member; // Use the message author's member object
fetchedUser = infoMem.user; // Get the User object from the member
}
} else {
// If a member is found in the guild, fetch their user object
fetchedUser = infoMem.user;
}

// Fetch the user's avatar as a PNG
const avatarURL = fetchedUser.displayAvatarURL({ extension: 'png', size: 512, dynamic: false });

// Generate the image
try {
// Load the avatar and the background image
const avatar = await loadImage(avatarURL);
const backgroundPath = path.resolve(__dirname, '../../resources/images/DeleteMeme.jpg');
const background = await loadImage(backgroundPath);

// Create a canvas with the dimensions of the background
const canvas = createCanvas(background.width, background.height);
const ctx = canvas.getContext('2d');

// Draw the background
ctx.drawImage(background, 0, 0);

// Resize and position the avatar
const avatarWidth = 155;
const avatarHeight = 155;
const avatarX = 95; // X-coordinate
const avatarY = 106; // Y-coordinate
ctx.drawImage(avatar, avatarX, avatarY, avatarWidth, avatarHeight);

// Send the result
const attachment = canvas.toBuffer();
await msg.channel.send({
files: [{ attachment, name: 'custom_avatar.png' }],
});
} catch (error) {
this.client.logger.error(error.stack);
msg.reply('There was an error processing the image.');
}
}
}

module.exports = Delete;
72 changes: 72 additions & 0 deletions commands/Images/lgbt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const Command = require('../../base/Command.js');
const { createCanvas, loadImage } = require('canvas');
const path = require('path');

class LGBT extends Command {
constructor(client) {
super(client, {
name: 'lgbt',
description: "Displays you or the mentioned user's avatar with the LGBT overlay.",
category: 'Images',
usage: 'lgbt [user]',
});
}

async run(msg, args) {
let infoMem; // Will store the GuildMember or User object
let fetchedUser; // Will store the User object

// If text is provided, try to get the member from the guild
if (args?.length > 0) {
infoMem = await this.client.util.getMember(msg, args.join(' ').toLowerCase());
} else {
infoMem = msg.member;
}

if (!infoMem) {
// If no member is found, try to fetch the user by ID
const findId = args.join(' ').toLowerCase().replace(/<@|>/g, '');

try {
// Fetch the user object using the ID
fetchedUser = await this.client.users.fetch(findId, { force: true });
} catch (err) {
// If the user cannot be fetched, default to the message author
infoMem = msg.member; // Use the message author's member object
fetchedUser = infoMem.user; // Get the User object from the member
}
} else {
// If a member is found in the guild, fetch their user object
fetchedUser = infoMem.user;
}

// Fetch the user's avatar as a PNG
const avatarURL = fetchedUser.displayAvatarURL({ extension: 'png', size: 512, dynamic: false });

// Generate the image
try {
const avatar = await loadImage(avatarURL);
const canvas = createCanvas(400, 400);
const ctx = canvas.getContext('2d');

// Draw the avatar
ctx.drawImage(avatar, 0, 0, 400, 400);

// Load and draw the "WASTED" banner
const rainbowPath = path.resolve(__dirname, '../../resources/images/rainbow.png');
const rainbow = await loadImage(rainbowPath);
ctx.drawImage(rainbow, 0, 0, 400, 400);

// Send the result
const attachment = canvas.toBuffer();
await msg.channel.send({
files: [{ attachment, name: 'lgbt.png' }],
});
} catch (error) {
this.client.logger.error(error.stack);
msg.reply('There was an error processing the image.');
}
}
}

module.exports = LGBT;
80 changes: 80 additions & 0 deletions commands/Images/shit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const Command = require('../../base/Command.js');
const { createCanvas, loadImage } = require('canvas');
const path = require('path');

class Shit extends Command {
constructor(client) {
super(client, {
name: 'shit',
description: "Displays you or the mentioned user's avatar as stepped in shit",
category: 'Images',
usage: 'shit [user]',
});
}

async run(msg, args) {
let infoMem; // Will store the GuildMember or User object
let fetchedUser; // Will store the User object

// If text is provided, try to get the member from the guild
if (args?.length > 0) {
infoMem = await this.client.util.getMember(msg, args.join(' ').toLowerCase());
} else {
infoMem = msg.member;
}

if (!infoMem) {
// If no member is found, try to fetch the user by ID
const findId = args.join(' ').toLowerCase().replace(/<@|>/g, '');

try {
// Fetch the user object using the ID
fetchedUser = await this.client.users.fetch(findId, { force: true });
} catch (err) {
// If the user cannot be fetched, default to the message author
infoMem = msg.member; // Use the message author's member object
fetchedUser = infoMem.user; // Get the User object from the member
}
} else {
// If a member is found in the guild, fetch their user object
fetchedUser = infoMem.user;
}

// Fetch the user's avatar as a PNG
const avatarURL = fetchedUser.displayAvatarURL({ extension: 'png', size: 512, dynamic: false });

// Generate the image
try {
const avatar = await loadImage(avatarURL);
const canvas = createCanvas(600, 835);
const ctx = canvas.getContext('2d');

// Load and draw the shit image
const shitPath = path.resolve(__dirname, '../../resources/images/plate_shit.png');
const shit = await loadImage(shitPath);
ctx.drawImage(shit, 0, 0, 600, 835);

// Draw the avatar with rotation
const avatarX = 220 + 75 / 2; // X-coordinate of the avatar's center
const avatarY = 600 + 75 / 2; // Y-coordinate of the avatar's center
const rotationAngle = (-40 * Math.PI) / 180; // Convert -30 degrees to radians (negative for counterclockwise)

ctx.save(); // Save the current canvas state
ctx.translate(avatarX, avatarY); // Move the canvas origin to the avatar's center
ctx.rotate(rotationAngle); // Rotate the canvas counterclockwise
ctx.drawImage(avatar, -75 / 2, -75 / 2, 75, 75); // Draw the avatar, offset by half its size
ctx.restore(); // Restore the canvas state

// Send the result
const attachment = canvas.toBuffer();
await msg.channel.send({
files: [{ attachment, name: 'lgbt.png' }],
});
} catch (error) {
this.client.logger.error(error.stack);
msg.reply('There was an error processing the image.');
}
}
}

module.exports = Shit;
77 changes: 77 additions & 0 deletions commands/Images/wanted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const Command = require('../../base/Command.js');
const { createCanvas, loadImage } = require('canvas');
const path = require('path');

class Wanted extends Command {
constructor(client) {
super(client, {
name: 'wanted',
description: "Displays you or the mentioned user's avatar with on a wanted poster",
category: 'Images',
usage: 'wanted [user]',
});
}

async run(msg, args) {
let infoMem; // Will store the GuildMember or User object
let fetchedUser; // Will store the User object

// If text is provided, try to get the member from the guild
if (args?.length > 0) {
infoMem = await this.client.util.getMember(msg, args.join(' ').toLowerCase());
}

if (!infoMem) {
// If no member is found, try to fetch the user by ID
const findId = args.join(' ').toLowerCase().replace(/<@|>/g, '');

try {
// Fetch the user object using the ID
fetchedUser = await this.client.users.fetch(findId, { force: true });
} catch (err) {
// If the user cannot be fetched, default to the message author
infoMem = msg.member; // Use the message author's member object
fetchedUser = infoMem.user; // Get the User object from the member
}
} else {
// If a member is found in the guild, fetch their user object
fetchedUser = infoMem.user;
}

// Fetch the user's avatar as a PNG
const avatarURL = fetchedUser.displayAvatarURL({ extension: 'png', size: 512, dynamic: false });

// Generate the image
try {
// Load the avatar and the background image
const avatar = await loadImage(avatarURL);
const backgroundPath = path.resolve(__dirname, '../../resources/images/wanted_poster.jpg');
const background = await loadImage(backgroundPath);

// Create a canvas with the dimensions of the background
const canvas = createCanvas(background.width, background.height);
const ctx = canvas.getContext('2d');

// Draw the background
ctx.drawImage(background, 0, 0);

// Resize and position the avatar
const avatarWidth = 400;
const avatarHeight = 400;
const avatarX = 170; // X-coordinate
const avatarY = 305; // Y-coordinate
ctx.drawImage(avatar, avatarX, avatarY, avatarWidth, avatarHeight);

// Send the result
const attachment = canvas.toBuffer();
await msg.channel.send({
files: [{ attachment, name: 'custom_avatar.png' }],
});
} catch (error) {
this.client.logger.error(error.stack);
msg.reply('There was an error processing the image.');
}
}
}

module.exports = Wanted;
Loading

0 comments on commit 233996f

Please sign in to comment.