Allow switching on /addswipe - Add optional "switch" arg to /addswipe - Make /addswipe return the new swipe id

2ce58bb0a6f1b7504db5bcce113071248496eb69

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +32 -7Showing whitespace changes
public/scripts/slash-commands.js+32 -7
@@ -912,13 +912,28 @@ export function initDefaultSlashCommands() {
912912 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
913913 name: 'addswipe',
914914 callback: addSwipeCallback,
915+ returns: 'the new swipe id',
915916 aliases: ['swipeadd'],
917+ namedArgumentList: [
918+ SlashCommandNamedArgument.fromProps({
919+ name: 'switch',
920+ description: 'switch to the new swipe',
921+ typeList: [ARGUMENT_TYPE.BOOLEAN],
922+ enumList: commonEnumProviders.boolean()(),
923+ }),
924+ ],
916925 unnamedArgumentList: [
917926 new SlashCommandArgument(
918927 'text', [ARGUMENT_TYPE.STRING], true,
919928 ),
920929 ],
921- helpString: 'Adds a swipe to the last chat message.',
930+ helpString: `
931+ <div>
932+ Adds a swipe to the last chat message.
933+ </div>
934+ <div>
935+ Use switch=true to switch to directly switch to the new swipe.
936+ </div>`,
922937 }));
923938 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
924939 name: 'stop',
@@ -2154,8 +2169,11 @@ async function echoCallback(args, value) {
21542169 }
21552170}
21562171
2157-
2172+/**
2158-async function addSwipeCallback(_, arg) {
2173+ * @param {{switch?: string}} args - named arguments
2174+ * @param {string} value - The swipe text to add (unnamed argument)
2175+ */
2176+async function addSwipeCallback(args, value) {
21592177 const lastMessage = chat[chat.length - 1];
21602178
21612179 if (!lastMessage) {
@@ -2163,7 +2181,7 @@ async function addSwipeCallback(_, arg) {
21632181 return '';
21642182 }
21652183
21662184 if (!argvalue) {
21672185 console.warn('WARN: No argument provided for /addswipe command');
21682186 return '';
21692187 }
@@ -2192,23 +2210,30 @@ async function addSwipeCallback(_, arg) {
21922210 lastMessage.swipe_info = lastMessage.swipes.map(() => ({}));
21932211 }
21942212
21952213 lastMessage.swipes.push(argvalue);
21962214 lastMessage.swipe_info.push({
21972215 send_date: getMessageTimeStamp(),
21982216 gen_started: null,
21992217 gen_finished: null,
22002218 extra: {
22012219 bias: extractMessageBias(argvalue),
22022220 gen_id: Date.now(),
22032221 api: 'manual',
22042222 model: 'slash command',
22052223 },
22062224 });
22072225
2226+ const newSwipeId = lastMessage.swipes.length - 1;
2227+
2228+ if (isTrueBoolean(args.switch)) {
2229+ lastMessage.swipe_id = newSwipeId;
2230+ lastMessage.mes = lastMessage.swipes[newSwipeId];
2231+ }
2232+
22082233 await saveChatConditional();
22092234 await reloadCurrentChat();
22102235
22112236 return ''String(newSwipeId);
22122237}
22132238
22142239async function deleteSwipeCallback(_, arg) {