|
6 | 6 | use danog\MadelineProto\Logger; |
7 | 7 | use danog\MadelineProto\Magic; |
8 | 8 | use danog\MadelineProto\PTSException; |
| 9 | +use danog\MadelineProto\RPCError\BusinessConnectionNotAllowedError; |
9 | 10 | use danog\MadelineProto\RPCErrorException; |
10 | 11 | use danog\MadelineProto\Settings; |
11 | 12 | use danog\MadelineProto\Settings\Logger as SettingsLogger; |
@@ -69,10 +70,11 @@ function getTL(TLSchema $schema) |
69 | 70 | } |
70 | 71 | Assert::true(preg_match('/^[a-zA-Z0-9_-]*$/', $auth) === 1, 'TELERPC_AUTH_TOKEN can only contain a-z, A-Z, 0-9, _ and -'); |
71 | 72 |
|
| 73 | +$client = HttpClientBuilder::buildDefault(); |
72 | 74 | if ($auth) { |
73 | 75 | $res = json_decode( |
74 | 76 | ( |
75 | | - HttpClientBuilder::buildDefault() |
| 77 | + $client |
76 | 78 | ->request(new Request('https://report-rpc-error.madelineproto.xyz/?auth='.$auth.'&cleanup=1')) |
77 | 79 | )->getBody()->buffer(), |
78 | 80 | true, |
@@ -205,10 +207,24 @@ function call(API $API, string $method, array $args = []): void |
205 | 207 | } |
206 | 208 | unset($methods["user $name"]); |
207 | 209 | }); |
208 | | - $methods["business $name"] = async(static function () use ($bot, $name, $cId, &$methods): void { |
| 210 | + $methods["business $name"] = async(static function () use ($bot, $name, $cId, $client, $auth, &$methods): void { |
| 211 | + $ok = true; |
209 | 212 | try { |
210 | 213 | call($bot, $name, ['businessConnectionId' => $cId]); |
211 | | - } catch (RPCErrorException|PTSException) { |
| 214 | + } catch (PTSException|BusinessConnectionNotAllowedError) { |
| 215 | + $ok = false; |
| 216 | + } catch (RPCErrorException $e) { |
| 217 | + echo "Got ".$e->getMessage()." for business $name".PHP_EOL; |
| 218 | + } |
| 219 | + |
| 220 | + if ($ok && $auth) { |
| 221 | + $res = json_decode( |
| 222 | + ( |
| 223 | + $client |
| 224 | + ->request(new Request('https://report-rpc-error.madelineproto.xyz/?auth='.$auth.'&error=BUSINESS_CONNECTION_INVALID&method='.urlencode($name).'&code=400')) |
| 225 | + )->getBody()->buffer(), |
| 226 | + true, |
| 227 | + ); |
212 | 228 | } |
213 | 229 | unset($methods["business $name"]); |
214 | 230 | }); |
|
0 commit comments