<commit_before><?php
/**
 * Copyright (C) 2016-2017 <NAME>
 * This file is part of BruhhBot.
 * BruhhBot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * BruhhBot 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with BruhhBot. If not, see <http://www.gnu.org/licenses/>.
 */




function from_master($update, $MadelineProto, $str = '', $send = false)
{
    $user = cache_from_user_info($update, $MadelineProto);
    $master = cache_get_info($update, $MadelineProto, getenv('MASTER_USERNAME'));
    if ($user['bot_api_id'] == $master['bot_api_id']
        or in_array($user['bot_api_id'], json_decode(getenv('SUDO'), true))
        or $user['bot_api_id'] == $MadelineProto->bot_api_id
        or $user['bot_api_id'] == $MadelineProto->bot_id
    ) {
        return true;
    } else {
        if ($send) {
            $peer = $MadelineProto->get_info($update['update']['message']['to_id'])['InputPeer'];
            $msg_id = $update['update']['message']['id'];
            $message = $str;
            $sentMessage = $MadelineProto->messages->sendMessage(
                ['peer' => $peer, 'reply_to_msg_id' => $msg_id, 'message' => $message]
            );
            \danog\MadelineProto\Logger::log($sentMessage);
        }

        return false;
    }
}

function is_master($MadelineProto, $userid)
{
    if ($userid == $MadelineProto->get_info(
        getenv('MASTER_USERNAME')
    )['bot_api_id']
        or $userid == $MadelineProto->get_info(
        getenv('BOT_API_USERNAME')
    )['bot_api_id']
     ) {
        return true;
    } else {
        return false;
    }
}

function from_admin($update, $MadelineProto, $str = '', $send = false)
{
    $ch_id = -100 .$update['update']['message']['to_id']['channel_id'];
    $userid = $MadelineProto->get_info(
        $update['update']['message']['from_id']
    )['bot_api_id'];
    if (!isset($MadelineProto->cache[$ch_id])) {
        $MadelineProto->cache[$ch_id] = [];
    }
    if (!isset($MadelineProto->cache[$ch_id]['admins'])) {
        $MadelineProto->cache[$ch_id]['admins'] = [];
    }
    if (isset($MadelineProto->cache[$ch_id]['admins'][$userid])) {
        $diff = time() - $MadelineProto->cache[$ch_id]['admins'][$userid]['timestamp'];
        if ($diff < 300) {
            return $MadelineProto->cache[$ch_id]['admins'][$userid]['return'];
        }
    }
    $admins = cache_get_chat_info($update, $MadelineProto);
    foreach ($admins['participants'] as $key) {
        if (array_key_exists('user', $key)) {
            $id = $key['user']['id'];
        } else {
            if (array_key_exists('bot', $key)) {
                $id = $key['bot']['id'];
            }
        }
        if ($id == $userid) {
            if (array_key_exists('role', $key)) {
                if ($key['role'] == 'moderator'
                    or $key['role'] == 'creator'
                    or $key['role'] == 'editor'
                    or $key['role'] == 'admin'
                ) {
                    $mod = true;
                    break;
                } else {
                    $mod = false;
                    break;
                }
            } else {
                $mod = false;
                break;
            }
        }
        $mod = false;
    }
    if ($mod or from_master($update, $MadelineProto)) {
        $MadelineProto->cache[$ch_id]['admins'][$userid] = ['timestamp' => time(), 'return' => true];

        return true;
    } else {
        if ($send) {
            $peer = $MadelineProto->get_info($update['update']['message']['to_id'])['InputPeer'];
            $msg_id = $update['update']['message']['id'];
            $message = $str;
            $sentMessage = $MadelineProto->messages->sendMessage(
                ['peer' => $peer, 'reply_to_msg_id' => $msg_id, 'message' => $message]
            );
            \danog\MadelineProto\Logger::log($sentMessage);
        }
        $MadelineProto->cache[$ch_id]['admins'][$userid] = ['timestamp' => time(), 'return' => false];

        return false;
    }
}

