mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add enum providers for /theme and /movingui commands
This commit is contained in:
		| @@ -46,6 +46,7 @@ import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandPa | |||||||
| import { SlashCommand } from './slash-commands/SlashCommand.js'; | import { SlashCommand } from './slash-commands/SlashCommand.js'; | ||||||
| import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; | import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; | ||||||
| import { AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js'; | import { AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js'; | ||||||
|  | import { SlashCommandEnumValue } from './slash-commands/SlashCommandEnumValue.js'; | ||||||
|  |  | ||||||
| export { | export { | ||||||
|     loadPowerUserSettings, |     loadPowerUserSettings, | ||||||
| @@ -975,6 +976,7 @@ function switchUiMode() { | |||||||
|  |  | ||||||
| function toggleWaifu() { | function toggleWaifu() { | ||||||
|     $('#waifuMode').trigger('click'); |     $('#waifuMode').trigger('click'); | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| function switchWaifuMode() { | function switchWaifuMode() { | ||||||
| @@ -2483,14 +2485,12 @@ async function resetMovablePanels(type) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function doNewChat() { | async function doNewChat() { | ||||||
|     setTimeout(() => { |  | ||||||
|     $('#option_start_new_chat').trigger('click'); |     $('#option_start_new_chat').trigger('click'); | ||||||
|     }, 1); |     await delay(1); | ||||||
|     //$("#dialogue_popup").hide(); |  | ||||||
|     setTimeout(() => { |  | ||||||
|     $('#dialogue_popup_ok').trigger('click'); |     $('#dialogue_popup_ok').trigger('click'); | ||||||
|     }, 1); |     await delay(1); | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -2627,17 +2627,15 @@ async function doMesCut(_, text) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function doDelMode(_, text) { | async function doDelMode(_, text) { | ||||||
|     //first enter delmode |  | ||||||
|     $('#option_delete_mes').trigger('click', { fromSlashCommand: true }); |  | ||||||
|  |  | ||||||
|     //reject invalid args |     //reject invalid args | ||||||
|     if (text && isNaN(text)) { |     if (text && isNaN(text)) { | ||||||
|         toastr.warning('Must enter a number or nothing.'); |         toastr.warning('Must enter a number or nothing.'); | ||||||
|         await delay(300); //unsure why 300 is neccessary here, but any shorter and it wont see the delmode UI |         return ''; | ||||||
|         $('#dialogue_del_mes_cancel').trigger('click'); |  | ||||||
|         return; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     //first enter delmode | ||||||
|  |     $('#option_delete_mes').trigger('click', { fromSlashCommand: true }); | ||||||
|  |  | ||||||
|     //parse valid args |     //parse valid args | ||||||
|     if (text) { |     if (text) { | ||||||
|         await delay(300); //same as above, need event signal for 'entered del mode' |         await delay(300); //same as above, need event signal for 'entered del mode' | ||||||
| @@ -2648,7 +2646,7 @@ async function doDelMode(_, text) { | |||||||
|  |  | ||||||
|         if (oldestMesIDToDel < 0) { |         if (oldestMesIDToDel < 0) { | ||||||
|             toastr.warning(`Cannot delete more than ${chat.length} messages.`); |             toastr.warning(`Cannot delete more than ${chat.length} messages.`); | ||||||
|             return; |             return ''; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         let oldestMesToDel = $('#chat').find(`.mes[mesid=${oldestMesIDToDel}]`); |         let oldestMesToDel = $('#chat').find(`.mes[mesid=${oldestMesIDToDel}]`); | ||||||
| @@ -2657,7 +2655,7 @@ async function doDelMode(_, text) { | |||||||
|             oldestMesToDel = await loadUntilMesId(oldestMesIDToDel); |             oldestMesToDel = await loadUntilMesId(oldestMesIDToDel); | ||||||
|  |  | ||||||
|             if (!oldestMesToDel || !oldestMesToDel.length) { |             if (!oldestMesToDel || !oldestMesToDel.length) { | ||||||
|                 return; |                 return ''; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -2670,12 +2668,15 @@ async function doDelMode(_, text) { | |||||||
|         //await delay(1) |         //await delay(1) | ||||||
|         $('#dialogue_del_mes_ok').trigger('click'); |         $('#dialogue_del_mes_ok').trigger('click'); | ||||||
|         toastr.success(`Deleted ${trueNumberOfDeletedMessage} messages.`); |         toastr.success(`Deleted ${trueNumberOfDeletedMessage} messages.`); | ||||||
|         return; |         return ''; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| function doResetPanels() { | function doResetPanels() { | ||||||
|     $('#movingUIreset').trigger('click'); |     $('#movingUIreset').trigger('click'); | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| function setAvgBG() { | function setAvgBG() { | ||||||
| @@ -2906,6 +2907,7 @@ async function setThemeCallback(_, text) { | |||||||
|     applyTheme(theme.name); |     applyTheme(theme.name); | ||||||
|     $('#themes').val(theme.name); |     $('#themes').val(theme.name); | ||||||
|     saveSettingsDebounced(); |     saveSettingsDebounced(); | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function setmovingUIPreset(_, text) { | async function setmovingUIPreset(_, text) { | ||||||
| @@ -2929,6 +2931,7 @@ async function setmovingUIPreset(_, text) { | |||||||
|     applyMovingUIPreset(preset.name); |     applyMovingUIPreset(preset.name); | ||||||
|     $('#movingUIPresets').val(preset.name); |     $('#movingUIPresets').val(preset.name); | ||||||
|     saveSettingsDebounced(); |     saveSettingsDebounced(); | ||||||
|  |     return ''; | ||||||
| } | } | ||||||
|  |  | ||||||
| const EPHEMERAL_STOPPING_STRINGS = []; | const EPHEMERAL_STOPPING_STRINGS = []; | ||||||
| @@ -3943,9 +3946,12 @@ $(document).ready(() => { | |||||||
|         name: 'theme', |         name: 'theme', | ||||||
|         callback: setThemeCallback, |         callback: setThemeCallback, | ||||||
|         unnamedArgumentList: [ |         unnamedArgumentList: [ | ||||||
|             new SlashCommandArgument( |             SlashCommandArgument.fromProps({ | ||||||
|                 'name', [ARGUMENT_TYPE.STRING], true, |                 description: 'name', | ||||||
|             ), |                 typeList: [ARGUMENT_TYPE.STRING], | ||||||
|  |                 isRequired: true, | ||||||
|  |                 enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)), | ||||||
|  |             }), | ||||||
|         ], |         ], | ||||||
|         helpString: 'sets a UI theme by name', |         helpString: 'sets a UI theme by name', | ||||||
|     })); |     })); | ||||||
| @@ -3953,9 +3959,12 @@ $(document).ready(() => { | |||||||
|         name: 'movingui', |         name: 'movingui', | ||||||
|         callback: setmovingUIPreset, |         callback: setmovingUIPreset, | ||||||
|         unnamedArgumentList: [ |         unnamedArgumentList: [ | ||||||
|             new SlashCommandArgument( |             SlashCommandArgument.fromProps({ | ||||||
|                 'name', [ARGUMENT_TYPE.STRING], true, |                 description: 'name', | ||||||
|             ), |                 typeList: [ARGUMENT_TYPE.STRING], | ||||||
|  |                 isRequired: true, | ||||||
|  |                 enumProvider: () => movingUIPresets.map(preset => new SlashCommandEnumValue(preset.name)), | ||||||
|  |             }), | ||||||
|         ], |         ], | ||||||
|         helpString: 'activates a movingUI preset by name', |         helpString: 'activates a movingUI preset by name', | ||||||
|     })); |     })); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user