Alias /note-pos command to match /inject

This commit is contained in:
Cohee 2024-11-23 15:34:08 +02:00
parent 3af5302714
commit c5bd43405c
1 changed files with 26 additions and 18 deletions

View File

@ -76,15 +76,17 @@ function setNoteIntervalCommand(_, text) {
function setNotePositionCommand(_, text) { function setNotePositionCommand(_, text) {
const validPositions = { const validPositions = {
'after': 0,
'scenario': 0, 'scenario': 0,
'chat': 1, 'chat': 1,
'before_scenario': 2 'before_scenario': 2,
'before': 2,
}; };
if (text) { if (text) {
const position = validPositions[text?.trim()]; const position = validPositions[text?.trim()?.toLowerCase()];
if (typeof position == 'undefined') { if (typeof position === 'undefined') {
toastr.error(t`Not a valid position`); toastr.error(t`Not a valid position`);
return; return;
} }
@ -94,22 +96,23 @@ function setNotePositionCommand(_, text) {
} }
return Object.keys(validPositions).find(key => validPositions[key] == chat_metadata[metadata_keys.position]); return Object.keys(validPositions).find(key => validPositions[key] == chat_metadata[metadata_keys.position]);
} }
function setNoteRoleCommand(_, text) { function setNoteRoleCommand(_, text) {
const validRoles = { const validRoles = {
'system': 0, 'system': 0,
'user': 1, 'user': 1,
'assistant': 2 'assistant': 2,
}; };
if (text) { if (text) {
const role = validRoles[text?.trim()]; const role = validRoles[text?.trim()?.toLowerCase()];
if (typeof role == 'undefined') { if (typeof role === 'undefined') {
toastr.error(t`Not a valid role`); toastr.error(t`Not a valid role`);
return; return;
} }
$(`#extension_floating_role`).val(Math.abs(role)).trigger('input'); $('#extension_floating_role').val(Math.abs(role)).trigger('input');
toastr.info(t`Author's Note role updated`); toastr.info(t`Author's Note role updated`);
} }
return Object.keys(validRoles).find(key => validRoles[key] == chat_metadata[metadata_keys.role]); return Object.keys(validRoles).find(key => validRoles[key] == chat_metadata[metadata_keys.role]);
@ -491,7 +494,8 @@ export function initAuthorsNote() {
}); });
$('#option_toggle_AN').on('click', onANMenuItemClick); $('#option_toggle_AN').on('click', onANMenuItemClick);
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note', SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'note',
callback: setNoteTextCommand, callback: setNoteTextCommand,
returns: 'current author\'s note', returns: 'current author\'s note',
unnamedArgumentList: [ unnamedArgumentList: [
@ -505,8 +509,9 @@ export function initAuthorsNote() {
</div> </div>
`, `,
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'depth', SlashCommandParser.addCommandObject(SlashCommand.fromProps({
aliases: ['note-depth'], name: 'note-depth',
aliases: ['depth'],
callback: setNoteDepthCommand, callback: setNoteDepthCommand,
returns: 'current author\'s note depth', returns: 'current author\'s note depth',
unnamedArgumentList: [ unnamedArgumentList: [
@ -520,8 +525,9 @@ export function initAuthorsNote() {
</div> </div>
`, `,
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'freq', SlashCommandParser.addCommandObject(SlashCommand.fromProps({
aliases: ['note-freq'], name: 'note-frequency',
aliases: ['freq', 'note-freq'],
callback: setNoteIntervalCommand, callback: setNoteIntervalCommand,
returns: 'current author\'s note insertion frequency', returns: 'current author\'s note insertion frequency',
namedArgumentList: [], namedArgumentList: [],
@ -536,14 +542,15 @@ export function initAuthorsNote() {
</div> </div>
`, `,
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'pos', SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'note-position',
callback: setNotePositionCommand, callback: setNotePositionCommand,
aliases: ['note-pos'], aliases: ['pos', 'note-pos'],
returns: 'current author\'s note insertion position', returns: 'current author\'s note insertion position',
namedArgumentList: [], namedArgumentList: [],
unnamedArgumentList: [ unnamedArgumentList: [
new SlashCommandArgument( new SlashCommandArgument(
'position', [ARGUMENT_TYPE.STRING], false, false, null, ['chat', 'scenario','before_scenario'], 'position', [ARGUMENT_TYPE.STRING], false, false, null, ['before', 'after', 'chat'],
), ),
], ],
helpString: ` helpString: `
@ -552,13 +559,14 @@ export function initAuthorsNote() {
</div> </div>
`, `,
})); }));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'note-role', SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'note-role',
callback: setNoteRoleCommand, callback: setNoteRoleCommand,
returns: 'current author\'s note chat insertion role', returns: 'current author\'s note chat insertion role',
namedArgumentList: [], namedArgumentList: [],
unnamedArgumentList: [ unnamedArgumentList: [
new SlashCommandArgument( new SlashCommandArgument(
'position', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'user','assistant'], 'position', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'user', 'assistant'],
), ),
], ],
helpString: ` helpString: `