Allow switching on /addswipe - Add optional "switch" arg to /addswipe - Make /addswipe return the new swipe id
| @@ -912,13 +912,28 @@ export function initDefaultSlashCommands() { | ||
| 912 | 912 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 913 | 913 | name: 'addswipe', |
| 914 | 914 | callback: addSwipeCallback, |
| 915 | + returns: 'the new swipe id', | |
| 915 | 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 | 925 | unnamedArgumentList: [ |
| 917 | 926 | new SlashCommandArgument( |
| 918 | 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 | 938 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 924 | 939 | name: 'stop', |
| @@ -2154,8 +2169,11 @@ async function echoCallback(args, value) { | ||
| 2154 | 2169 | } |
| 2155 | 2170 | } |
| 2156 | 2171 | |
| 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) { | |
| 2159 | 2177 | const lastMessage = chat[chat.length - 1]; |
| 2160 | 2178 | |
| 2161 | 2179 | if (!lastMessage) { |
| @@ -2163,7 +2181,7 @@ async function addSwipeCallback(_, arg) { | ||
| 2163 | 2181 | return ''; |
| 2164 | 2182 | } |
| 2165 | 2183 | |
| 2166 | 2184 | if (!argvalue) { |
| 2167 | 2185 | console.warn('WARN: No argument provided for /addswipe command'); |
| 2168 | 2186 | return ''; |
| 2169 | 2187 | } |
| @@ -2192,23 +2210,30 @@ async function addSwipeCallback(_, arg) { | ||
| 2192 | 2210 | lastMessage.swipe_info = lastMessage.swipes.map(() => ({})); |
| 2193 | 2211 | } |
| 2194 | 2212 | |
| 2195 | 2213 | lastMessage.swipes.push(argvalue); |
| 2196 | 2214 | lastMessage.swipe_info.push({ |
| 2197 | 2215 | send_date: getMessageTimeStamp(), |
| 2198 | 2216 | gen_started: null, |
| 2199 | 2217 | gen_finished: null, |
| 2200 | 2218 | extra: { |
| 2201 | 2219 | bias: extractMessageBias(argvalue), |
| 2202 | 2220 | gen_id: Date.now(), |
| 2203 | 2221 | api: 'manual', |
| 2204 | 2222 | model: 'slash command', |
| 2205 | 2223 | }, |
| 2206 | 2224 | }); |
| 2207 | 2225 | |
| 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 | 2233 | await saveChatConditional(); |
| 2209 | 2234 | await reloadCurrentChat(); |
| 2210 | 2235 | |
| 2211 | 2236 | return ''String(newSwipeId); |
| 2212 | 2237 | } |
| 2213 | 2238 | |
| 2214 | 2239 | async function deleteSwipeCallback(_, arg) { |