Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bot): Allow reactions by bots #10138

Merged
merged 1 commit into from
Aug 8, 2023
Merged

Conversation

nickvergessen
Copy link
Member

☑️ Resolves

🏁 Checklist

Comment on lines +133 to 137
$response = new DataResponse([], $e->getCode());
if ($e->getCode() === Http::STATUS_UNAUTHORIZED) {
$response->throttle(['action' => 'bot']);
}
return $response;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am looking for a way to avoid repetition here and keep the same logic in one place. Maybe a wrapper like this:

private function handleInvalidArgumentException(\InvalidArgumentException $e) {
	$response = new DataResponse([], $e->getCode());
	if ($e->getCode() === Http::STATUS_UNAUTHORIZED) {
		$response->throttle(['action' => 'bot']);
	}
	return $response;
}

Block from l. 130 to l. 138 is used several times. I wonder we could extract it in a method, but then we will have something like:

$bot = $this->loadBot($token, $message);
if ($bot instanceof DataResponse) {
	return $bot;
}

And I don't like it ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I don't like mixed return types, that's why I went for the throwing instead.

lib/Controller/BotController.php Show resolved Hide resolved
lib/Controller/BotController.php Show resolved Hide resolved
@nickvergessen nickvergessen merged commit 348111c into master Aug 8, 2023
24 checks passed
@nickvergessen nickvergessen deleted the feat/10094/bot-reactions branch August 8, 2023 14:41
@nickvergessen nickvergessen mentioned this pull request Aug 7, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants