Merge pull request #2629 from SillyTavern/improve-swipe-commands
Improve `/addswipe` and `/delswipe` slightly
This commit is contained in:
commit
478e1a6bb5
|
@ -717,6 +717,7 @@ export function initDefaultSlashCommands() {
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'delswipe',
|
name: 'delswipe',
|
||||||
callback: deleteSwipeCallback,
|
callback: deleteSwipeCallback,
|
||||||
|
returns: 'the new, currently selected swipe id',
|
||||||
aliases: ['swipedel'],
|
aliases: ['swipedel'],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
|
@ -912,13 +913,28 @@ export function initDefaultSlashCommands() {
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'addswipe',
|
name: 'addswipe',
|
||||||
callback: addSwipeCallback,
|
callback: addSwipeCallback,
|
||||||
|
returns: 'the new swipe id',
|
||||||
aliases: ['swipeadd'],
|
aliases: ['swipeadd'],
|
||||||
|
namedArgumentList: [
|
||||||
|
SlashCommandNamedArgument.fromProps({
|
||||||
|
name: 'switch',
|
||||||
|
description: 'switch to the new swipe',
|
||||||
|
typeList: [ARGUMENT_TYPE.BOOLEAN],
|
||||||
|
enumList: commonEnumProviders.boolean()(),
|
||||||
|
}),
|
||||||
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
'text', [ARGUMENT_TYPE.STRING], true,
|
'text', [ARGUMENT_TYPE.STRING], true,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
helpString: 'Adds a swipe to the last chat message.',
|
helpString: `
|
||||||
|
<div>
|
||||||
|
Adds a swipe to the last chat message.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
Use switch=true to switch to directly switch to the new swipe.
|
||||||
|
</div>`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'stop',
|
name: 'stop',
|
||||||
|
@ -2154,8 +2170,11 @@ async function echoCallback(args, value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
async function addSwipeCallback(_, arg) {
|
* @param {{switch?: string}} args - named arguments
|
||||||
|
* @param {string} value - The swipe text to add (unnamed argument)
|
||||||
|
*/
|
||||||
|
async function addSwipeCallback(args, value) {
|
||||||
const lastMessage = chat[chat.length - 1];
|
const lastMessage = chat[chat.length - 1];
|
||||||
|
|
||||||
if (!lastMessage) {
|
if (!lastMessage) {
|
||||||
|
@ -2163,7 +2182,7 @@ async function addSwipeCallback(_, arg) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arg) {
|
if (!value) {
|
||||||
console.warn('WARN: No argument provided for /addswipe command');
|
console.warn('WARN: No argument provided for /addswipe command');
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -2192,23 +2211,30 @@ async function addSwipeCallback(_, arg) {
|
||||||
lastMessage.swipe_info = lastMessage.swipes.map(() => ({}));
|
lastMessage.swipe_info = lastMessage.swipes.map(() => ({}));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMessage.swipes.push(arg);
|
lastMessage.swipes.push(value);
|
||||||
lastMessage.swipe_info.push({
|
lastMessage.swipe_info.push({
|
||||||
send_date: getMessageTimeStamp(),
|
send_date: getMessageTimeStamp(),
|
||||||
gen_started: null,
|
gen_started: null,
|
||||||
gen_finished: null,
|
gen_finished: null,
|
||||||
extra: {
|
extra: {
|
||||||
bias: extractMessageBias(arg),
|
bias: extractMessageBias(value),
|
||||||
gen_id: Date.now(),
|
gen_id: Date.now(),
|
||||||
api: 'manual',
|
api: 'manual',
|
||||||
model: 'slash command',
|
model: 'slash command',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const newSwipeId = lastMessage.swipes.length - 1;
|
||||||
|
|
||||||
|
if (isTrueBoolean(args.switch)) {
|
||||||
|
lastMessage.swipe_id = newSwipeId;
|
||||||
|
lastMessage.mes = lastMessage.swipes[newSwipeId];
|
||||||
|
}
|
||||||
|
|
||||||
await saveChatConditional();
|
await saveChatConditional();
|
||||||
await reloadCurrentChat();
|
await reloadCurrentChat();
|
||||||
|
|
||||||
return '';
|
return String(newSwipeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSwipeCallback(_, arg) {
|
async function deleteSwipeCallback(_, arg) {
|
||||||
|
@ -2244,7 +2270,7 @@ async function deleteSwipeCallback(_, arg) {
|
||||||
await saveChatConditional();
|
await saveChatConditional();
|
||||||
await reloadCurrentChat();
|
await reloadCurrentChat();
|
||||||
|
|
||||||
return '';
|
return String(newSwipeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function askCharacter(args, text) {
|
async function askCharacter(args, text) {
|
||||||
|
|
Loading…
Reference in New Issue