<commit_before><?php declare(strict_types=1);

namespace Room11\Jeeves\Plugins;

use Amp\Promise;
use Room11\Jeeves\Chat\Client\ChatClient;
use Room11\Jeeves\Chat\Message\Command;
use Room11\Jeeves\System\PluginCommandEndpoint;

class Scrabble extends BasePlugin
{
    const SCORES = [
        'en' => [
            1 => 'EAIONRTLSU',
            2 => 'DG',
            3 => 'BCMP',
            4 => 'FHVWY',
            5 => 'K',
            8 => 'JX',
            10 => 'QZ'
        ]
    ];

    private $chatClient;

    public function __construct(ChatClient $chatClient)
    {
        $this->chatClient = $chatClient;
    }

    public function scrabble(Command $command): Promise
    {
        if (!$command->hasParameters()) {
            return new Success();
        }

        return $this->chatClient->postReply(
            $command, 
            $this->calculateScore(implode($command->getParameters()))
        );
    }

    public function getDescription(): string
    {
        return 'Calculates the Scrabble score for the given input';
    }

    private function calculateScore(string $input): string
    {
        $sum = 0;
        foreach ($input as $char) {
            if ($char !== '~') {
                $sum += key(preg_grep("~$char~i", SCORES['en']));
            }
        }
        return $sum;
    }

    /**
     * @return PluginCommandEndpoint[]
     */
    public function getCommandEndpoints(): array
    {
        return [new PluginCommandEndpoint('Scrabble', [$this, 'scrabble'], 'scrabble')];
    }
}<commit_msg>escaping chars in regex pattern<commit_after><?php declare(strict_types=1);

namespace Room11\Jeeves\Plugins;

use Amp\Promise;
use Room11\Jeeves\Chat\Client\ChatClient;
use Room11\Jeeves\Chat\Message\Command;
use Room11\Jeeves\System\PluginCommandEndpoint;

class Scrabble extends BasePlugin
{
    const SCORES = [
        'en' => [
            1 => 'EAIONRTLSU',
            2 => 'DG',
            3 => 'BCMP',
            4 => 'FHVWY',
            5 => 'K',
            8 => 'JX',
            10 => 'QZ'
        ]
    ];

    private $chatClient;

    public function __construct(ChatClient $chatClient)
    {
        $this->chatClient = $chatClient;
    }

    public function scrabble(Command $command): Promise
    {
        if (!$command->hasParameters()) {
            return new Success();
        }

        return $this->chatClient->postReply(
            $command, 
            $this->calculateScore(implode($command->getParameters()))
        );
    }

    public function getDescription(): string
    {
        return 'Calculates the Scrabble score for the given input';
    }

    private function calculateScore(string $input): string
    {
        $sum = 0;
        foreach ($input as $char) {
            $char = preg_quote($char);
            $sum += key(preg_grep("~$char~i", SCORES['en']));
        }
        return $sum;
    }

    /**
     * @return PluginCommandEndpoint[]
     */
    public function getCommandEndpoints(): array
    {
        return [new PluginCommandEndpoint('Scrabble', [$this, 'scrabble'], 'scrabble')];
    }
}
{'fraction_non_alphanumeric': 0.13554410817772053, 'fraction_numerical': 0.01159047005795235, 'mean_word_length': 2.0282651072124755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7427424', 'n_tokens_mistral': 959, 'n_tokens_neox': 922, 'n_words': 200}