From 4f6127c8f22e92e79abd4c7f1c0a5e0234cde32a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 2 Apr 2024 01:16:25 +0300 Subject: [PATCH] Actually support comma-split syntax in random --- public/scripts/macros.js | 5 ++++- public/scripts/templates/macros.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/public/scripts/macros.js b/public/scripts/macros.js index a8d178604..cd40f0245 100644 --- a/public/scripts/macros.js +++ b/public/scripts/macros.js @@ -190,7 +190,10 @@ function randomReplace(input, emptyListPlaceholder = '') { input = input.replace(randomPatternNew, (match, listString) => { //split on double colons instead of commas to allow for commas inside random items - const list = listString.split('::').filter(item => item.length > 0); + const list = listString.includes('::') + ? listString.split('::').filter(item => item.length > 0) + : listString.split(',').map(item => item.trim()).filter(item => item.length > 0); + if (list.length === 0) { return emptyListPlaceholder; } diff --git a/public/scripts/templates/macros.html b/public/scripts/templates/macros.html index 1c27718cc..5ba45c9f9 100644 --- a/public/scripts/templates/macros.html +++ b/public/scripts/templates/macros.html @@ -34,7 +34,7 @@
  • {{idle_duration}} – the time since the last user message was sent
  • {{bias "text here"}} – sets a behavioral bias for the AI until the next user input. Quotes around the text are important.
  • {{roll:(formula)}} – rolls a dice. (ex: >{{roll:1d6}} will roll a 6-sided dice and return a number between 1 and 6)
  • -
  • {{random::(args)}} – returns a random item from the list. (ex: {{random::1,2,3,4}} will return 1 of the 4 numbers at random. Works with text lists too.
  • +
  • {{random::(args)}} – returns a random item from the list. (ex: {{random::1::2::3::4}} will return 1 of the 4 numbers at random. Works with text lists too.
  • {{random::(arg1)::(arg2)}} – alternative syntax for random that allows to use commas in the list items.
  • {{pick::(args)}} – picks a random item from the list. Works the same as {{random}}, with the same possible syntax options, but the pick will stay consistent for this chat once picked and won't be re-rolled on consecutive messages and prompt processing.
  • {{banned "text here"}} – dynamically add text in the quotes to banned words sequences, if Text Generation WebUI backend used. Do nothing for others backends. Can be used anywhere (Character description, WI, AN, etc.) Quotes around the text are important.