mirror of
https://github.com/danbulant/Shasha
synced 2026-05-24 12:22:00 +00:00
accept json arg, reportMessage
This commit is contained in:
parent
316c87c5d5
commit
db21dcb9b4
1 changed files with 62 additions and 21 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const commando = require("@iceprod/discord.js-commando");
|
||||
const { MessageEmbed } = require("discord.js");
|
||||
const { ranLog, errLog, getChannelMessage, noPerm, tryReact } = require("../../resources/functions");
|
||||
const { ranLog, errLog, getChannelMessage, noPerm, tryReact, findChannelRegEx, trySend } = require("../../resources/functions");
|
||||
const getColor = require("../../resources/getColor");
|
||||
|
||||
module.exports = class embmaker extends commando.Command {
|
||||
|
|
@ -18,15 +18,24 @@ module.exports = class embmaker extends commando.Command {
|
|||
hidden:false
|
||||
});
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {commando.CommandoMessage} msg
|
||||
* @param {*} arg
|
||||
* @returns
|
||||
*/
|
||||
async run(msg, arg) {
|
||||
const args = arg.trim().split(/(?<!\\)(\-\-)+/);
|
||||
let embed = new MessageEmbed();
|
||||
let autName, footertext, autIcon, autUrl, footericon, content, channel, editSrc, newAttach = [];
|
||||
let autName, footertext, autIcon, autUrl, footericon, content, channel, editSrc, newAttach = [], reportMessage = "";
|
||||
try {
|
||||
for(const value of args) {
|
||||
if (value.toLowerCase().startsWith("json")) {
|
||||
embed = new MessageEmbed(JSON.parse(value.slice("json".length).trim()));
|
||||
}
|
||||
if (value.toLowerCase().startsWith('edit')) {
|
||||
const editArg = value.slice('edit'.length).trim().split(/ +/);
|
||||
if (editArg) {
|
||||
if (editArg[0].length > 0) {
|
||||
editSrc = await getChannelMessage(this.client, msg, editArg[0], editArg[1]);
|
||||
if (editSrc) {
|
||||
const editEmb = editSrc.embeds[0];
|
||||
|
|
@ -54,17 +63,23 @@ module.exports = class embmaker extends commando.Command {
|
|||
footericon = editEmb.footer.iconURL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reportMessage += "**[EDIT]** No editable embed found.\n";
|
||||
}
|
||||
} else {
|
||||
reportMessage += "**[EDIT]** Unknown message.\n";
|
||||
}
|
||||
} else {
|
||||
reportMessage += "**[EDIT]** No argument provided.\n";
|
||||
}
|
||||
}
|
||||
if (value.toLowerCase().startsWith('quote')) {
|
||||
const quoteargs = value.slice('quote'.length).toLowerCase().trim().split(/ +/);
|
||||
if (quoteargs) {
|
||||
if (quoteargs[0].length > 0) {
|
||||
await getChannelMessage(this.client, msg, quoteargs[0], quoteargs[1])
|
||||
.then(quoteThis => {
|
||||
if (quoteThis) {
|
||||
const author = quoteThis.guild.member(quoteThis.author);
|
||||
const author = quoteThis.member;
|
||||
autName = author ? author.displayName : quoteThis.author.username;
|
||||
autIcon = quoteThis.author.displayAvatarURL({size:4096,dynamic:true});
|
||||
autUrl = quoteThis.url;
|
||||
|
|
@ -78,14 +93,16 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (quoteThis.attachments) {
|
||||
for(const attach of quoteThis.attachments) {
|
||||
attach.map(g => {
|
||||
if (/^http/.test(g.proxyURL)) {
|
||||
newAttach.push(g.proxyURL);
|
||||
}
|
||||
newAttach.push(g.proxyURL);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reportMessage += "**[QUOTE]** Unknown message.\n";
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reportMessage += "**[QUOTE]** No argument provided.\n";
|
||||
}
|
||||
}
|
||||
if (value.toLowerCase().startsWith('remove')) {
|
||||
|
|
@ -126,6 +143,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(autVal.slice('icon'.length).trim())) {
|
||||
autIcon = autVal.slice('icon'.length).trim();
|
||||
} else {
|
||||
reportMessage += "**[AUTHOR]** Invalid icon URL.\n";
|
||||
autIcon = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -133,6 +151,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(autVal.slice('url'.length).trim())) {
|
||||
autUrl = autVal.slice('url'.length).trim();
|
||||
} else {
|
||||
reportMessage += "**[AUTHOR]** Invalid URL.\n";
|
||||
autUrl = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -149,6 +168,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(value.slice("image".length).trim())) {
|
||||
embed.setImage(value.slice("image".length).trim());
|
||||
} else {
|
||||
reportMessage += "**[IMAGE]** Invalid URL.\n";
|
||||
embed.setImage(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -156,6 +176,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(value.slice("thumbnail".length).trim())) {
|
||||
embed.setThumbnail(value.slice("thumbnail".length).trim());
|
||||
} else {
|
||||
reportMessage += "**[THUMBNAIL]** Invalid URL.\n";
|
||||
embed.setThumbnail(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -163,6 +184,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(value.slice("url".length).trim())) {
|
||||
embed.setURL(value.slice("url".length).trim());
|
||||
} else {
|
||||
reportMessage += "**[URL]** Invalid URL.\n";
|
||||
embed.setURL(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,22 +193,26 @@ module.exports = class embmaker extends commando.Command {
|
|||
for(const theFile of attach) {
|
||||
if (/^http/.test(theFile)) {
|
||||
newAttach.push(theFile);
|
||||
} else {
|
||||
if (theFile.toLowerCase() !== "-copy") {
|
||||
reportMessage += "**[ATTACHMENT]** Invalid URL.\n";
|
||||
}
|
||||
}
|
||||
if (theFile === '-copy' && editSrc) {
|
||||
if (editSrc.attachments) {
|
||||
if (theFile.toLowerCase() === '-copy' && editSrc) {
|
||||
if (editSrc.attachments[0].length > 0) {
|
||||
for(const attach of editSrc.attachments) {
|
||||
attach.map(g => {
|
||||
if (/^http/.test(g.proxyURL)) {
|
||||
newAttach.push(g.proxyURL);
|
||||
}
|
||||
newAttach.push(g.proxyURL);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
reportMessage += "**[ATTACHMENT]** No attachment to copy.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value.toLowerCase().startsWith("timestamp")) {
|
||||
if(!/[a-zA-Z]/.test(value.slice("timestamp".length).trim())) {
|
||||
if(!/\D/.test(value.slice("timestamp".length).trim())) {
|
||||
embed.setTimestamp(parseInt(value.slice("timestamp".length).trim(), 10));
|
||||
} else {
|
||||
if (value.slice("timestamp".length).trim().toLowerCase() === 'now') {
|
||||
|
|
@ -195,6 +221,9 @@ module.exports = class embmaker extends commando.Command {
|
|||
embed.setTimestamp(value.slice("timestamp".length).trim());
|
||||
}
|
||||
}
|
||||
if (!embed.timestamp) {
|
||||
reportMessage += "**[TIMESTAMP]** Invalid format.\n";
|
||||
}
|
||||
}
|
||||
if (value.toLowerCase().startsWith('footer')) {
|
||||
const footerData = value.trim().split(/( \-)+/);
|
||||
|
|
@ -206,6 +235,7 @@ module.exports = class embmaker extends commando.Command {
|
|||
if (/^http/.test(footval.slice('icon'.length).trim())) {
|
||||
footericon = footval.slice('icon'.length).trim();
|
||||
} else {
|
||||
reportMessage += "**[FOOTER]** Invalid icon URL.\n";
|
||||
footericon = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -243,12 +273,20 @@ module.exports = class embmaker extends commando.Command {
|
|||
let ID = value.slice('channel'.length).trim();
|
||||
if (ID.toLowerCase() === 'here') {
|
||||
channel = msg.channel;
|
||||
}
|
||||
if (ID.startsWith('<#') && ID.endsWith('>')) {
|
||||
ID = ID.slice(2, -1);
|
||||
}
|
||||
if (!/\D/.test(ID)) {
|
||||
channel = this.client.channels.cache.get(ID);
|
||||
} else {
|
||||
if (/^\d{17,19}$/.test(ID)) {
|
||||
channel = msg.guild.channels.cache.get(ID);
|
||||
if (!channel) {
|
||||
if (this.client.owners.includes(msg.author.id)) {
|
||||
channel = this.client.channels.cache.get(ID);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel = findChannelRegEx(msg, ID, ["category", "voice"])[0];
|
||||
}
|
||||
if (!channel) {
|
||||
reportMessage += "**[CHANNEL]** Unknown channel.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -280,7 +318,10 @@ module.exports = class embmaker extends commando.Command {
|
|||
embed = null;
|
||||
}
|
||||
if (newAttach.length > 0) {
|
||||
console.log("Uploading attachments...");
|
||||
reportMessage += "**[ATTACHMENT]** Uploading attachments....\n";
|
||||
}
|
||||
if (reportMessage.length > 0) {
|
||||
trySend(this.client, msg, reportMessage);
|
||||
}
|
||||
if (editSrc) {
|
||||
if (channel) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue