<commit_before><?php

namespace Botonomous\utility;

use Botonomous\CommandContainer;

/**
 * Class MessageUtility.
 */
class MessageUtility extends AbstractUtility
{
    /**
     * Remove the mentioned bot username from the message.
     *
     * @param $message
     *
     * @throws \Exception
     *
     * @return string
     */
    public function removeMentionedBot($message)
    {
        $botUserId = $this->getConfig()->get('botUserId');
        $userLink = $this->linkToUser($botUserId);

        return preg_replace("/{$userLink}/", '', $message, 1);
    }

    /**
     * Check if the bot user id is mentioned in the message.
     *
     * @param $message
     *
     * @throws \Exception
     *
     * @return bool
     */
    public function isBotMentioned($message)
    {
        $botUserId = $this->getConfig()->get('botUserId');
        $userLink = $this->linkToUser($botUserId);

        return (new StringUtility())->findInString($userLink, $message, false);
    }

    /**
     * Return command name in the message.
     *
     * @param $message
     *
     * @return null|string
     */
    public function extractCommandName($message)
    {
        // remove the bot mention if it exists
        $message = $this->removeMentionedBot($message);

        /**
         * Command must start with / and at the beginning of the sentence.
         */
        $commandPrefix = $this->getConfig()->get('commandPrefix');
        $commandPrefix = preg_quote($commandPrefix, '/');

        $pattern = '/^('.$commandPrefix.'\w{1,})/';

        preg_match($pattern, ltrim($message), $groups);

        // If command is found, remove command prefix from the beginning of the command
        return isset($groups[1]) ? ltrim($groups[1], $commandPrefix) : null;
    }

    /**
     * Return command details in the message.
     *
     * @param $message
     *
     * @return \Botonomous\Command
     */
    public function extractCommandDetails($message)
    {
        // first get the command name
        $command = $this->extractCommandName($message);

        // then get the command details
        return (new CommandContainer())->getAsObject($command);
    }

    /**
     * @param $triggerWord
     * @param $message
     *<commit_msg>Add doc<commit_after><?php

namespace Botonomous\utility;

use Botonomous\CommandContainer;

/**
 * Class MessageUtility.
 */
class MessageUtility extends AbstractUtility
{
    /**
     * Remove the mentioned bot username from the message.
     *
     * @param $message
     *
     * @throws \Exception
     *
     * @return string
     */
    public function removeMentionedBot($message)
    {
        $botUserId = $this->getConfig()->get('botUserId');
        $userLink = $this->linkToUser($botUserId);

        return preg_replace("/{$userLink}/", '', $message, 1);
    }

    /**
     * Check if the bot user id is mentioned in the message.
     *
     * @param $message
     *
     * @throws \Exception
     *
     * @return bool
     */
    public function isBotMentioned($message)
    {
        $botUserId = $this->getConfig()->get('botUserId');
        $userLink = $this->linkToUser($botUserId);

        return (new StringUtility())->findInString($userLink, $message, false);
    }

    /**
     * Return command name in the message.
     *
     * @param $message
     *
     * @return null|string
     */
    public function extractCommandName($message)
    {
        // remove the bot mention if it exists
        $message = $this->removeMentionedBot($message);

        /**
         * Command must start with / and at the beginning of the sentence.
         */
        $commandPrefix = $this->getConfig()->get('commandPrefix');
        $commandPrefix = preg_quote($commandPrefix, '/');

        $pattern = '/^('.$commandPrefix.'\w{1,})/';

        preg_match($pattern, ltrim($message), $groups);

        // If command is found, remove command prefix from the beginning of the command
        return isset($groups[1]) ? ltrim($groups[1], $commandPrefix) : null;
    }

    /**
     * Return command details in the message.
     *
     * @param $message
     *
     * @return \Botonomous\Command|null
     */
    public function extractCommandDetails($message)
    {
        // first get the command name
        $command = $this->extractCommandName($message);

        // then get the command details
        return (new CommandContainer())->getAsObject($command);
    }

    /**
     * @param $triggerWord
     * @param $message
     *
{'fraction_non_alphanumeric': 0.13453413386702245, 'fraction_numerical': 0.00177896375361352, 'mean_word_length': 2.2641509433962264, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '4217106', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1259, 'n_words': 315}