import { replacePickPlaceholders } from '@/services/pick'
import { replaceRandomWordPlaceholders } from '@/services/randomWord'
import { replaceShufflePlaceholders } from '@/services/shuffle'
const replacers = [
replaceRandomWordPlaceholders,
replacePickPlaceholders,
replaceShufflePlaceholders
]
const helpString = `
Replace the placeholders in the provided text.
Example:
-
/replaceRandom I have a %%RandomWord:PetSpecies%% myself
-
/replaceRandom I looked for him in %%Shuffle::the infirmary::the classroom::the gym;; ,%%, and his room but I couldn't find him.
-
/replaceRandom I have a %%Pick::Red::Blue::Green%% hoodie.
`
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