Zonies-Bot/commands/gaydar.js
2025-05-12 15:08:23 -05:00

99 lines
3.7 KiB
JavaScript

const fs = require("fs");
const path = require("path");
const Embed = require("../functions/embed")
const Uploader = require("revolt-uploader");
module.exports = {
config: {
name: "gaydar",
usage: true,
cooldown: 5000,
available: true,
permissions: [],
roles: [],
dm: false,
aliases: ['gd']
},
run: async (client, message, args, db) => {
try {
function randomInteger(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
let targetUser;
// Check if there's a mentioned user
if (message.mentionIds && message.mentionIds.length > 0) {
try {
const server = await client.servers.fetch(message.server.id);
const member = await server.fetchMember(message.mentionIds[0]);
if (!member || !member.id || !member.id.user) {
throw new Error("Invalid member structure");
}
// Fetch the user using the user ID from the member object
targetUser = await client.users.fetch(member.id.user);
if (!targetUser || !targetUser.username) {
throw new Error("Could not fetch user information");
}
} catch (fetchError) {
console.error("Fetch error details:", fetchError.message);
return message.reply({
embeds: [new Embed()
.setDescription("Could not find the mentioned user.")
.setColor(`#FF0000`)]
}, false);
}
} else {
// Use the command author if no user is mentioned
targetUser = message.author;
}
if (!targetUser) {
return message.reply({
embeds: [new Embed()
.setDescription("Could not determine the target user.")
.setColor(`#FF0000`)]
}, false);
}
const amount = randomInteger(1, 100);
const imagePath = path.join(__dirname, "../assets/gaydar.jpg");
// Check if file exists
if (!fs.existsSync(imagePath)) {
return message.reply({
embeds: [new Embed()
.setDescription("Error: Required image file not found.")
.setColor(`#FF0000`)]
}, false);
}
// Upload the image as an attachment
const attachment = await client.Uploader.uploadFile(imagePath, "gaydar.jpg");
// Send the message with the attachment
await message.channel.sendMessage({
content: `#### ${targetUser.username} is ${amount}% gay.`,
attachments: [attachment]
});
} catch (error) {
console.log(`${Date(Date.now().toString()).slice(0, 25)}`);
console.log("User: " + message.author.username + ` [${message.authorId}] ` + " | Command: gaydar | Args: " + (args?.join(" ") || "NONE"));
console.log(error.message);
return message.reply({
embeds: [new Embed()
.setDescription("An error occurred while processing the command.")
.setColor(`#FF0000`)]
}, false);
}
},
};