feat: replaceRandom slash command

This commit is contained in:
2026-04-16 13:34:10 -06:00
parent e9736efa05
commit cd186e5a5d
7 changed files with 230 additions and 167 deletions
@@ -0,0 +1,62 @@
import { replacePickPlaceholders } from '@/services/pick'
import { replaceRandomWordPlaceholders } from '@/services/randomWord'
import { replaceShufflePlaceholders } from '@/services/shuffle'
const replacers = [
replaceRandomWordPlaceholders,
replacePickPlaceholders,
replaceShufflePlaceholders
]
const helpString = `<div>
<div>Replace the placeholders in the provided text.</div>
<div>
<strong>Example:</strong>
<ul>
<li>
<pre><code class="language-stscript">/replaceRandom I have a %%RandomWord:PetSpecies%% myself</code></pre>
</li>
<li>
<pre><code class="language-stscript">/replaceRandom I looked for him in %%Shuffle::the infirmary::the classroom::the gym;; ,%%, and his room but I couldn't find him.</code></pre>
</li>
<li>
<pre><code class="language-stscript">/replaceRandom I have a %%Pick::Red::Blue::Green%% hoodie.</code></pre>
</li>
</ul>
</div>
</div>`
const initializeSlashCommands = () => {
const { SlashCommandParser, SlashCommand, SlashCommandArgument } =
SillyTavern.getContext()
SlashCommandParser.addCommandObject(
SlashCommand.fromProps({
name: 'randomReplace',
aliases: ['replaceRandom'],
unnamedArgumentList: [
SlashCommandArgument.fromProps({
description: 'The text to replace in placeholder format.',
acceptsMultiple: false,
typeList: ['string'],
isRequired: true
})
],
returns: 'The text with the placeholders replaced.',
helpString,
callback: (_, unnamedArgument) => {
if (typeof unnamedArgument !== 'string') {
return ''
}
let text = unnamedArgument
for (const replacer of replacers) {
text = replacer(text)
}
return text
}
})
)
}
export default initializeSlashCommands