From e75f5550e31cedafed8f2d9aeace1ff284f51a89 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Fri, 5 Apr 2024 22:33:16 +0300
Subject: [PATCH] Add /classify command
---
.../scripts/extensions/expressions/index.js | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js
index 9ed19a71f..f6beb9375 100644
--- a/public/scripts/extensions/expressions/index.js
+++ b/public/scripts/extensions/expressions/index.js
@@ -885,6 +885,22 @@ async function setSpriteSetCommand(_, folder) {
moduleWorker();
}
+async function classifyCommand(_, text) {
+ if (!text) {
+ console.log('No text provided');
+ return '';
+ }
+
+ if (!modules.includes('classify') && !extension_settings.expressions.local) {
+ toastr.warning('Text classification is disabled or not available');
+ return '';
+ }
+
+ const label = getExpressionLabel(text);
+ console.debug(`Classification result for "${text}": ${label}`);
+ return label;
+}
+
async function setSpriteSlashCommand(_, spriteId) {
if (!spriteId) {
console.log('No sprite id provided');
@@ -1758,5 +1774,6 @@ async function fetchImagesNoCache() {
registerSlashCommand('sprite', setSpriteSlashCommand, ['emote'], '(spriteId) – force sets the sprite for the current character', true, true);
registerSlashCommand('spriteoverride', setSpriteSetCommand, ['costume'], '(optional folder) – sets an override sprite folder for the current character. If the name starts with a slash or a backslash, selects a sub-folder in the character-named folder. Empty value to reset to default.', true, true);
registerSlashCommand('lastsprite', (_, value) => lastExpression[value.trim()] ?? '', [], '(charName) – Returns the last set sprite / expression for the named character.', true, true);
- registerSlashCommand('th', toggleTalkingHeadCommand, ['talkinghead'], '– Character Expressions: toggles Image Type - talkinghead (extras) on/off.');
+ registerSlashCommand('th', toggleTalkingHeadCommand, ['talkinghead'], '– Character Expressions: toggles Image Type - talkinghead (extras) on/off.', true, true);
+ registerSlashCommand('classify', classifyCommand, [], '(text) – classifies the text and returns a label.', true, true);
})();