Added extra font support to some other commands, handle overflow on image api
This commit is contained in:
parent
2644ce2d4a
commit
30bcb7a969
9 changed files with 44 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto"];
|
||||
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto", "times"];
|
||||
|
||||
class CaptionCommand extends ImageCommand {
|
||||
params(url) {
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
const words = ["me irl", "dank", "follow my second account @esmBot_", "2016", "meme", "wholesome", "reddit", "instagram", "twitter", "facebook", "fortnite", "minecraft", "relatable", "gold", "funny", "template", "hilarious", "memes", "deep fried", "2020", "leafy", "pewdiepie"];
|
||||
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto", "times"];
|
||||
|
||||
class CaptionTwoCommand extends ImageCommand {
|
||||
params(url) {
|
||||
const newArgs = this.args.filter(item => !item.includes(url));
|
||||
return {
|
||||
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(" "),
|
||||
top: !!this.specialArgs.top
|
||||
top: !!this.specialArgs.top,
|
||||
font: this.specialArgs.font && allowedFonts.includes(this.specialArgs.font.toLowerCase()) ? this.specialArgs.font.toLowerCase() : "helvetica"
|
||||
};
|
||||
}
|
||||
|
||||
static description = "Adds a me.me caption/tag list to an image/GIF";
|
||||
static description = "Adds a me.me caption/tag list to an image";
|
||||
static aliases = ["tags2", "meirl", "memecaption", "medotmecaption"];
|
||||
static arguments = ["{text}"];
|
||||
static flags = [{
|
||||
name: "top",
|
||||
description: "Put the caption on the top of an image/GIF instead of the bottom"
|
||||
description: "Put the caption on the top of an image instead of the bottom"
|
||||
}, {
|
||||
name: "font",
|
||||
type: allowedFonts.join("|"),
|
||||
description: "Specify the font you want to use (default: `helvetica`)"
|
||||
}];
|
||||
|
||||
static noText = "You need to provide some text to add a caption!";
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto", "times"];
|
||||
|
||||
class MemeCommand extends ImageCommand {
|
||||
params(url) {
|
||||
|
@ -6,7 +7,8 @@ class MemeCommand extends ImageCommand {
|
|||
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
|
||||
return {
|
||||
top: (this.specialArgs.case ? topText : topText.toUpperCase()).replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%"),
|
||||
bottom: bottomText ? (this.specialArgs.case ? bottomText : bottomText.toUpperCase()).replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : ""
|
||||
bottom: bottomText ? (this.specialArgs.case ? bottomText : bottomText.toUpperCase()).replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : "",
|
||||
font: this.specialArgs.font && allowedFonts.includes(this.specialArgs.font.toLowerCase()) ? this.specialArgs.font.toLowerCase() : "impact"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,6 +17,10 @@ class MemeCommand extends ImageCommand {
|
|||
static flags = [{
|
||||
name: "case",
|
||||
description: "Make the meme text case-sensitive (allows for lowercase text)"
|
||||
}, {
|
||||
name: "font",
|
||||
type: allowedFonts.join("|"),
|
||||
description: "Specify the font you want to use (default: `impact`)"
|
||||
}];
|
||||
|
||||
static requiresText = true;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import ImageCommand from "../../classes/imageCommand.js";
|
||||
const allowedFonts = ["futura", "impact", "helvetica", "arial", "roboto", "noto", "times"];
|
||||
|
||||
class MotivateCommand extends ImageCommand {
|
||||
params(url) {
|
||||
|
@ -6,13 +7,19 @@ class MotivateCommand extends ImageCommand {
|
|||
const [topText, bottomText] = newArgs.join(" ").split(/(?<!\\),/).map(elem => elem.trim());
|
||||
return {
|
||||
top: topText.replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%"),
|
||||
bottom: bottomText ? bottomText.replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : ""
|
||||
bottom: bottomText ? bottomText.replaceAll("&", "\\&").replaceAll(">", "\\>").replaceAll("<", "\\<").replaceAll("\"", "\\"").replaceAll("'", "\\'").replaceAll("%", "\\%") : "",
|
||||
font: this.specialArgs.font && allowedFonts.includes(this.specialArgs.font.toLowerCase()) ? this.specialArgs.font.toLowerCase() : "times"
|
||||
};
|
||||
}
|
||||
|
||||
static description = "Generates a motivational poster";
|
||||
static aliases = ["motivational", "motiv", "demotiv", "demotivational", "poster", "motivation", "demotivate"];
|
||||
static arguments = ["[top text]", "{bottom text}"];
|
||||
static flags = [{
|
||||
name: "font",
|
||||
type: allowedFonts.join("|"),
|
||||
description: "Specify the font you want to use (default: `times`)"
|
||||
}];
|
||||
|
||||
static requiresText = true;
|
||||
static noText = "You need to provide some text to generate a motivational poster!";
|
||||
|
|
|
@ -15,6 +15,7 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
|||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string caption = obj.Get("caption").As<Napi::String>().Utf8Value();
|
||||
bool top = obj.Get("top").As<Napi::Boolean>().Value();
|
||||
string font = obj.Get("font").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -39,7 +40,10 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
|
|||
caption_image.fillColor("black");
|
||||
caption_image.font("Helvetica Neue");
|
||||
caption_image.fontPointsize(width / 17);
|
||||
caption_image.read("pango:" + caption);
|
||||
caption_image.read("pango:<span font_family=\"" +
|
||||
(font == "roboto" ? "Roboto Condensed" : font) +
|
||||
"\" weight=\"" + (font != "impact" ? "bold" : "normal") +
|
||||
"\">" + caption + "</span>");
|
||||
caption_image.extent(Geometry(width, caption_image.rows() + (width / 25)),
|
||||
Magick::CenterGravity);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
|||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string top = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||
string bottom = obj.Get("bottom").As<Napi::String>().Utf8Value();
|
||||
string font = obj.Get("font").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -43,7 +44,10 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
|
|||
top_text.font("Impact");
|
||||
top_text.fontPointsize(width / 12);
|
||||
top_text.textGravity(Magick::CenterGravity);
|
||||
top_text.read("pango:<span foreground='white'>" + top + "</span>");
|
||||
top_text.read("pango:<span font_family=\"" +
|
||||
(font == "roboto" ? "Roboto Condensed" : font) +
|
||||
"\" weight=\"" + (font != "impact" ? "bold" : "normal") +
|
||||
"\" foreground='white'>" + top + "</span>");
|
||||
Image top_text_fill = top_text;
|
||||
top_text_fill.channel(Magick::AlphaChannel);
|
||||
top_text_fill.morphology(Magick::EdgeOutMorphology, "Octagon");
|
||||
|
|
|
@ -15,6 +15,7 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
|||
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
|
||||
string top_text = obj.Get("top").As<Napi::String>().Utf8Value();
|
||||
string bottom_text = obj.Get("bottom").As<Napi::String>().Utf8Value();
|
||||
string font = obj.Get("font").As<Napi::String>().Utf8Value();
|
||||
string type = obj.Get("type").As<Napi::String>().Utf8Value();
|
||||
int delay =
|
||||
obj.Has("delay") ? obj.Get("delay").As<Napi::Number>().Int32Value() : 0;
|
||||
|
@ -40,7 +41,10 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
|
|||
top.font("Times");
|
||||
top.textGravity(Magick::CenterGravity);
|
||||
top.fontPointsize(56);
|
||||
top.read("pango:<span foreground='white'>" + top_text + "</span>");
|
||||
top.read("pango:<span font_family=\"" +
|
||||
(font == "roboto" ? "Roboto Condensed" : font) +
|
||||
"\" weight=\"" + (font != "impact" ? "bold" : "normal") +
|
||||
"\" foreground='white'>" + top_text + "</span>");
|
||||
top.extent(Geometry(bottom_text != "" ? to_string(top.columns()) + "x" +
|
||||
to_string(top.rows())
|
||||
: to_string(top.columns()) + "x" +
|
||||
|
|
|
@ -152,7 +152,8 @@ class ImageConnection {
|
|||
|
||||
async do(op, data) {
|
||||
const buf = Buffer.alloc(1 + 2);
|
||||
const tag = this.tag++;
|
||||
let tag = this.tag++;
|
||||
if (tag > 65535) tag = this.tag = 0;
|
||||
buf.writeUint8(op);
|
||||
buf.writeUint16LE(tag, 1);
|
||||
this.conn.send(Buffer.concat([buf, data]));
|
||||
|
|
|
@ -108,7 +108,8 @@ class ImageWorker extends BaseServiceWorker {
|
|||
|
||||
async run(object) {
|
||||
if (process.env.API === "true") {
|
||||
const num = this.nextID++;
|
||||
let num = this.nextID++;
|
||||
if (num > 4294967295) num = this.nextID = 0;
|
||||
const currentServer = await this.getIdeal(object);
|
||||
await currentServer.queue(num, object);
|
||||
await currentServer.wait(num);
|
||||
|
|
Loading…
Reference in a new issue