63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
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
|