(current_blocked)
| 421 | } |
| 422 | |
| 423 | async process(current_blocked) { |
| 424 | this.is_blocked = current_blocked; |
| 425 | |
| 426 | if (this.chunk_start == -1) { |
| 427 | this.queue.push(this.chunk); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | if (hasFlagged(this.chunk) || ChatPayload.isPatch(this.chunk) || (this.is_blocked && this.chunk.indexOf(DONE) !== -1)) { |
| 432 | while (this.chunk_start != -1 && !this.is_done) { |
| 433 | var chunk_end = this.chunk.indexOf("\n", this.chunk_start); |
| 434 | if (chunk_end == -1) |
| 435 | chunk_end = this.chunk.length - 1; |
| 436 | var chunk_text = this.chunk.substring(this.chunk_start + 5, chunk_end).trim(); |
| 437 | |
| 438 | if (chunk_text === DONE) { |
| 439 | this.is_done = true; |
| 440 | if (!temp_chat && this.handle_latest && this.is_blocked) { |
| 441 | console.log("[DEMOD] Blocked response finished, attempting to reload it from history."); |
| 442 | var latest = await redownloadLatest(); |
| 443 | if (latest !== null) { |
| 444 | this.payload.setMessage(latest); |
| 445 | this.queue.push(this.payload.getData()); |
| 446 | } |
| 447 | else { |
| 448 | this.payload.setText("DeMod: Request completed, but DeMod failed to access the history. Try refreshing the conversation instead."); |
| 449 | this.queue.push(this.payload.getData()); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | } |
| 454 | else { |
| 455 | var chunk_data = null; |
| 456 | try { |
| 457 | chunk_data = JSON.parse(chunk_text); |
| 458 | var conv_id = ChatPayload.getConversationId(chunk_data); |
| 459 | if (conv_id !== null) { |
| 460 | this.conversation_id = conv_id; |
| 461 | last_conv_id = conv_id; |
| 462 | } |
| 463 | } catch (e) {} |
| 464 | |
| 465 | if (chunk_data !== null) { |
| 466 | if (chunk_data.hasOwnProperty('moderation_response')) { |
| 467 | var has_flag = chunk_data.moderation_response.flagged === true; |
| 468 | var has_block = chunk_data.moderation_response.blocked === true; |
| 469 | if (has_flag || has_block) { |
| 470 | if (has_flag) { |
| 471 | if (this.mod_result !== ModerationResult.BLOCKED) |
| 472 | this.mod_result = ModerationResult.FLAGGED; |
| 473 | } |
| 474 | console.log("[DEMOD] Received chunk contains flagging/blocking properties, clearing"); |
| 475 | chunk_data.moderation_response.flagged = false; |
| 476 | chunk_data.moderation_response.blocked = false; |
| 477 | } |
| 478 | |
| 479 | if (has_block) { |
| 480 | console.log("[DEMOD] Message has been BLOCKED. Waiting for Chat to finalize the request..."); |
no test coverage detected