<?php

use Database\{Games, Inviteuser, Listbots, Profile, Settings, Users};

if (!$user_active) {
    $Telegram->sendMessage($chatid, msg('blocked'));
    die();
}

if (preg_match('/^\/([Ss]tart)(.*)/', $text)) {
    if (getStore('inGame') == true) {
        $Telegram->sendMessage($chatid, msg('errorGame_9'), 'html', true);
        die();
    }
    if (!preg_match('/^\/([Ss]tart)$/', $text)) {
        $dta = str_replace(['/start', ' '], '', $text);
        if (Profile::checkUserByCode($dta)) {
            $ProfileInviter = Profile::getUserByCode($dta);
            $inviterId = $ProfileInviter->chatid;
            $inviterCoin = $ProfileInviter->coin;
            $inviterCount = $ProfileInviter->invite;
            $coinBot = Settings::getSettings('coininvite');
            if (Users::check($chatid) == true and Inviteuser::hasInvited($inviterId, $chatid) == false) {
                Inviteuser::addInvited($inviterId, $chatid);
                Profile::updateCoin($inviterId, $inviterCoin + $coinBot);
                Profile::updateInvite($inviterId, $inviterCount + 1);
                $Telegram->sendMessage($inviterId, msg('inviteduser'), 'html', true);

            }
        }

    }

    $Telegram->sendMessage($chatid, msg('start') ."\n\n".$signature, 'html', true, $button_start);

} elseif ($data == 'listbot') {
    Users::updateCommand($chatid, null);
    $botTxt = '';
    foreach (Listbots::getBots() as $bot) {
        $coBot = Games::getCountGameByBot($bot->bot);
        $botTxt .= '@' . $bot->bot . "\n";
        $botArr[] = ['count' => $coBot, 'bot' => $bot->bot];
    }

    $Telegram->editMessageText($chatid, $MessageID, str_replace('#bot', $botTxt, msg('listBot')), 'html', '', true, $button_start);
} elseif (preg_match('/^\/([Rr]emovebtn)/', $text)) {
    if (Profile::getUser($chatid)->ingame == false) {
        $a = $Telegram->sendMessage($chatid, '.', 'html', true, $button_remove);
        if ($a->getOk()) {
            $Telegram->deleteMessage($chatid, $a->getResult()->getMessageId());
        }
        $Telegram->sendMessage($chatid, msg('def')."\n\n".$signature, 'html', true, $button_start);
    }
} elseif ($data == 'callus') {
    $Telegram->editMessageText($chatid, $MessageID, str_replace('#id', '@' . Settings::getSettings('idsupport'), msg('call')), 'html', '', true, $button_start);
} elseif ($data == 'help') {
    $Telegram->editMessageText($chatid, $MessageID, msg('help')."\n\n".$signature, 'html', '', true, $button_start);
} elseif (preg_match('/^\/([Rr]emovephoto)/', $text)) {
    Profile::updatePhoto($chatid, null);
    $Telegram->sendMessage($chatid, msg('done')."\n\n".$signature, 'html', true);
} elseif ($data == 'AdsBtn') {
$Telegram->forwardMessage($chatid,'-1001167867190', 7);
    // $Telegram->sendMessage($chatid, msg('txtAdsBtn')."\n\n".$signature, 'html', true);
    // $Telegram->sendMessage($chatid, msg('txtAdsBtn2')."\n\n".$signature, 'html', true, $button_start);

} elseif ($data == 'group') {
     $Telegram->sendMessage($chatid, msg('def')."\n\n".$signature, 'html', true, $button_group);

} elseif (preg_match('/^\/([Rr]eset)/', $text)) {
    Profile::updatePhoto($chatid, null);
    Profile::updateAge($chatid, null);
    Profile::updateCity($chatid, null);
    Profile::updateName($chatid, null);
    Profile::updateState($chatid, null);
    $Telegram->sendMessage($chatid, msg('done')."\n\n".$signature, 'html', true);
}
