<commit_before><?php

namespace PWRTelegram\PWRTelegram;

/*
Copyright 2016 <NAME>
(https://daniil.it)

This file is part of the PWRTelegram API.
the PWRTelegram API is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The PWRTelegram API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the PWRTelegram API.
If not, see <http://www.gnu.org/licenses/>.
*/
class API extends Tools
{
    public function __construct($params)
    {
        foreach ($params as $key => $val) {
            $this->{$key} = $val;
        }
        $info = $this->get_me();
        ini_set('error_log', isset($info['result']['username']) ? $this->homedir.'/'.$info['result']['username'].'.log' : $this->homedir.'/php-error-index.log');
    }

    public function db_connect()
    {
        if (!isset($this->pdo)) {
            $this->pdo = new \PDO($this->deep ? $this->deepdb : $this->db, $this->deep ? $this->deepdbuser : $this->dbuser, $this->deep ? $this->deepdbpassword : $this->dbpassword);
            $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
            $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
        }
    }

    public function madeline_connect()
    {
        if (!isset($this->madeline)) {
            require_once $this->pwrhomedir.'/vendor/autoload.php';
            try {
                $this->madeline = \danog\MadelineProto\Serialization::deserialize($this->madeline_path);
                if (is_object($this->madeline)) return $this->madeline;
            } catch (\danog\MadelineProto\Exception $e) {
            } catch (\danog\MadelineProto\RPCErrorException $e) {
            } catch (\Error $e) {
            }
            error_log('RELOGIN');
            if ($this->user) {
                $this->jsonexit(['ok' => false, 'error_code' => 400, 'description' => 'Please login again.']);
            }
            $this->madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true]]);
            $this->madeline->bot_login($this->real_token);
            $this->madeline->API->get_updates_difference();
            $this->madeline->API->store_db([], true);
            \danog\MadelineProto\Serialization::serialize($this->madeline_path, $this->madeline);<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace PWRTelegram\PWRTelegram;

/*
Copyright 2016 <NAME>
(https://daniil.it)

This file is part of the PWRTelegram API.
the PWRTelegram API is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The PWRTelegram API is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with the PWRTelegram API.
If not, see <http://www.gnu.org/licenses/>.
*/
class API extends Tools
{
    public function __construct($params)
    {
        foreach ($params as $key => $val) {
            $this->{$key} = $val;
        }
        $info = $this->get_me();
        ini_set('error_log', isset($info['result']['username']) ? $this->homedir.'/'.$info['result']['username'].'.log' : $this->homedir.'/php-error-index.log');
    }

    public function db_connect()
    {
        if (!isset($this->pdo)) {
            $this->pdo = new \PDO($this->deep ? $this->deepdb : $this->db, $this->deep ? $this->deepdbuser : $this->dbuser, $this->deep ? $this->deepdbpassword : $this->dbpassword);
            $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
            $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
        }
    }

    public function madeline_connect()
    {
        if (!isset($this->madeline)) {
            require_once $this->pwrhomedir.'/vendor/autoload.php';
            try {
                $this->madeline = \danog\MadelineProto\Serialization::deserialize($this->madeline_path);
                if (is_object($this->madeline)) {
                    return $this->madeline;
                }
            } catch (\danog\MadelineProto\Exception $e) {
            } catch (\danog\MadelineProto\RPCErrorException $e) {
            } catch (\Error $e) {
            }
            error_log('RELOGIN');
            if ($this->user) {
                $this->jsonexit(['ok' => false, 'error_code' => 400, 'description' => 'Please login again.']);
            }
            $this->madeline = new \danog\MadelineProto\API(['logger' => ['logger' => 1], 'pwr' => ['pwr' => true, 'db_token' => $this->db_token, 'strict' => true]]);
            $this->madeline->bot_login($this->real_token);
            $this->madeline->API->get_updates_difference();
            $this->madeline->API->store_db([], true);
            \danog\MadelineProto\Serialization::serialize($this->madeline_path, $this->madeline);
{'fraction_non_alphanumeric': 0.14981002352089742, 'fraction_numerical': 0.0032567396417586395, 'mean_word_length': 2.7967032967032965, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 107, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1063147', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1628, 'n_words': 424}