add 'full' parameter to findGroupMemberId
| @@ -292,10 +292,11 @@ export function getGroupNames() { | ||
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | 294 | * Finds the character ID for a group member. |
| 295 | 295 | * @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 | |
| 297 | 298 | */ |
| 298 | 299 | export function findGroupMemberId(arg, full) { |
| 299 | 300 | arg = arg?.trim(); |
| 300 | 301 | |
| 301 | 302 | if (!arg) { |
| @@ -311,15 +312,19 @@ export function findGroupMemberId(arg) { | ||
| 311 | 312 | } |
| 312 | 313 | |
| 313 | 314 | const index = parseInt(arg); |
| 314 | 315 | const searchByNamesearchByString = isNaN(index); |
| 315 | 316 | |
| 316 | 317 | 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'] }); | |
| 319 | 324 | const result = fuse.search(arg); |
| 320 | 325 | |
| 321 | 326 | if (!result.length) { |
| 322 | 327 | console.warn(`WARN: No group member found withusing namestring ${arg}`); |
| 323 | 328 | return; |
| 324 | 329 | } |
| 325 | 330 | |
| @@ -330,9 +335,11 @@ export function findGroupMemberId(arg) { | ||
| 330 | 335 | return; |
| 331 | 336 | } |
| 332 | 337 | |
| 333 | 338 | 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 { | |
| 336 | 343 | const memberAvatar = group.members[index]; |
| 337 | 344 | |
| 338 | 345 | if (memberAvatar === undefined) { |
| @@ -347,8 +354,14 @@ export function findGroupMemberId(arg) { | ||
| 347 | 354 | return; |
| 348 | 355 | } |
| 349 | 356 | |
| 350 | 357 | 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 | + }; | |
| 352 | 365 | } |
| 353 | 366 | } |
| 354 | 367 | |