mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
add 'full' parameter to findGroupMemberId
This commit is contained in:
@@ -292,10 +292,11 @@ export function getGroupNames() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the character ID for a group member.
|
* Finds the character ID for a group member.
|
||||||
* @param {string} arg 0-based member index or character name
|
* @param {number|string} arg 0-based member index or character name
|
||||||
* @returns {number} 0-based character ID
|
* @param {Boolean} full Whether to return a key-value object containing extra data
|
||||||
|
* @returns {number|Object} 0-based character ID or key-value object if full is true
|
||||||
*/
|
*/
|
||||||
export function findGroupMemberId(arg) {
|
export function findGroupMemberId(arg, full) {
|
||||||
arg = arg?.trim();
|
arg = arg?.trim();
|
||||||
|
|
||||||
if (!arg) {
|
if (!arg) {
|
||||||
@@ -311,15 +312,19 @@ export function findGroupMemberId(arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const index = parseInt(arg);
|
const index = parseInt(arg);
|
||||||
const searchByName = isNaN(index);
|
const searchByString = isNaN(index);
|
||||||
|
|
||||||
if (searchByName) {
|
if (searchByString) {
|
||||||
const memberNames = group.members.map(x => ({ name: characters.find(y => y.avatar === x)?.name, index: characters.findIndex(y => y.avatar === x) }));
|
const memberNames = group.members.map(x => ({
|
||||||
const fuse = new Fuse(memberNames, { keys: ['name'] });
|
avatar: x,
|
||||||
|
name: characters.find(y => y.avatar === x)?.name,
|
||||||
|
index: characters.findIndex(y => y.avatar === x),
|
||||||
|
}));
|
||||||
|
const fuse = new Fuse(memberNames, { keys: ['avatar', 'name'] });
|
||||||
const result = fuse.search(arg);
|
const result = fuse.search(arg);
|
||||||
|
|
||||||
if (!result.length) {
|
if (!result.length) {
|
||||||
console.warn(`WARN: No group member found with name ${arg}`);
|
console.warn(`WARN: No group member found using string ${arg}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,9 +335,11 @@ export function findGroupMemberId(arg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Triggering group member ${chid} (${arg}) from search result`, result[0]);
|
console.log(`Targeting group member ${chid} (${arg}) from search result`, result[0]);
|
||||||
return chid;
|
|
||||||
} else {
|
return !full ? chid : { ...{ id: chid }, ...result[0].item };
|
||||||
|
}
|
||||||
|
else {
|
||||||
const memberAvatar = group.members[index];
|
const memberAvatar = group.members[index];
|
||||||
|
|
||||||
if (memberAvatar === undefined) {
|
if (memberAvatar === undefined) {
|
||||||
@@ -347,8 +354,14 @@ export function findGroupMemberId(arg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Triggering group member ${memberAvatar} at index ${index}`);
|
console.log(`Targeting group member ${memberAvatar} at index ${index}`);
|
||||||
return chid;
|
|
||||||
|
return !full ? chid : {
|
||||||
|
id: chid,
|
||||||
|
avatar: memberAvatar,
|
||||||
|
name: characters.find(y => y.avatar === memberAvatar)?.name,
|
||||||
|
index: index,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user