mrmBot-Matrix/commands/image-editing/motivate.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

import ImageCommand from "../../classes/imageCommand.js";
2022-09-11 04:48:44 +00:00
import { textEncode } from "../../utils/misc.js";
class MotivateCommand extends ImageCommand {
async criteria(text, url) {
const [topText, bottomText] = text.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
if (topText === "" && bottomText === "") {
return false;
} else {
return true;
}
}
params(url) {
const newArgs = this.options.text ?? this.args.join(" ");
const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
return {
2022-09-11 04:48:44 +00:00
top: textEncode(topText),
bottom: bottomText ? textEncode(bottomText) : "",
font: typeof this.options.font === "string" && this.constructor.allowedFonts.includes(this.options.font.toLowerCase()) ? this.options.font.toLowerCase() : "times"
};
}
static init() {
super.init();
this.flags.push({
name: "font",
type: 3,
choices: (() => {
const array = [];
for (const font of this.allowedFonts) {
array.push({ name: font, value: font });
}
return array;
})(),
description: "Specify the font you want to use (default: times)"
});
return this;
}
static description = "Generates a motivational poster";
static aliases = ["motivational", "motiv", "demotiv", "demotivational", "poster", "motivation", "demotivate"];
static arguments = ["[top text]", "{bottom text}"];
static requiresText = true;
2021-05-24 19:31:44 +00:00
static noText = "You need to provide some text to generate a motivational poster!";
static noImage = "You need to provide an image/GIF to generate a motivational poster!";
static command = "motivate";
}
export default MotivateCommand;