<?php
//region Add Group
use Database\{Groups, Listbots, Users};
use  inc\functions;
use  inc\fileStorage;

if (preg_match('/^\/([Aa]ddgroup)/', $text) && $user_rank == 'admin') {
    $Telegram->SendMessage($chatid, $chatid, 'html', false);

    if (!Groups::hasGroup($chatid)) {
        Groups::addGroup($chatid);
        $Telegram->SendMessage($chatid, $chatid, 'html', false);

        fileStorage::removeFile('bot');
        $Telegram->SendMessage($chatid, msg('DoneAddGroup'), 'html', false);
    } else {
        $Telegram->SendMessage($chatid, msg('alreadyexistsGroup'), 'html', false);
    }
}
//endregion Add Group
//dregion Remove Group
elseif (preg_match('/^\/([Rr]emovegroup)/', $text) && $user_rank == 'admin') {
    if (Groups::hasGroup($chatid)) {
        Groups::removeGroup($chatid);
        fileStorage::removeFile('bot');
        $Telegram->SendMessage($chatid, msg('DoneRemoveGroup'), 'html', false);
    } else {
        $Telegram->SendMessage($chatid, msg('NotFoundGroupOnDatabase'), 'html', false);
    }
}
//endregion Remove Group


//region Send waring For User
elseif (preg_match('/^([Ss]endWaring_)(.*)/', $data)) {
    $dta = str_replace(['SendWaring_'], '', $data);
    $bot = Users::getUser($dta)->bot;
    $beforToken = $Telegram->bot_token;
    $Telegram->bot_token = getStore('allBots')[$bot];
    $msg = str_replace(['#user'], [functions::generationMentions($dta, $dta)], msg('DoneSendWaring'));
    $Telegram->SendMessage($dta, msg('TextWaring'), 'html', false);
    $Telegram->bot_token = $beforToken;
    $Telegram->EditMessageText($chatid, $MessageID, $msg, 'html', '', true);

}
//endregion Send waring For User

//region Blocked User
elseif (preg_match('/^([Bb]lockedUser_)(.*)/', $data)) {
    $dta = str_replace(['BlockedUser_'], '', $data);
    Users::updateActive($dta, 0);
    $msg = str_replace(['#user'], [functions::generationMentions($dta, $dta)], msg('DoneBlockedUser'));
    $Telegram->EditMessageText($chatid, $MessageID, $msg, 'html', '', true);
}
//endregion Blocked User
if (Groups::hasGroup($chatid) == false && $user_rank != 'admin') {
    $Telegram->SendMessage($chatid, msg('noinvite'), 'html', false);
    $Telegram->LeaveChat($chatid);
}
