diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 45aea41a0..5cb76d06d 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1918,6 +1918,46 @@ export function initDefaultSlashCommands() { ], helpString: 'Converts the provided string to lowercase.', })); + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'substr', + aliases: ['substring'], + callback: (arg, text) => typeof text === 'string' ? text.slice(...[Number(arg.start), arg.end && Number(arg.end)]) : '', + returns: 'substring', + namedArgumentList: [ + new SlashCommandNamedArgument( + 'start', 'start index', [ARGUMENT_TYPE.NUMBER], false, false, + ), + new SlashCommandNamedArgument( + 'end', 'end index', [ARGUMENT_TYPE.NUMBER], false, false, + ), + ], + unnamedArgumentList: [ + new SlashCommandArgument( + 'string', [ARGUMENT_TYPE.STRING], true, false, + ), + ], + helpString: ` +
start
is omitted, it's treated as 0.start
< 0, the index is counted from the end of the string.start
>= the string's length, an empty string is returned.end
is omitted, or if end
>= the string's length, extracts to the end of the string.end
< 0, the index is counted from the end of the string.end
<= start
after normalizing negative values, an empty string is returned.
+ /let x The morning is upon us. ||+
/substr start=-3 {{var::x}} | /echo |/# us. ||+
/substr start=-3 end=-1 {{var::x}} | /echo |/# us ||+
/substr end=-1 {{var::x}} | /echo |/# The morning is upon us ||+
/substr start=4 end=-1 {{var::x}} | /echo |/# morning is upon us ||+