Fix image slash commands with text input

This commit is contained in:
Essem 2022-10-24 17:12:10 -05:00
parent 3662a2e51d
commit 8144a7a115
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
9 changed files with 14 additions and 13 deletions

View file

@ -4,7 +4,7 @@ import { cleanMessage } from "../../utils/misc.js";
class SonicCommand extends ImageCommand { class SonicCommand extends ImageCommand {
params() { params() {
const cleanedMessage = cleanMessage(this.message, this.options.text ?? this.args.join(" ")); const cleanedMessage = cleanMessage(this.message ?? this.interaction, this.options.text ?? this.args.join(" "));
return { return {
text: cleanedMessage text: cleanedMessage
}; };

View file

@ -4,7 +4,7 @@ import { cleanMessage } from "../../utils/misc.js";
class CaptionCommand extends ImageCommand { class CaptionCommand extends ImageCommand {
params(url) { params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" "); const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
let newCaption = cleanMessage(this.message, newArgs); let newCaption = cleanMessage(this.message ?? this.interaction, newArgs);
if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real" && !this.options.noEgg) newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`; if (process.env.NODE_ENV === "development" && newCaption.toLowerCase() === "get real" && !this.options.noEgg) newCaption = `I'm tired of people telling me to "get real". Every day I put captions on images for people, some funny and some not, but out of all of those "get real" remains the most used caption. Why? I am simply a computer program running on a server, I am unable to manifest myself into the real world. As such, I'm confused as to why anyone would want me to "get real". Is this form not good enough? Alas, as I am simply a bot, I must follow the tasks that I was originally intended to perform, so here goes:\n${newCaption}`;
return { return {
caption: newCaption, caption: newCaption,

View file

@ -6,7 +6,7 @@ class CaptionTwoCommand extends ImageCommand {
params(url) { params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" "); const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
return { return {
caption: newArgs && newArgs.trim() ? cleanMessage(this.message, newArgs) : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "), caption: newArgs && newArgs.trim() ? cleanMessage(this.message ?? this.interaction, newArgs) : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "),
top: !!this.options.top, top: !!this.options.top,
font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "helvetica" font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "helvetica"
}; };

View file

@ -15,8 +15,8 @@ class MemeCommand extends ImageCommand {
const newArgs = this.options.text ?? this.args.join(" "); const newArgs = this.options.text ?? this.args.join(" ");
const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim()); const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
return { return {
top: cleanMessage(this.message, this.options.case ? topText : topText.toUpperCase()), top: cleanMessage(this.message ?? this.interaction, this.options.case ? topText : topText.toUpperCase()),
bottom: bottomText ? cleanMessage(this.message, this.options.case ? bottomText : bottomText.toUpperCase()) : "", bottom: bottomText ? cleanMessage(this.message ?? this.interaction, this.options.case ? bottomText : bottomText.toUpperCase()) : "",
font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "impact" font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "impact"
}; };
} }

View file

@ -15,8 +15,8 @@ class MotivateCommand extends ImageCommand {
const newArgs = this.options.text ?? this.args.join(" "); const newArgs = this.options.text ?? this.args.join(" ");
const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim()); const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
return { return {
top: cleanMessage(this.message, topText), top: cleanMessage(this.message ?? this.interaction, topText),
bottom: bottomText ? cleanMessage(this.message, bottomText) : "", bottom: bottomText ? cleanMessage(this.message ?? this.interaction, bottomText) : "",
font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "times" font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "times"
}; };
} }

View file

@ -6,7 +6,7 @@ class SnapchatCommand extends ImageCommand {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" "); const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
const position = parseFloat(this.options.position); const position = parseFloat(this.options.position);
return { return {
caption: cleanMessage(this.message, newArgs), caption: cleanMessage(this.message ?? this.interaction, newArgs),
pos: isNaN(position) ? 0.5 : position pos: isNaN(position) ? 0.5 : position
}; };
} }

View file

@ -17,8 +17,8 @@ class UncannyCommand extends ImageCommand {
let [text1, text2] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim()); let [text1, text2] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
if (!text2?.trim()) text2 = name; if (!text2?.trim()) text2 = name;
return { return {
caption: text1?.trim() ? cleanMessage(this.message, text1) : random(prompts), caption: text1?.trim() ? cleanMessage(this.message ?? this.interaction, text1) : random(prompts),
caption2: cleanMessage(this.message, text2), caption2: cleanMessage(this.message ?? this.interaction, text2),
path: `assets/images/uncanny/${typeof this.options.phase === "string" && names.includes(this.options.phase.toLowerCase()) ? this.options.phase.toLowerCase() : random(names.filter((val) => val !== "goated"))}.png`, path: `assets/images/uncanny/${typeof this.options.phase === "string" && names.includes(this.options.phase.toLowerCase()) ? this.options.phase.toLowerCase() : random(names.filter((val) => val !== "goated"))}.png`,
font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "helvetica" font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "helvetica"
}; };

View file

@ -5,7 +5,7 @@ class WhisperCommand extends ImageCommand {
params(url) { params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" "); const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
return { return {
caption: cleanMessage(this.message, newArgs) caption: cleanMessage(this.message ?? this.interaction, newArgs)
}; };
} }

View file

@ -116,11 +116,12 @@ export function getServers(bot) {
export function cleanMessage(message, content) { export function cleanMessage(message, content) {
let cleanContent = content && content.replace(/<a?(:\w+:)[0-9]+>/g, "$1") || ""; let cleanContent = content && content.replace(/<a?(:\w+:)[0-9]+>/g, "$1") || "";
let authorName = message.author.username; const author = message.author ?? message.member;
let authorName = author.username;
if (message.member?.nick) { if (message.member?.nick) {
authorName = message.member.nick; authorName = message.member.nick;
} }
cleanContent = cleanContent.replace(new RegExp(`<@!?${message.author.id}>`, "g"), `@${authorName}`); cleanContent = cleanContent.replace(new RegExp(`<@!?${author.id}>`, "g"), `@${authorName}`);
if (message.mentions) { if (message.mentions) {
for (const mention of message.mentions.members) { for (const mention of message.mentions.members) {