· 7 years ago · Jan 03, 2019, 04:48 PM
1<?php
2
3namespace botconsole;
4
5if (!isset($_REQUEST)) {
6 return;
7}
8//ÐÐСТРОЙКИ ГРУППЫ
9$confirmationToken = 'f';
10
11$token = 'f';
12
13$secretKey = 'f';
14
15//ÐÐСТРОЙКИ СЕРВЕРÐ
16$host = 'f';
17$port = f;
18$password = 'c-f';
19
20//ÐДМИÐИСТРÐТОРЫ (id)
21$ids = array(
22 00000000,
23 269593592
24);
25
26$data = json_decode(file_get_contents('php://input'));
27
28if (strcmp($data->secret, $secretKey) !== 0 && strcmp($data->type, 'confirmation') !== 0) {
29 return;
30}
31
32
33require_once('Rcon.php');
34
35
36switch ($data->type) {
37
38 case 'confirmation':
39 echo $confirmationToken;
40 break;
41
42 case 'message_new':
43
44 $userId = $data->object->user_id;
45 $text = $data->object->body;
46
47
48 foreach ($ids as $id) {
49 if (in_array($userId, $ids)) {
50
51
52
53 ###################sendMessage##################
54 $request_params = array(
55 'message' => "Выполнение команды: /" . $text,
56 'user_id' => $userId,
57 'access_token' => $token,
58 'v' => '5.0'
59 );
60 $get_params = http_build_query($request_params);
61 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
62 echo ('ok');
63 // return false; ############################################
64 $timeout = 3;
65
66 $rcon = new Rcon($host, $port, $password, $timeout);
67
68 if ($rcon->connect()) {
69 $alert = $rcon->sendCommand($text);
70
71
72 ###################sendMessage##################
73 $request_params = array(
74 'message' => $alert,
75 'user_id' => $userId,
76 'access_token' => $token,
77 'v' => '5.0'
78 );
79 $get_params = http_build_query($request_params);
80 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
81 echo ('ok');
82 // return false; ############################################
83
84 }
85 } else {
86 ###################sendMessage##################
87 $request_params = array(
88 'message' => "Ð’Ñ‹ не ÑвлÑетеÑÑŒ админиÑтратором. ",
89 'user_id' => $userId,
90 'access_token' => $token,
91 'v' => '5.0'
92 );
93 $get_params = http_build_query($request_params);
94 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
95 echo ('ok');
96 // return false;
97 ############################################
98 }
99 }
100
101
102
103 break;
104}