diff --git a/backend/src/plugins/Tags/TagsPlugin.ts b/backend/src/plugins/Tags/TagsPlugin.ts index 0b5763ff..f43169a1 100644 --- a/backend/src/plugins/Tags/TagsPlugin.ts +++ b/backend/src/plugins/Tags/TagsPlugin.ts @@ -8,7 +8,7 @@ import { GuildLogs } from "../../data/GuildLogs"; import { GuildSavedMessages } from "../../data/GuildSavedMessages"; import { GuildTags } from "../../data/GuildTags"; import { mapToPublicFn } from "../../pluginUtils"; -import { convertDelayStringToMS } from "../../utils"; +import { convertDelayStringToMS, trimPluginDescription } from "../../utils"; import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin"; import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint"; import { TagCreateCmd } from "./commands/TagCreateCmd"; @@ -22,6 +22,8 @@ import { onMessageCreate } from "./util/onMessageCreate"; import { onMessageDelete } from "./util/onMessageDelete"; import { renderTagBody } from "./util/renderTagBody"; import { LogsPlugin } from "../Logs/LogsPlugin"; +import { generateTemplateMarkdown } from "./docs"; +import { TemplateFunctions } from "./templateFunctions"; const defaultOptions: PluginOptions = { config: { @@ -58,6 +60,18 @@ export const TagsPlugin = zeppelinGuildPlugin()({ showInDocs: true, info: { prettyName: "Tags", + description: trimPluginDescription(` + Tags are a way to store and reuse information. + `), + configurationGuide: trimPluginDescription(` + ### Template Functions + You can use template functions in your tags. These functions are called when the tag is rendered. + You can use these functions to render dynamic content, or to access information from the message and/or user calling the tag. + You use them by adding a \`{}\` on your tag. + + ### Available Functions + ${generateTemplateMarkdown(TemplateFunctions)} + `), }, configSchema: ConfigSchema, diff --git a/backend/src/plugins/Tags/docs.ts b/backend/src/plugins/Tags/docs.ts index e69de29b..ee990dc2 100644 --- a/backend/src/plugins/Tags/docs.ts +++ b/backend/src/plugins/Tags/docs.ts @@ -0,0 +1,19 @@ +import { TemplateFunction } from "./types"; + +export function generateTemplateMarkdown(definitions: TemplateFunction[]): string { + const table = definitions + .map(def => { + const argsString = def.signature ?? `(${def.arguments.join(", ")})`; + const usage = def.signature ? `| ${def.signature} |` : argsString; + const exampl = def.examples ? def.examples.map(ex => `> ${ex}`).join("\n") : ""; + return ` + #### ${def.name} + \`${usage}\` + **${def.description}** + ${exampl} + `; + }) + .join("\n\n"); + + return table; +} diff --git a/backend/src/plugins/Tags/templateFunctions.ts b/backend/src/plugins/Tags/templateFunctions.ts index ac113501..1af05c79 100644 --- a/backend/src/plugins/Tags/templateFunctions.ts +++ b/backend/src/plugins/Tags/templateFunctions.ts @@ -1,6 +1,7 @@ import { TemplateFunction } from "./types"; -export const functions: TemplateFunction[] = [ +// TODO: Generate this dynamically, lmao +export const TemplateFunctions: TemplateFunction[] = [ { name: "info", description: "Checks if a condition is true or false and returns the corresponding ifTrue or ifFalse", @@ -78,4 +79,88 @@ export const functions: TemplateFunction[] = [ arguments: ["argument1", "argument2"], examples: ["lte(2, 2)"], }, + { + name: "slice", + description: "Slices a string argument at start and end", + returnValue: "string", + arguments: ["string", "start", "end"], + examples: ['slice("Hello World", 0, 5)'], + }, + { + name: "lower", + description: "Converts a string argument to lowercase", + returnValue: "string", + arguments: ["string"], + examples: ['lower("Hello World")'], + }, + { + name: "upper", + description: "Converts a string argument to uppercase", + returnValue: "string", + arguments: ["string"], + examples: ['upper("Hello World")'], + }, + { + name: "upperFirst", + description: "Converts the first character of a string argument to uppercase", + returnValue: "string", + arguments: ["string"], + examples: ['upperFirst("hello World")'], + }, + { + name: "rand", + description: "Returns a random number between from and to, optionally using seed", + returnValue: "number", + arguments: ["from", "to", "seed"], + examples: ["rand(1, 10)"], + }, + { + name: "round", + description: "Rounds a number to the given decimal places", + returnValue: "number", + arguments: ["number", "decimalPlaces"], + examples: ["round(1.2345, 2)"], + }, + { + name: "add", + description: "Adds two or more numbers", + returnValue: "number", + arguments: ["number1", "number2", "..."], + examples: ["add(1, 2)"], + }, + { + name: "sub", + description: "Subtracts two or more numbers", + returnValue: "number", + arguments: ["number1", "number2", "..."], + examples: ["sub(3, 1)"], + }, + { + name: "mul", + description: "Multiplies two or more numbers", + returnValue: "number", + arguments: ["number1", "number2", "..."], + examples: ["mul(2, 3)"], + }, + { + name: "div", + description: "Divides two or more numbers", + returnValue: "number", + arguments: ["number1", "number2", "..."], + examples: ["div(6, 2)"], + }, + { + name: "cases", + description: "Returns the argument at position", + returnValue: "any", + arguments: ["position", "argument1", "argument2", "..."], + examples: ['cases(1, "Hello", "World")'], + }, + { + name: "choose", + description: "Returns a random argument", + returnValue: "any", + arguments: ["argument1", "argument2", "..."], + examples: ['choose("Hello", "World", "!")'], + }, ];