Rework image API again, replaced many calls to replace with replaceAll
This commit is contained in:
parent
b2b8fd643a
commit
62346cbae4
15 changed files with 271 additions and 185 deletions
|
@ -9,7 +9,7 @@ exports.run = async (message, args) => {
|
|||
const { buffer, type } = await magick.run({
|
||||
cmd: "caption",
|
||||
path: image.path,
|
||||
caption: newArgs.join(" ").replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%"),
|
||||
caption: newArgs.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%"),
|
||||
type: image.type
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
|
|
|
@ -9,7 +9,7 @@ exports.run = async (message, args) => {
|
|||
const { buffer, type } = await magick.run({
|
||||
cmd: "captionTwo",
|
||||
path: image.path,
|
||||
caption: newArgs.length !== 0 ? newArgs.join(" ").replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "),
|
||||
caption: newArgs.length !== 0 ? newArgs.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : words.sort(() => 0.5 - Math.random()).slice(0, Math.floor(Math.random() * words.length + 1)).join(" "),
|
||||
type: image.type
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
|
|
|
@ -11,7 +11,7 @@ exports.run = async (message, args) => {
|
|||
if (args[0].toLowerCase() === "disable") {
|
||||
let channel;
|
||||
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
|
||||
const id = args[1].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "");
|
||||
const id = args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
|
||||
if (guildDB.disabled.includes(id)) return `${message.author.mention}, I'm already disabled in this channel!`;
|
||||
channel = message.channel.guild.channels.get(id);
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ exports.run = async (message, args) => {
|
|||
} else if (args[0].toLowerCase() === "enable") {
|
||||
let channel;
|
||||
if (args[1] && args[1].match(/^<?[@#]?[&!]?\d+>?$/) && args[1] >= 21154535154122752) {
|
||||
const id = args[1].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "");
|
||||
const id = args[1].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "");
|
||||
if (!guildDB.disabled.includes(id)) return `${message.author.mention}, I'm not disabled in that channel!`;
|
||||
channel = message.channel.guild.channels.get(id);
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ exports.run = async (message, args) => {
|
|||
const image = await require("../utils/imagedetect.js")(message);
|
||||
if (image === undefined) return `${message.author.mention}, you need to provide an image to overlay a flag onto!`;
|
||||
if (!args[0].match(emojiRegex)) return `${message.author.mention}, you need to provide an emoji of a flag to overlay!`;
|
||||
const flag = emoji.unemojify(args[0]).replace(/:/g, "").replace("flag-", "");
|
||||
const flag = emoji.unemojify(args[0]).replaceAll(":", "").replace("flag-", "");
|
||||
let path = `./assets/images/region-flags/png/${flag.toUpperCase()}.png`;
|
||||
if (flag === "🏴☠️") path = "./assets/images/pirateflag.png";
|
||||
if (flag === "rainbow-flag") path = "./assets/images/rainbowflag.png";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
exports.run = async (message, args) => {
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to convert to fullwidth!`;
|
||||
return args.join("").replace(/[A-Za-z0-9]/g, (s) => { return String.fromCharCode(s.charCodeAt(0) + 0xFEE0); });
|
||||
return args.join("").replaceAll(/[A-Za-z0-9]/g, (s) => { return String.fromCharCode(s.charCodeAt(0) + 0xFEE0); });
|
||||
};
|
||||
|
||||
exports.aliases = ["aesthetic", "aesthetics", "aes"];
|
||||
|
|
|
@ -5,7 +5,7 @@ exports.run = async (message, args) => {
|
|||
message.channel.sendTyping();
|
||||
const { buffer } = await magick.run({
|
||||
cmd: "homebrew",
|
||||
caption: args.join(" ").toLowerCase().replace(/\n/g, " ")
|
||||
caption: args.join(" ").toLowerCase().replaceAll("\n", " ")
|
||||
});
|
||||
return {
|
||||
file: buffer,
|
||||
|
|
|
@ -10,8 +10,8 @@ exports.run = async (message, args) => {
|
|||
const { buffer, type } = await magick.run({
|
||||
cmd: "meme",
|
||||
path: image.path,
|
||||
top: topText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%"),
|
||||
bottom: bottomText ? bottomText.toUpperCase().replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%") : "",
|
||||
top: topText.toUpperCase().replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%"),
|
||||
bottom: bottomText ? bottomText.toUpperCase().replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : "",
|
||||
type: image.type
|
||||
});
|
||||
return {
|
||||
|
|
|
@ -10,8 +10,8 @@ exports.run = async (message, args) => {
|
|||
const { buffer, type } = await magick.run({
|
||||
cmd: "motivate",
|
||||
path: image.path,
|
||||
top: topText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%"),
|
||||
bottom: bottomText ? bottomText.replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%") : "",
|
||||
top: topText.replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%"),
|
||||
bottom: bottomText ? bottomText.replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : "",
|
||||
type: image.type
|
||||
});
|
||||
if (processMessage.channel.messages.get(processMessage.id)) await processMessage.delete();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
exports.run = async (message, args) => {
|
||||
if (!args[0]) return `${message.author.mention}, you need to provide a snowflake ID!`;
|
||||
if (!args[0].match(/^<?[@#]?[&!]?\d+>?$/) && args[0] < 21154535154122752) return `${message.author.mention}, that's not a valid snowflake!`;
|
||||
return new Date((args[0].replace(/@/g, "").replace(/#/g, "").replace(/!/g, "").replace(/&/g, "").replace(/</g, "").replace(/>/g, "") / 4194304) + 1420070400000).toUTCString();
|
||||
return new Date((args[0].replaceAll("@", "").replaceAll("#", "").replaceAll("!", "").replaceAll("&", "").replaceAll("<", "").replaceAll(">", "") / 4194304) + 1420070400000).toUTCString();
|
||||
};
|
||||
|
||||
exports.aliases = ["timestamp", "snowstamp", "snow"];
|
||||
|
|
|
@ -4,7 +4,7 @@ const wrap = require("../utils/wrap.js");
|
|||
exports.run = async (message, args) => {
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide some text to make a Sonic meme!`;
|
||||
message.channel.sendTyping();
|
||||
const cleanedMessage = args.join(" ").replace(/&/g, "\\&").replace(/>/g, "\\>").replace(/</g, "\\<").replace(/"/g, "\\"").replace(/'/g, "\\'").replace(/%/g, "\\%");
|
||||
const cleanedMessage = args.join(" ").replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%");
|
||||
const { buffer } = await magick.run({
|
||||
cmd: "sonic",
|
||||
text: wrap(cleanedMessage, {width: 15, indent: ""})
|
||||
|
|
|
@ -10,11 +10,11 @@ exports.run = async (message, args) => {
|
|||
const result = await request.json();
|
||||
for (const [i, value] of result.items.entries()) {
|
||||
if (value.id.kind === "youtube#channel") {
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replace(/\*/g, "\\*")}**\nhttps://youtube.com/channel/${value.id.channelId}`);
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nhttps://youtube.com/channel/${value.id.channelId}`);
|
||||
} else if (value.id.kind === "youtube#playlist") {
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replace(/\*/g, "\\*")}**\nCreated by **${decodeEntities(value.snippet.channelTitle).replace(/\*/g, "\\*")}**\nhttps://youtube.com/playlist?list=${value.id.playlistId}`);
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nCreated by **${decodeEntities(value.snippet.channelTitle).replaceAll("*", "\\*")}**\nhttps://youtube.com/playlist?list=${value.id.playlistId}`);
|
||||
} else {
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replace(/\*/g, "\\*")}**\nUploaded by **${decodeEntities(value.snippet.channelTitle).replace(/\*/g, "\\*")}** on **${value.snippet.publishedAt.split("T")[0]}**\nhttps://youtube.com/watch?v=${value.id.videoId}`);
|
||||
messages.push(`Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nUploaded by **${decodeEntities(value.snippet.channelTitle).replaceAll("*", "\\*")}** on **${value.snippet.publishedAt.split("T")[0]}**\nhttps://youtube.com/watch?v=${value.id.videoId}`);
|
||||
}
|
||||
}
|
||||
return paginator(message, messages);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue