<?
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$token = file_get_contents(__DIR__.'/token.txt');
define('TOKEN', $token);
//https://api.telegram.org/bot1997853074:AAG24rfDL7tti6u09ddl0p_DsEW_xFPcuNo/setWebhook?url=https://bots.sdarks.ru/
require_once $_SERVER['DOCUMENT_ROOT'] . "/vendor/autoload.php";
require_once __DIR__ . '/core.php';
$databaseDirectory = __DIR__ . "/myDatabase";
use SleekDB\Store;
$configuration = [
"auto_cache" => true,
"cache_lifetime" => null,
"timeout" => false
];
if (!isset($_GET['test'])) {
file_put_contents(__DIR__ . '/test.json', file_get_contents('php://input'));
$data = json_decode(file_get_contents('php://input'));
} else {
$data = json_decode(file_get_contents(__DIR__ . '/test.json'));
}
if ($data->message->chat->type != 'private') {
exit('ok');
}
if (!empty($data->message->text)) {
$userStore = new Store("user", $databaseDirectory, $configuration);
$tgStore = new Store("tg", $databaseDirectory, $configuration);
$TGuser = $tgStore->findById($data->message->from->id);
if (empty($TGuser)) {
$tg = [
'_id' => $data->message->from->id,
'login' => $data->message->from->username,
'name' => $data->message->from->first_name.' '.$data->message->from->last_name,
'language_code' => $data->message->from->language_code,
'is_premium' => $data->message->from->is_premium
];
$tgStore->updateOrInsert($tg, false);
}
$user = $userStore->findById($data->message->from->id);
$reload = [
'/reload',
'return',
'reset',
'кудщфв',
'куегкт',
'куыуе',
'начать заново'
];
if (!empty($data->message->text) and in_array(strtolower($data->message->text), $reload) or empty($user)) {
if (!empty($user)) {
$userStore->deleteById($data->message->from->id);
}
$user = [
'_id' => $data->message->from->id,
'stage' => 'launch',
'toldname' => '0',
'status' => 0,
'pause' => 0,
'boulderdayone' => '0',
'deadenddayone' => '0',
'hurtshoulder' => '0',
'mapsuggest' => '0',
'toldstudent' => '0',
'backofship' => '0',
'frontofship' => '0',
'rations' => '0',
'ratpellets' => '0',
'startedburialtalk' => '0',
'capalive' => '1',
'ginny' => '0',
'power' => 'none',
'capburied' => '0',
'crewburied' => '0',
'hurtankle' => '0',
'pills' => '0',
'glowrods' => '0',
'ginnycaravel' => '0',
'zombierats' => '0',
'compassweird' => '0',
'bringginnytwo' => '0',
'proximityalarm' => '0',
'trycaravelgalley' => '0',
'homemadecompass' => '0',
'triedgalley' => '0',
'peakdoorway' => '0',
'sendingsos' => '0',
'warnship' => '0',
'overridetarget' => '0',
'clockwisecrater' => '0',
'plural' => 'none',
'testrods' => '10',
'gameend' => '',
'inBridgeContent' => '0'
];
$user = $userStore->updateOrInsert($user, false);
}
}
$user = (object) $user;
if (!empty($user->gameend)) {
if (!empty($user->gameend) and ($user->gameend == 'connectionlost' or $user->gemeend == 'wrappingthingsup')) {
$send_data = [
'text' => 'Ваш напарник мёртв',
'chat_id' => $user->_id
];
$keyboard = [];
$keyboard['keyboard'][0][] = ['text' => 'Начать заново'];
} elseif ($user->gameend == '"whatthehell"') {
$send_data = [
'text' => 'Вы спасли напарника, поздравляем)',
'chat_id' => $user->ids
];
$keyboard = [];
$keyboard['keyboard'][0][] = ['text' => 'reload'];
}
$keyboard['resize_keyboard'] = true;
$keyboard['one_time_keyboard'] = true;
$keyboard['selective'] = true;
$send_data['reply_markup'] = json_encode($keyboard);
sendTelegram($send_data);
exit();
}
if (isset($user->pause) and $user->pause > time()) {
$send_data = [
'text' => 'Я сейчас занят, не отвлекай',
'chat_id' => $data->message->chat->id
];
sendTelegram($send_data);
exit();
}
$str = '';
$button = [];
$update = false;
echo '<pre>';
echo 'TG: ';
print_r($data);
echo 'User: ';
print_r($user);
echo '</pre>';
main_index($user, $data);