Skip to content

Commit

Permalink
任务查找增加finalPrompt选项
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Jul 31, 2024
1 parent 8690831 commit d079475
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MessageHandler/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function handle($message): bool
$task = Discord::getRunningTaskByCondition((new TaskCondition())->prompt($finalPrompt)->params([Discord::INTERACTION_FAILURE => true]));
if (!$task) {
Log::debug("MessageHandler Success no task found messageHash=$messageHash messageId=$messageId nonce=$nonce and no InteractionFailure task found");
$task = Discord::getRunningTaskByCondition((new TaskCondition())->prompt($finalPrompt));
$task = Discord::getRunningTaskByCondition((new TaskCondition())->prompt($finalPrompt)) ?: Discord::getRunningTaskByCondition((new TaskCondition())->finalPrompt($finalPrompt));
if (!$task) {
Log::debug("MessageHandler Success no task found messageHash=$messageHash messageId=$messageId nonce=$nonce prompt=$finalPrompt and no task found");
return false;
Expand Down
21 changes: 20 additions & 1 deletion src/TaskCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TaskCondition

protected $prompt;

protected $finalPrompt;

protected $messageId;

protected $messageHash;
Expand Down Expand Up @@ -61,6 +63,16 @@ public function prompt($prompt): TaskCondition
return $this;
}

/**
* @param $prompt
* @return $this
*/
public function finalPrompt($prompt): TaskCondition
{
$this->finalPrompt = $prompt;
return $this;
}

/**
* @param $messageId
* @return $this
Expand Down Expand Up @@ -110,16 +122,23 @@ public function match(Task $task): bool
if ($this->prompt !== null && $this->prompt !== $task->prompt()) {
return false;
}
if ($this->finalPrompt !== null && $this->finalPrompt !== $task->finalPrompt()) {
return false;
}
if ($this->messageId !== null && $this->messageId !== $task->messageId()) {
return false;
}
if ($this->messageHash !== null && $this->messageHash !== $task->messageHash()) {
return false;
}
// 只查找prompt的任务时只查找messageHash为空的任务
// 只有prompt条件时只查找messageHash为空的任务
if ($this->prompt !== null && $this->nonce === null && $this->messageId === null && $this->messageHash === null && $task->messageHash()) {
return false;
}
// 只有finalPrompt条件时只查找messageHash为空的任务
if ($this->finalPrompt !== null && $this->nonce === null && $this->messageId === null && $this->messageHash === null && $task->messageHash()) {
return false;
}
$params = $task->params();
foreach ($this->params as $key => $value) {
if (!isset($params[$key]) || $params[$key] != $value) {
Expand Down

0 comments on commit d079475

Please sign in to comment.