function is_admin($update, $MadelineProto, $userid, $send = false, $ch_id = false)
{
    try {
        if (!$ch_id) {
            $admins = cache_get_chat_info($update, $MadelineProto);
        } else {
            $admins = cache_get_info($update, $MadelineProto, $ch_id, true);
        }
        $ch_id = $admins['id'];
        if (!isset($MadelineProto->cache[$ch_id])) {
            $MadelineProto->cache[$ch_id] = [];
        }
        if (!isset($MadelineProto->cache[$ch_id]['admins'])) {
            $MadelineProto->cache[$ch_id]['admins'] = [];
        }
        if (isset($MadelineProto->cache[$ch_id]['admins'][$userid])) {
            $diff = time() - $MadelineProto->cache[$ch_id]['admins'][$userid]['timestamp'];
            if ($diff < 300) {
                return $MadelineProto->cache[$ch_id]['admins'][$userid]['return'];
            }<commit_msg>fixes<commit_after><?php
/**
 * Copyright (C) 2016-2017 <NAME>
 * This file is part of BruhhBot.
 * BruhhBot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * BruhhBot 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with BruhhBot. If not, see <http://www.gnu.org/licenses/>.
 */




function from_master($update, $MadelineProto, $str = '', $send = false)
{
    $user = cache_from_user_info($update, $MadelineProto);
    $master = cache_get_info($update, $MadelineProto, getenv('MASTER_USERNAME'));
    if ($user['bot_api_id'] == $master['bot_api_id']
        or in_array($user['bot_api_id'], json_decode(getenv('SUDO'), true))
        or $user['bot_api_id'] == $MadelineProto->bot_api_id
        or $user['bot_api_id'] == $MadelineProto->bot_id
    ) {
        return true;
    } else {
        if ($send) {
            $peer = $MadelineProto->get_info($update['update']['message']['to_id'])['InputPeer'];
            $msg_id = $update['update']['message']['id'];
            $message = $str;
            $sentMessage = $MadelineProto->messages->sendMessage(
                ['peer' => $peer, 'reply_to_msg_id' => $msg_id, 'message' => $message]
            );
            \danog\MadelineProto\Logger::log($sentMessage);
        }

        return false;
    }
}

function is_master($MadelineProto, $userid)
{
    if ($userid == $MadelineProto->get_info(
        getenv('MASTER_USERNAME')
    )['bot_api_id']
        or $userid == $MadelineProto->get_info(
        getenv('BOT_API_USERNAME')
    )['bot_api_id']
     ) {
        return true;
    } else {
        return false;
    }
}

function from_admin($update, $MadelineProto, $str = '', $send = false)
{
    try {
        $ch_id = -100 .$update['update']['message']['to_id']['channel_id'];
        $userid = $MadelineProto->get_info(
            $update['update']['message']['from_id']
        )['bot_api_id'];
        if (!isset($MadelineProto->cache[$ch_id])) {
            $MadelineProto->cache[$ch_id] = [];
        }
        if (!isset($MadelineProto->cache[$ch_id]['admins'])) {
            $MadelineProto->cache[$ch_id]['admins'] = [];
        }
        if (isset($MadelineProto->cache[$ch_id]['admins'][$userid])) {
            $diff = time() - $MadelineProto->cache[$ch_id]['admins'][$userid]['timestamp'];
            if ($diff < 300) {
                return $MadelineProto->cache[$ch_id]['admins'][$userid]['return'];
            }
        }
        $admins = cache_get_chat_info($update, $MadelineProto);
        foreach ($admins['participants'] as $key) {
            if (array_key_exists('user', $key)) {
                $id = $key['user']['id'];
            } else {
                if (array_key_exists('bot', $key)) {
                    $id = $key['bot']['id'];
                }
            }
            if ($id == $userid) {
                if (array_key_exists('role', $key)) {
                    if ($key['role'] == 'moderator'
                        or $key['role'] == 'creator'
                        or $key['role'] == 'editor'
                        or $key['role'] == 'admin'
                    ) {
                        $mod = true;
                        break;
                    } else {
                        $mod = false;
                        break;
                    }
                } else {
                    $mod = false;
                    break;
                }
            }
            $mod = false;
        }
        if ($mod or from_master($update, $MadelineProto)) {
            $MadelineProto->cache[$ch_id]['admins'][$userid] = ['timestamp' => time(), 'return' => true];

            return true;
        } else {
            if ($send) {
                $peer = $MadelineProto->get_info($update['update']['message']['to_id'])['InputPeer'];
                $msg_id = $update['update']['message']['id'];
                $message = $str;
                $sentMessage = $MadelineProto->messages->sendMessage(
                    ['peer' => $peer, 'reply_to_msg_id' => $msg_id, 'message' => $message]
                );
                \danog\MadelineProto\Logger::log($sentMessage);
            }
            $MadelineProto->cache[$ch_id]['admins'][$userid] = ['timestamp' => time(), 'return' => false];

            return false;
        }
    } catch (Exception $e) {
        return false;
    }
}

function is_admin($update, $MadelineProto, $userid, $send = false, $ch_id = false)
{
    try {
        if (!$ch_id) {
            $admins = cache_get_chat_info($update, $MadelineProto);
        } else {
            $admins = cache_get_info($update, $MadelineProto, $ch_id, true);
        }
        $ch_id = $admins['id'];
        if (!isset($MadelineProto->cache[$ch_id])) {
            $MadelineProto->cache[$ch_id] = [];
        }
        if (!isset($MadelineProto->cache[$ch_id]['admins'])) {
            $MadelineProto->cache[$ch_id]['admins'] = [];
        }
        if (isset($MadelineProto->cache[$ch_id]['admins'][$userid])) {
            $diff = time() - $MadelineProto->cache[$ch_id]['admins'][$userid]['timestamp'];
            if ($diff < 300) {
                return $MadelineProto->cache[$ch_id]['admins'][$userid]['return'];
            }
{'fraction_non_alphanumeric': 0.17009226272038, 'fraction_numerical': 0.003288572211564812, 'mean_word_length': 2.1779390420899856, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 81, 'https://': 0, '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': '1722929', 'n_tokens_mistral': 3409, 'n_tokens_neox': 3282, 'n_words': 658}