| 984 | 984 | /** |
| 985 | 985 | * Activates a group member based on the last message. |
| 986 | 986 | * @param {string[]} members Array of group member avatar ids |
| 987 | + * @param {Object} [options] Options object |
| 988 | + * @param {boolean} [options.allowSystem] Whether to allow system messages |
| 987 | 989 | * @returns {number[]} Array of character ids |
| 988 | 990 | */ |
| 989 | 991 | function activateSwipe(members, { allowSystem = false } = {}) { |
| 990 | 992 | let activatedNames = []; |
| 991 | 993 | const lastMessage = chat[chat.length - 1]; |
| 992 | 994 | |
| 993 | | - if (lastMessage.is_user || lastMessage.is_system || lastMessage.extra?.type === system_message_types.NARRATOR) { |
| 995 | + if (!lastMessage) { |
| 996 | + return []; |
| 997 | + } |
| 998 | + |
| 999 | + if (lastMessage.is_user || (!allowSystem && lastMessage.is_system) || lastMessage.extra?.type === system_message_types.NARRATOR) { |
| 994 | 1000 | for (const message of chat.slice().reverse()) { |
| 995 | 1001 | if (message.is_user || (!allowSystem && message.is_system) || message.extra?.type === system_message_types.NARRATOR) { |
| 996 | 1002 | continue; |
| 997 | 1003 | } |
| 998 | 1004 | |