add 'full' parameter to findGroupMemberId

b8821acb953a045798dd9383e6ec056e92022026

Succubyss <87207237+Succubyss@users.noreply.github.com>

1 files changed, +27 -14Showing whitespace changes
public/scripts/group-chats.js+27 -14
@@ -292,10 +292,11 @@ export function getGroupNames() {
292292
293293/**
294294 * Finds the character ID for a group member.
295295 * @param {number|string} arg 0-based member index or character name
296- * @returns {number} 0-based character ID
296+ * @param {Boolean} full Whether to return a key-value object containing extra data
297+ * @returns {number|Object} 0-based character ID or key-value object if full is true
297298 */
298299export function findGroupMemberId(arg, full) {
299300 arg = arg?.trim();
300301
301302 if (!arg) {
@@ -311,15 +312,19 @@ export function findGroupMemberId(arg) {
311312 }
312313
313314 const index = parseInt(arg);
314315 const searchByNamesearchByString = isNaN(index);
315316
316317 if (searchByNamesearchByString) {
317- const memberNames = group.members.map(x => ({ name: characters.find(y => y.avatar === x)?.name, index: characters.findIndex(y => y.avatar === x) }));
318+ const memberNames = group.members.map(x => ({
318- const fuse = new Fuse(memberNames, { keys: ['name'] });
319+ avatar: x,
320+ name: characters.find(y => y.avatar === x)?.name,
321+ index: characters.findIndex(y => y.avatar === x),
322+ }));
323+ const fuse = new Fuse(memberNames, { keys: ['avatar', 'name'] });
319324 const result = fuse.search(arg);
320325
321326 if (!result.length) {
322327 console.warn(`WARN: No group member found withusing namestring ${arg}`);
323328 return;
324329 }
325330
@@ -330,9 +335,11 @@ export function findGroupMemberId(arg) {
330335 return;
331336 }
332337
333338 console.log(`TriggeringTargeting group member ${chid} (${arg}) from search result`, result[0]);
334- return chid;
339+
335- } else {
340+ return !full ? chid : { ...{ id: chid }, ...result[0].item };
341+ }
342+ else {
336343 const memberAvatar = group.members[index];
337344
338345 if (memberAvatar === undefined) {
@@ -347,8 +354,14 @@ export function findGroupMemberId(arg) {
347354 return;
348355 }
349356
350357 console.log(`TriggeringTargeting group member ${memberAvatar} at index ${index}`);
351- return chid;
358+
359+ return !full ? chid : {
360+ id: chid,
361+ avatar: memberAvatar,
362+ name: characters.find(y => y.avatar === memberAvatar)?.name,
363+ index: index,
364+ };
352365 }
353366}
354367