<commit_before><?php
/*
 * CodeMOOC QuizzleBot
 * ===================
 * UWiClab, University of Urbino
 * ===================
 * Class wrapping the bot's context in this run.
 */

require_once('lib.php');

require_once('incoming_message.php');

class Context {

    private $message;

    /**
     * Construct Context class.
     * @param §message IncomingMessage.
     */
    function __construct($message) {
        if(!($message instanceof IncomingMessage))
            die('Message variable is not an IncomingMessage instance');

        $this->message = $message;
        $this->refresh();
    }

    /* True if the talking user is an admin */
    function is_abmin() {
        return $this->message->from_id === ADMIN_TELEGRAM_ID;
    }

    /**
     * Gets the user's Telegram ID.
     */
    function get_telegram_user_id() {
        return $this->message->from_id;
    }

    /**
     * Gets the user's chat ID.
     */
    function get_telegram_chat_id() {
        return $this->message->chat_id;
    }

    /**
     * Gets the raw message.
     */
    function get_message() {
        return $this->message;
    }

    /**
     * Gets a cleaned-up response from the user, if any.
     */
    function get_response() {
        $text = $this->message->text;
        if($text)
            return extract_response($text);
        else
            return '';
    }

    /**
     * Replies to the current incoming message.
     * Enables markdown parsing and disables web previews by default.
     */
    function reply($message, $additional_values = null) {
        $hydration_values = array(
            '%FIRST_NAME%' => $this->get_message()->get_sender_first_name(),
            '%FULL_NAME%' => $this->get_message()->get_sender_full_name(),
            '%GROUP_NAME%' => $this->get_group_name()
        );

        $hydrated = hydrate($message, unite_arrays($hydration_values, $additional_values));

        return telegram_send_message(
            $this->get_chat_id(),
            $hydrated,
            array(
                'parse_mode' => 'HTML',
                'disable_web_page_preview' => true
            )
        );
    }

    /**
     * Refreshes information about the context from the DB.
     */
    function refresh() {
        $identity = db_row_query("SELECT `id`, `full_name`, `is_admin` FROM `identities` WHERE `telegram_id` = {$this->get_user_id()}");
        if(!$identity) {
            //No identity registered
            return;
        }

        $this->group_id = intval($identity[0]);
        $this->is_admin = (bool)$identity[2];

        $state = db_row_query("SELECT `name`, `participants_count`, `state`, `track_id`, `track_index` FROM `status` WHERE `game_id` = " . CURRENT_GAME_ID . " AND `group_id` = {$this->group_id}");
        if(!$state) {
            //No registration
            return;
        }

        if($state[0]) {
            $this->group_name = $state[0];
        }
        else {
            $this->group_name = TEXT_UNNAMED_GROUP;
        }
        $this->group_state = intval($state[2]);
        if($state[3] !== null) {
            $this->group_track_id = intval($state[3]);
        }
        $this->group_track_index = intval($state[4]);
    }

}<commit_msg>Remove context loading<commit_after><?php
/*
 * CodeMOOC QuizzleBot
 * ===================
 * UWiClab, University of Urbino
 * ===================
 * Class wrapping the bot's context in this run.
 */

require_once('lib.php');

require_once('incoming_message.php');

class Context {

    private $message;

    /**
     * Construct Context class.
     * @param §message IncomingMessage.
     */
    function __construct($message) {
        if(!($message instanceof IncomingMessage))
            die('Message variable is not an IncomingMessage instance');

        $this->message = $message;
    }

    /* True if the talking user is an admin */
    function is_abmin() {
        return $this->message->from_id === ADMIN_TELEGRAM_ID;
    }

    /**
     * Gets the user's Telegram ID.
     */
    function get_telegram_user_id() {
        return $this->message->from_id;
    }

    /**
     * Gets the user's chat ID.
     */
    function get_telegram_chat_id() {
        return $this->message->chat_id;
    }

    /**
     * Gets the raw message.
     */
    function get_message() {
        return $this->message;
    }

    /**
     * Gets a cleaned-up response from the user, if any.
     */
    function get_response() {
        $text = $this->message->text;
        if($text)
            return extract_response($text);
        else
            return '';
    }

    /**
     * Replies to the current incoming message.
     * Enables markdown parsing and disables web previews by default.
     */
    function reply($message, $additional_values = null) {
        $hydration_values = array(
            '%FIRST_NAME%' => $this->get_message()->get_sender_first_name(),
            '%FULL_NAME%' => $this->get_message()->get_sender_full_name(),
            '%GROUP_NAME%' => $this->get_group_name()
        );

        $hydrated = hydrate($message, unite_arrays($hydration_values, $additional_values));

        return telegram_send_message(
            $this->get_chat_id(),
            $hydrated,
            array(
                'parse_mode' => 'HTML',
                'disable_web_page_preview' => true
            )
        );
    }

}
{'fraction_non_alphanumeric': 0.14711359404096835, 'fraction_numerical': 0.0014897579143389199, 'mean_word_length': 2.0956772334293947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '4081745', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1583, 'n_words': 341}