diff --git a/extension.json b/extension.json index 42d1c72..eb44a72 100644 --- a/extension.json +++ b/extension.json @@ -17,6 +17,14 @@ "askai": true } }, + "RateLimits": { + "askai": { + "user": [ + 5, + 30 + ] + } + }, "AutoloadClasses": { "MediaWiki\\AskAI\\ApiQueryAskAI": "includes/api/ApiQueryAskAI.php", "MediaWiki\\AskAI\\Hooks": "includes/Hooks.php", diff --git a/includes/api/ApiQueryAskAI.php b/includes/api/ApiQueryAskAI.php index 6908949..e2f0124 100644 --- a/includes/api/ApiQueryAskAI.php +++ b/includes/api/ApiQueryAskAI.php @@ -31,12 +31,17 @@ use ApiQueryBase; use MediaWiki\AskAI\Service\ServiceFactory; use Status; +use ThrottledError; use Wikimedia\ParamValidator\ParamValidator; class ApiQueryAskAI extends ApiQueryBase { public function execute() { $this->checkUserRightsAny( 'askai' ); + if ( $this->getUser()->pingLimiter( 'askai' ) ) { + throw new ThrottledError; + } + $ai = ServiceFactory::getAI(); if ( !$ai ) { $this->dieStatus( Status::newFatal( 'askai-unknown-service' ) );