Skip to content

Commit

Permalink
add back /m and /z
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Jul 12, 2023
1 parent b4a67b8 commit 153fa19
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
118 changes: 118 additions & 0 deletions commands/other/magnify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const prefix = process.env.PREFIX;

const strings = require("../../resources/strings.json");

const warnUser = require("../../helpers/warnUser");
const { magnify } = require("../../functions/textures/magnify");

module.exports = {
name: "magnify",
aliases: ["m", "z"],
description: strings.command.description.magnify,
category: "Faithful",
guildOnly: false,
uses: strings.command.use.anyone,
example: `${prefix}m + file attached`,
async execute(client, message, args) {
let DATA;

// <data>
// image attached
if ((args[0] == undefined || args[0] == '') && message.attachments.size > 0) {
DATA = message.attachments.first().url;
return magnify(message, DATA);
}

// replying to message
else if (message.reference) {
message.channel.messages.fetch(message.reference.messageId).then(msg => {
if (msg.attachments.size > 0) {
DATA = msg.attachments.first().url;
return magnify(message, DATA);
}
else return warnUser(message, strings.command.image.no_reply_attachment);
}).catch(error => {
return warnUser(message, error);
})
}

// previous image
else if ((args[0] == undefined || args[0] == '' || args[0] == 'up' || args[0] == '^' || args[0] == 'last') && message.attachments.size == 0) {
return PreviousImage();
}

// Discord message URL
else if (args[0].startsWith('https://discord.com/channels')) {
message.channel.messages.fetch(args[0].split('/').pop()).then(msg => {
if (msg.attachments.size > 0) {
DATA = msg.attachments.first().url;
return magnify(message, DATA);
}
else return warnUser(message, strings.command.image.not_attached.message)
}).catch(() => { return warnUser(message, strings.command.url.same_channel_only) })
}

// Image URL
else if (args[0].startsWith('https://') || args[0].startsWith('http://')) {
if (args[0].endsWith('.png') || args[0].endsWith('.jpeg') || args[0].endsWith('.jpg') || args[0].endsWith('.gif')) {
DATA = args[0];
return magnify(message, DATA);
} else return warnUser(message, strings.command.image.invalid_extension)
}

// Discord message ID
else if (!isNaN(args[0])) {
message.channel.messages.fetch(args[0]).then(msg => {
if (msg.attachments.size > 0) {
DATA = msg.attachments.first().url;
return magnify(message, DATA);
}
else return warnUser(message, strings.command.image.not_attached.id);
}).catch(error => {
return warnUser(message, error);
})
}

async function PreviousImage() {
/**
* DO NOT DELETE THE COMMENTS IN THIS FUNCTION!
* Right now this function is using a workaround for something that was broken by discord.js v13 and may possibly work again in the future.
*/

var found = false;
//var messages = [];
var list_messages = await message.channel.messages.fetch({ limit: 10 });
var lastMsg = list_messages.sort((a, b) => b.createdTimestamp - a.createdTimestamp).filter((m) => m.attachments.size > 0 || m.embeds[0] != undefined).first();
//messages.push(...list_messages.array());

//for (var i in messages) {
//var msg = messages
var url = '';
try {
if (lastMsg.attachments.size > 0) {
found = true;
url = lastMsg.attachments.first().url;
//break;
}
else if (lastMsg.embeds[0] != undefined && lastMsg.embeds[0] != null && lastMsg.embeds[0].image) {
found = true;
url = lastMsg.embeds[0].image.url;
//break;
}
else if (lastMsg.content.startsWith('https://') || lastMsg.content.startsWith('http://')) {
if (lastMsg.content.endsWith('.png') || lastMsg.content.endsWith('.jpeg') || lastMsg.content.endsWith('.jpg') || lastMsg.content.endsWith('.gif')) {
found = true;
url = lastMsg.content;
//break;
}
}
} catch (e) {
return warnUser(message, strings.command.image.not_found_in_10_last)
}
//}

if (found) await magnify(message, url)
else return warnUser(message, strings.command.image.not_found_in_10_last)
}
}
};
1 change: 1 addition & 0 deletions resources/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"reload": "Reloads a command",
"say": "Make the bot send any message you specify",
"shutdown": "Stops the bot",
"magnify": "Resize an image.",
"status": "Changes the bot's status: \n**Activity**:\nPLAYING, STREAMING, LISTENING, WATCHING, COMPETING, CUSTOM_STATUS (does not work)\n**Presence**:\nonline, idle, dnd",
"animate": "Animates a texture."
},
Expand Down

0 comments on commit 153fa19

Please sign in to comment.