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 -7Ignore whitespace
public/scripts/slash-commands.js+32 -7
@@ -912,13 +912,28 @@ export function initDefaultSlashCommands() {
912 SlashCommandParser.addCommandObject(SlashCommand.fromProps({912 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
913 name: 'addswipe',913 name: 'addswipe',
914 callback: addSwipeCallback,914 callback: addSwipeCallback,
915 returns: 'the new swipe id',
915 aliases: ['swipeadd'],916 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 ],
916 unnamedArgumentList: [925 unnamedArgumentList: [
917 new SlashCommandArgument(926 new SlashCommandArgument(
918 'text', [ARGUMENT_TYPE.STRING], true,927 'text', [ARGUMENT_TYPE.STRING], true,
919 ),928 ),
920 ],929 ],
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>`,
922 }));937 }));
923 SlashCommandParser.addCommandObject(SlashCommand.fromProps({938 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
924 name: 'stop',939 name: 'stop',
@@ -2154,8 +2169,11 @@ async function echoCallback(args, value) {
2154 }2169 }
2155}2170}
21562171
21572172/**
2158async function addSwipeCallback(_, arg) {2173 * @param {{switch?: string}} args - named arguments
2174 * @param {string} value - The swipe text to add (unnamed argument)
2175 */
2176async function addSwipeCallback(args, value) {
2159 const lastMessage = chat[chat.length - 1];2177 const lastMessage = chat[chat.length - 1];
21602178
2161 if (!lastMessage) {2179 if (!lastMessage) {
@@ -2163,7 +2181,7 @@ async function addSwipeCallback(_, arg) {
2163 return '';2181 return '';
2164 }2182 }
21652183
2166 if (!arg) {2184 if (!value) {
2167 console.warn('WARN: No argument provided for /addswipe command');2185 console.warn('WARN: No argument provided for /addswipe command');
2168 return '';2186 return '';
2169 }2187 }
@@ -2192,23 +2210,30 @@ async function addSwipeCallback(_, arg) {
2192 lastMessage.swipe_info = lastMessage.swipes.map(() => ({}));2210 lastMessage.swipe_info = lastMessage.swipes.map(() => ({}));
2193 }2211 }
21942212
2195 lastMessage.swipes.push(arg);2213 lastMessage.swipes.push(value);
2196 lastMessage.swipe_info.push({2214 lastMessage.swipe_info.push({
2197 send_date: getMessageTimeStamp(),2215 send_date: getMessageTimeStamp(),
2198 gen_started: null,2216 gen_started: null,
2199 gen_finished: null,2217 gen_finished: null,
2200 extra: {2218 extra: {
2201 bias: extractMessageBias(arg),2219 bias: extractMessageBias(value),
2202 gen_id: Date.now(),2220 gen_id: Date.now(),
2203 api: 'manual',2221 api: 'manual',
2204 model: 'slash command',2222 model: 'slash command',
2205 },2223 },
2206 });2224 });
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
2208 await saveChatConditional();2233 await saveChatConditional();
2209 await reloadCurrentChat();2234 await reloadCurrentChat();
22102235
2211 return '';2236 return String(newSwipeId);
2212}2237}
22132238
2214async function deleteSwipeCallback(_, arg) {2239async function deleteSwipeCallback(_, arg) {