mirror of
https://github.com/danog/telerpc.git
synced 2024-11-26 20:14:48 +01:00
Merge branch 'master' of github.com:danog/telerpc
This commit is contained in:
commit
b8d8bb47bf
@ -6,4 +6,4 @@
|
|||||||
|
|
||||||
include 'src/Main.php';
|
include 'src/Main.php';
|
||||||
|
|
||||||
(new Main)->run();
|
(new Main())->run();
|
||||||
|
24
src/Main.php
24
src/Main.php
@ -3,6 +3,7 @@
|
|||||||
final class Main
|
final class Main
|
||||||
{
|
{
|
||||||
private ?\PDO $pdo = null;
|
private ?\PDO $pdo = null;
|
||||||
|
|
||||||
private function connect(): \PDO
|
private function connect(): \PDO
|
||||||
{
|
{
|
||||||
if ($this->pdo !== null) {
|
if ($this->pdo !== null) {
|
||||||
@ -11,8 +12,10 @@ final class Main
|
|||||||
$this->pdo = include 'db.php';
|
$this->pdo = include 'db.php';
|
||||||
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
return $this->pdo;
|
return $this->pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function error(string $message): string
|
private static function error(string $message): string
|
||||||
{
|
{
|
||||||
return \json_encode(['ok' => false, 'description' => $message]);
|
return \json_encode(['ok' => false, 'description' => $message]);
|
||||||
@ -43,6 +46,7 @@ final class Main
|
|||||||
|
|
||||||
return [$r, $hr];
|
return [$r, $hr];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function v4(): array
|
private function v4(): array
|
||||||
{
|
{
|
||||||
$this->connect();
|
$this->connect();
|
||||||
@ -68,6 +72,7 @@ final class Main
|
|||||||
|
|
||||||
return [$r, $hr];
|
return [$r, $hr];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function bot(): array
|
private function bot(): array
|
||||||
{
|
{
|
||||||
$this->connect();
|
$this->connect();
|
||||||
@ -75,8 +80,10 @@ final class Main
|
|||||||
$q = $this->pdo->prepare('SELECT method FROM bot_method_invalid');
|
$q = $this->pdo->prepare('SELECT method FROM bot_method_invalid');
|
||||||
$q->execute();
|
$q->execute();
|
||||||
$r = $q->fetchAll(PDO::FETCH_COLUMN);
|
$r = $q->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cli(): void
|
private function cli(): void
|
||||||
{
|
{
|
||||||
$this->connect();
|
$this->connect();
|
||||||
@ -124,11 +131,11 @@ final class Main
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[$r, $hr] = $this->v3();
|
[$r, $hr] = $this->v3();
|
||||||
\file_put_contents("data/v3.json", \json_encode(['ok' => true, 'result' => $r, 'human_result' => $hr]));
|
\file_put_contents('data/v3.json', \json_encode(['ok' => true, 'result' => $r, 'human_result' => $hr]));
|
||||||
[$r, $hr] = $this->v4();
|
[$r, $hr] = $this->v4();
|
||||||
\file_put_contents("data/v4.json", \json_encode(['ok' => true, 'result' => $r, 'human_result' => $hr]));
|
\file_put_contents('data/v4.json', \json_encode(['ok' => true, 'result' => $r, 'human_result' => $hr]));
|
||||||
$bot = $this->bot();
|
$bot = $this->bot();
|
||||||
\file_put_contents("data/bot.json", \json_encode(['ok' => true, 'result' => $bot]));
|
\file_put_contents('data/bot.json', \json_encode(['ok' => true, 'result' => $bot]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(): void
|
public function run(): void
|
||||||
@ -151,6 +158,7 @@ final class Main
|
|||||||
$error = $_REQUEST['error'];
|
$error = $_REQUEST['error'];
|
||||||
$method = $_REQUEST['error'];
|
$method = $_REQUEST['error'];
|
||||||
$code = $_REQUEST['code'];
|
$code = $_REQUEST['code'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
if ($error === $code) {
|
if ($error === $code) {
|
||||||
@ -163,16 +171,16 @@ final class Main
|
|||||||
$q = $this->pdo->prepare('SELECT description FROM error_descriptions WHERE error=?');
|
$q = $this->pdo->prepare('SELECT description FROM error_descriptions WHERE error=?');
|
||||||
$q->execute([$error]);
|
$q->execute([$error]);
|
||||||
if ($q->rowCount()) {
|
if ($q->rowCount()) {
|
||||||
die(self::ok($q->fetchColumn()));
|
exit(self::ok($q->fetchColumn()));
|
||||||
}
|
}
|
||||||
die(self::error('No description'));
|
exit(self::error('No description'));
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
die(self::error($e->getMessage()));
|
exit(self::error($e->getMessage()));
|
||||||
}
|
}
|
||||||
die(self::ok(true));
|
exit(self::ok(true));
|
||||||
} else {
|
} else {
|
||||||
die(self::error('API for reporting Telegram RPC errors. For localized errors see https://rpc.madelineproto.xyz, to report a new error use the `code`, `method` and `error` GET/POST parameters.'));
|
exit(self::error('API for reporting Telegram RPC errors. For localized errors see https://rpc.madelineproto.xyz, to report a new error use the `code`, `method` and `error` GET/POST parameters.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user