Allow switching on /addswipe
- Add optional "switch" arg to /addswipe - Make /addswipe return the new swipe id
This commit is contained in:
parent
e17f0b368d
commit
2ce58bb0a6
|
@ -912,13 +912,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 +2169,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 +2181,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 +2210,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) {
|
||||||
|
|
Loading…
Reference in New Issue