index.php

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
<?php
require_once("func.php");
error_reporting(-1);
$chat_id = 25;
$bot_id = 110496329;
$admin_id = 240768670;
function vk($method, $data, $token="435bf22a8ce17c2642ce4ed4132e0c57b80100c90299f82a6438816"){
$url="https://api.vk.com/method/".$method;
if($curl = curl_init()){
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$data['access_token']=$token;
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
return $out;
curl_close($curl);
}
}
function send($chat_id, $message){
vk("messages.send", array(
"chat_id" => $chat_id,
"message" => $message
));
}
$res = json_decode(vk("messages.getHistory", array(
"chat_id" => $chat_id,
"offset" => $offset,
"rev" => 1
)), true);
$offset = $res["response"][0] - 20;
$last = $res["response"][20]["mid"];
$res = json_decode(vk("messages.getHistory", array(
"chat_id" => $chat_id,
"offset" => $offset,
"rev" => 1
)), true);
$offset = $res["response"][0] - 20;
$last = $res["response"][20]["mid"];
$start = time();
while(1){
$res = json_decode(vk("messages.getHistory", array(
"chat_id" => $chat_id,
"offset" => $offset,
"rev" => 1
)), true);
$offset = $res["response"][0] - 20;
if($res["response"][20]["mid"] > $last){
for($i=1;$i<21;$i++){
$msg = $res["response"][$i]["body"];
if($res["response"][$i]["mid"] > $last){
if((int)$res["response"][$i]["uid"] == $bot_id) continue;
$args = split(" ", $msg);
switch($args[0]){
case "!тест":
send($chat_id, "Хуест");
break;
case "!аптайм":
$seconds = time() - $start;
$time = '';
$days = (int)floor($seconds/86400);
if($days > 1){
$time .= $days.' дн.., ';
}elseif($days == 1){
$time .= $days.' дн., ';
}
$hours = (int)floor(($seconds-$days*86400)/3600);
$time .= ($hours > 1 ? $hours.' ч., ' : ($hours == 1 ? '1 ч., ' : ''));
$minutes = (int)floor(($seconds-$days*86400 - $hours*3600)/60);
$time .= ($minutes > 1 ? $minutes.' мин., ' : ($minutes == 1 ? '1 сек., ' : ''));
$seconds = (int)fmod($seconds, 60);
$time .= ($seconds > 1 ? $seconds.' сек.' : ($seconds == 1 ? '1 сек.' : ''));
send($chat_id, "Бот уже работает: $time");
break;
case "!стоп":
if((int)$res["response"][$i]["uid"] == $admin_id){
send($chat_id, "Меня выключает админ:(");
exit;
}else{
send($chat_id, "Ты не мой админ, я не буду выключаться");
}
break;
case "!инфо":
if($args[1]){
$info = json_decode(vk("users.get", array(
"user_ids" => $args[1],
"fields" => "verified,bdate,city,country,last_seen,online"
)), true);
$info = $info["response"];
send($chat_id, show_user($info));
}else{
send($chat_id, "Использование: \n!инфо id1 \n !инфо durov \n !инфо <id1,id2,...,id1000> \nМаксимальное количество id: 1000");
}
}
echo $msg." ".time()."\n";
}
}
}
$last = $res["response"][20]["mid"];
sleep(1);
}
?>