From 0e01b4bb3850dd41b90bcaa28454083c171edca9 Mon Sep 17 00:00:00 2001 From: Ruko <92655412+rukogit@users.noreply.github.com> Date: Wed, 17 May 2023 22:25:25 +0200 Subject: [PATCH 1/4] Update templateFunctions.ts Added set, setr, get, tag, mention, isMention, strlen, timeAdd, timeSub, timeAgo, countdown, parseDateTime, formatTime and now to the template functions in the tags docs. --- backend/src/plugins/Tags/templateFunctions.ts | 135 +++++++++++++++--- 1 file changed, 113 insertions(+), 22 deletions(-) diff --git a/backend/src/plugins/Tags/templateFunctions.ts b/backend/src/plugins/Tags/templateFunctions.ts index 67a49069..1cff24fe 100644 --- a/backend/src/plugins/Tags/templateFunctions.ts +++ b/backend/src/plugins/Tags/templateFunctions.ts @@ -4,154 +4,161 @@ import { TemplateFunction } from "./types"; export const TemplateFunctions: TemplateFunction[] = [ { name: "if", - description: "Checks if a condition is true or false and returns the corresponding ifTrue or ifFalse", + description: "Checks if a condition is true or false and returns the corresponding ifTrue or ifFalse.", returnValue: "boolean", arguments: ["condition", "ifTrue", "ifFalse"], examples: ['if(user.bot, "User is a bot", "User is not a bot")'], }, { name: "and", - description: "Checks if all provided conditions are true", + description: "Checks if all provided conditions are true.", returnValue: "boolean", arguments: ["condition1", "condition2", "..."], examples: ["and(user.bot, user.verified)"], }, { name: "or", - description: "Checks if atleast one of the provided conditions is true", + description: "Checks if at least one of the provided conditions is true.", returnValue: "boolean", arguments: ["condition1", "condition2", "..."], examples: ["or(user.bot, user.verified)"], }, { name: "not", - description: "Checks if the provided condition is false", + description: "Checks if the provided condition is false.", returnValue: "boolean", arguments: ["condition"], examples: ["not(user.bot)"], }, { name: "concat", - description: "Concatenates several arguments into a string", + description: "Concatenates several arguments into a string.", returnValue: "string", arguments: ["argument1", "argument2", "..."], examples: ['concat("Hello ", user.username, "!")'], }, { name: "concatArr", - description: "Joins a array with the provided separator", + description: "Joins an array with the provided separator.", returnValue: "string", arguments: ["array", "separator"], examples: ['concatArr(["Hello", "World"], " ")'], }, { name: "eq", - description: "Checks if all provided arguments are equal to each other", + description: "Checks if all provided arguments are equal to each other.", returnValue: "boolean", arguments: ["argument1", "argument2", "..."], examples: ['eq(user.id, "106391128718245888")'], }, { name: "gt", - description: "Checks if the first argument is greater than the second", + description: "Checks if the first argument is greater than the second.", returnValue: "boolean", arguments: ["argument1", "argument2"], examples: ["gt(5, 2)"], }, { name: "gte", - description: "Checks if the first argument is greater or equal to the second", + description: "Checks if the first argument is greater or equal to the second.", returnValue: "boolean", arguments: ["argument1", "argument2"], examples: ["gte(2, 2)"], }, { name: "lt", - description: "Checks if the first argument is smaller than the second", + description: "Checks if the first argument is smaller than the second.", returnValue: "boolean", arguments: ["argument1", "argument2"], examples: ["lt(2, 5)"], }, { name: "lte", - description: "Checks if the first argument is smaller or equal to the second", + description: "Checks if the first argument is smaller or equal to the second.", returnValue: "boolean", arguments: ["argument1", "argument2"], examples: ["lte(2, 2)"], }, { name: "slice", - description: "Slices a string argument at start and end", + 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", + description: "Converts a string argument to lowercase.", returnValue: "string", arguments: ["string"], examples: ['lower("Hello World")'], }, { name: "upper", - description: "Converts a string argument to uppercase", + 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", + description: "Converts the first character of a string argument to uppercase.", returnValue: "string", arguments: ["string"], examples: ['upperFirst("hello World")'], }, + { + name: "strlen", + description: "Returns the length of a string argument.", + returnValue: "string", + arguments: ["string"], + examples: ['strlen("hello World")'], + }, { name: "rand", - description: "Returns a random number between from and to, optionally using seed", + 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", + 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", + description: "Adds two or more numbers.", returnValue: "number", arguments: ["number1", "number2", "..."], examples: ["add(1, 2)"], }, { name: "sub", - description: "Subtracts two or more numbers", + description: "Subtracts two or more numbers.", returnValue: "number", arguments: ["number1", "number2", "..."], examples: ["sub(3, 1)"], }, { name: "mul", - description: "Multiplies two or more numbers", + description: "Multiplies two or more numbers.", returnValue: "number", arguments: ["number1", "number2", "..."], examples: ["mul(2, 3)"], }, { name: "div", - description: "Divides two or more numbers", + description: "Divides two or more numbers.", returnValue: "number", arguments: ["number1", "number2", "..."], examples: ["div(6, 2)"], }, { name: "cases", - description: "Returns the argument at position", + description: "Returns the argument at the position.", returnValue: "any", arguments: ["position", "argument1", "argument2", "..."], examples: ['cases(1, "Hello", "World")'], @@ -163,4 +170,88 @@ export const TemplateFunctions: TemplateFunction[] = [ arguments: ["argument1", "argument2", "..."], examples: ['choose("Hello", "World", "!")'], }, +{ + name: "tag", + description: "Returns the return value of an existing tag.", + returnValue: "any", + arguments: ["tagName"], + examples: ['tag("tagName")'], + }, +{ + name: "mentions", + description: "Converts a user-id into a mention.", + returnValue: "string", + arguments: ["user-id"], + examples: ['mention(106391128718245888)'], + }, +{ + name: "isMention", + description: "Checks if the given string is a mention.", + returnValue: "boolean", + arguments: ["string"], + examples: ['isMention("<@!106391128718245888>'], + }, +{ + name: "parseDateTime", + description: "Parses a date string/unix timestamp into a unix.", + returnValue: "number", + arguments: ["date"], + examples: ['parseDateTime(1234567898765)', 'parseDateTime(2009-02-13T23:31:38Z)'], + }, +{ + name: "timeAdd", + description: "Adds a delay to a timestamp or to the current time.", + returnValue: "number", + arguments: ["timestamp", "delay"], + examples: ['timeAdd(123456789876, "1h")', 'timeAdd("1h")'], + }, +{ + name: "timeSub", + description: "Subtracts a delay from a timestamp or from the current time.", + returnValue: "number", + arguments: ["timestamp", "delay"], + examples: ['timeSub(123456789876, "1h")', 'timeSub("1h")'], + }, +{ + name: "timeAgo", + description: "Alias for timeSub.", + returnValue: "number", + arguments: ["delay"], + examples: ['timeAgo("1h")'], + }, +{ + name: "countdown", + description: "Returns a countdown string to target timestamp.", + returnValue: "string", + arguments: ["timestamp"], + examples: ['countdown(123456789876)'], + }, +{ + name: "formatTime", + description: "Formats a timestamp into a human readable string.", + returnValue: "string", + arguments: ["timestamp", "formatStyle"], + examples: ['{formatTime(now(), "YYYY-MM-DD HH")}'], + }, +{ + name: "set", + description: "Sets the value of a variable.", + returnValue: "any", + arguments: ["variableName", "value"], + examples: ['set("Hello", "World")'], + }, +{ + name: "setr", + description: "Sets and returns the value of a variable.", + returnValue: "any", + arguments: ["variableName", "value"], + examples: ['setr("Hello", "World")'], + }, +{ + name: "get", + description: "Gets and returns the value of a saved variable.", + returnValue: "any", + arguments: ["variableName"], + examples: ['get("variable")'], + }, ]; From 512630fbae1884036e1d6a625257388c7664a3d0 Mon Sep 17 00:00:00 2001 From: Ruko <92655412+rukogit@users.noreply.github.com> Date: Fri, 19 May 2023 16:54:46 +0200 Subject: [PATCH 2/4] Update templateFunctions.ts --- backend/src/plugins/Tags/templateFunctions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Tags/templateFunctions.ts b/backend/src/plugins/Tags/templateFunctions.ts index 1cff24fe..d1f361a2 100644 --- a/backend/src/plugins/Tags/templateFunctions.ts +++ b/backend/src/plugins/Tags/templateFunctions.ts @@ -174,8 +174,8 @@ export const TemplateFunctions: TemplateFunction[] = [ name: "tag", description: "Returns the return value of an existing tag.", returnValue: "any", - arguments: ["tagName"], - examples: ['tag("tagName")'], + arguments: ["tagName", "optionalArgs"], + examples: ['tag("tagName", 123)'], }, { name: "mentions", From c2b2434c285551ef2fa62362c7b6e1b811aab7bb Mon Sep 17 00:00:00 2001 From: Ruko <92655412+rukogit@users.noreply.github.com> Date: Sun, 21 May 2023 17:48:08 +0200 Subject: [PATCH 3/4] Update templateFunctions.ts changed the optional argument in for tag from 123 to "Hello World" fixed typo --- backend/src/plugins/Tags/templateFunctions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/plugins/Tags/templateFunctions.ts b/backend/src/plugins/Tags/templateFunctions.ts index d1f361a2..273ac1ae 100644 --- a/backend/src/plugins/Tags/templateFunctions.ts +++ b/backend/src/plugins/Tags/templateFunctions.ts @@ -175,10 +175,10 @@ export const TemplateFunctions: TemplateFunction[] = [ description: "Returns the return value of an existing tag.", returnValue: "any", arguments: ["tagName", "optionalArgs"], - examples: ['tag("tagName", 123)'], + examples: ['tag("tagName", "Hello World")'], }, { - name: "mentions", + name: "mention", description: "Converts a user-id into a mention.", returnValue: "string", arguments: ["user-id"], From 58549d8ae2c706a95adae32cea71606cc65bee71 Mon Sep 17 00:00:00 2001 From: Ruko <92655412+rukogit@users.noreply.github.com> Date: Sat, 1 Jul 2023 17:28:16 +0200 Subject: [PATCH 4/4] Update templateFunctions.ts Changed the returnValue for strlen from string to number --- backend/src/plugins/Tags/templateFunctions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/plugins/Tags/templateFunctions.ts b/backend/src/plugins/Tags/templateFunctions.ts index 273ac1ae..7eb374ef 100644 --- a/backend/src/plugins/Tags/templateFunctions.ts +++ b/backend/src/plugins/Tags/templateFunctions.ts @@ -110,7 +110,7 @@ export const TemplateFunctions: TemplateFunction[] = [ { name: "strlen", description: "Returns the length of a string argument.", - returnValue: "string", + returnValue: "number", arguments: ["string"], examples: ['strlen("hello World")'], },