You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB
PHTML

2 years ago
<?php
namespace Isekai\AIToolbox;
2 years ago
use MediaWiki\MediaWikiServices;
class AIToolboxUtils {
2 years ago
public static function getPointCost(string $action = '', int $tokens, int $extractLimit) {
$pointConfig = MediaWikiServices::getInstance()->getMainConfig()->get('IsekaiAIToolboxUserPoints');
2 years ago
if (!is_array($pointConfig) && !isset($pointConfig[$action])) {
return false;
}
$pointConfig = $pointConfig[$action];
if (!isset($pointConfig['pointType'])) {
return false;
}
$cost = 0;
$pointType = $pointConfig['pointType'];
// Fixed cost
if (isset($pointConfig['fixedCost'])) {
$cost += $pointConfig['fixedCost'];
}
// Per token cost
if (isset($pointConfig['perTokenCost'])) {
if (isset($pointConfig['fixedTokens'])) {
$tokens = max(0, $tokens - $pointConfig['fixedTokens']);
}
$cost += $pointConfig['perTokenCost'] * $tokens;
}
// Per extract cost
if (isset($pointConfig['perExtractCost'])) {
$cost += $pointConfig['perExtractCost'] * $extractLimit;
}
$cost = (int) ceil($cost);
return [$pointType, $cost];
}
}