Skip to content

Commit 9f84f7b

Browse files
committed
Finalize
1 parent b264994 commit 9f84f7b

1 file changed

Lines changed: 58 additions & 39 deletions

File tree

‎tools/gen_filerefmap.php‎

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,25 @@ public function getTypeAtPosition(ExtractFromHereOp|ExtractFromRootOp $path): st
3030
$idx = 0;
3131
$type = null;
3232
do {
33-
if ($type === null) {
34-
$constructor = $this->tl->getConstructors()->findByPredicate($path[$idx]);
35-
if ($constructor === false) {
36-
$constructor = $this->tl->getMethods()->findByMethod($path[$idx]);
37-
}
38-
Assert::notFalse($constructor, "Constructor or method not found for path: " . json_encode($path));
39-
} else {
40-
$constructor = self::getConstructorsOfType($this->tl, $type)[$path[$idx]] ?? null;
41-
Assert::notNull($constructor, "Could not find type {$path[$idx]} for $type, path: " . json_encode($path));
33+
if ($type !== null) {
34+
$_ = self::getConstructorsOfType($this->tl, $type)[$path[$idx]] ?? null;
35+
Assert::notNull($_, "Could not find type {$path[$idx]} for $type, path: " . json_encode($path));
36+
}
37+
$constructor = $this->tl->getConstructors()->findByPredicate($path[$idx]);
38+
if ($constructor === false) {
39+
$constructor = $this->tl->getMethods()->findByMethod($path[$idx]);
4240
}
41+
Assert::notFalse($constructor, "Constructor or method not found for path: " . json_encode($path));
42+
4343
$idx++;
4444
$type = null;
4545
foreach ($constructor['params'] as $param) {
4646
if ($param['name'] === $path[$idx]) {
4747
$type = $param['type'];
4848
}
4949
}
50-
Assert::notNull($type, "Parameter not found in constructor or method: " . json_encode($path));
50+
$n = $constructor['predicate'] ?? $constructor['name'];
51+
Assert::notNull($type, "Parameter {$path[$idx]} not found in constructor or method $n: " . json_encode($path));
5152
} while (++$idx < count($path));
5253

5354
return $type;
@@ -62,7 +63,7 @@ public static function getConstructorsOfType(TLInterface $tl, string $type): arr
6263
}
6364
foreach ($tl->getMethods()->by_id as $method) {
6465
if ($method['type'] === $type) {
65-
$constructors[$method['method']] = true;
66+
$constructors[$method['method']] = false;
6667
}
6768
}
6869
Assert::notEmpty($constructors, "No constructors found for type: $type");
@@ -112,6 +113,7 @@ public function extend(string ...$path): self
112113

113114
public function build(TLContext $tl): array
114115
{
116+
$tl->getTypeAtPosition($this);
115117
return [
116118
'op' => 'extractFromHere',
117119
'path' => $this->path,
@@ -135,6 +137,7 @@ public function extend(string ...$path): self
135137

136138
public function build(TLContext $tl): array
137139
{
140+
$tl->getTypeAtPosition($this);
138141
return [
139142
'op' => 'extractFromRoot',
140143
'path' => $this->path,
@@ -341,7 +344,7 @@ public function build(TLContext $tl): array
341344
}
342345
$locations[$constructor] = new GetMessageOp(
343346
new ExtractFromHereOp($constructor, 'peer_id'),
344-
new ExtractFromHereOp($constructor, 'msg_id'),
347+
new ExtractFromHereOp($constructor, 'id'),
345348
);
346349
}
347350
return;
@@ -351,7 +354,16 @@ public function build(TLContext $tl): array
351354
return;
352355
}
353356
if ($type === 'BotApp') {
354-
$locations['botApp'] = CallOp::simple('messages.getBotApp', 'botApp', ['url' => 'url']);
357+
$locations['botApp'] = CallOp::simple('messages.getBotApp', 'botApp', [
358+
'app' => new ConstructorOp(
359+
'inputBotAppID',
360+
[
361+
'id' => new ExtractFromHereOp('botApp', 'id'),
362+
'access_hash' => new ExtractFromHereOp('botApp', 'access_hash'),
363+
]
364+
),
365+
'hash' => new LiteralOp(0),
366+
]);
355367
return;
356368
}
357369
if ($type === 'BotInfo') {
@@ -427,19 +439,24 @@ public function build(TLContext $tl): array
427439
return;
428440
}
429441
if ($type === 'StarsTransaction') {
430-
$locations['starsTransaction'] = new CallOp(
431-
'payments.getStarsTransactionsByID',
432-
[
433-
'peer' => new ExtractFromRootOp('payments.StarsStatus', 'peer'),
434-
'id' => new ArrayOp(new ConstructorOp(
435-
'inputStarsTransaction',
436-
[
437-
'id' => new ExtractFromHereOp('starsTransaction', 'id'),
438-
'refund' => new ExtractFromHereOp('starsTransaction', 'refund'),
439-
]
440-
)),
441-
]
442-
);
442+
foreach (TLContext::getConstructorsOfType($TL, $type) as $constructor => $isConstructor) {
443+
if ($isConstructor) {
444+
continue;
445+
}
446+
$locations[$constructor] = new CallOp(
447+
'payments.getStarsTransactionByID',
448+
[
449+
'peer' => new ExtractFromRootOp($constructor, 'peer'),
450+
'id' => new ConstructorOp(
451+
'inputStarsTransaction',
452+
[
453+
'id' => new ExtractFromHereOp($constructor, 'id'),
454+
'refund' => new ExtractFromHereOp($constructor, 'refund'),
455+
]
456+
),
457+
]
458+
);
459+
}
443460
return;
444461
}
445462
if ($type === 'AttachMenuBot') {
@@ -499,19 +516,21 @@ public function build(TLContext $tl): array
499516
return;
500517
}
501518
if ($type === 'StickerSetCovered') {
502-
$locations['StickerSetCovered'] = new CallOp(
503-
'messages.getStickerSet',
504-
[
505-
'stickerset' => new ConstructorOp(
506-
'inputStickerSetID',
507-
[
508-
'id' => new ExtractFromHereOp('StickerSetCovered', 'set', 'stickerSet', 'id'),
509-
'access_hash' => new ExtractFromHereOp('StickerSetCovered', 'set', 'stickerSet', 'access_hash'),
510-
'hash' => new LiteralOp(0),
511-
],
512-
),
513-
]
514-
);
519+
foreach (['stickerSetMultiCovered', 'stickerSetFullCovered'] as $c) {
520+
$locations[$c] = new CallOp(
521+
'messages.getStickerSet',
522+
[
523+
'stickerset' => new ConstructorOp(
524+
'inputStickerSetID',
525+
[
526+
'id' => new ExtractFromHereOp($c, 'set', 'stickerSet', 'id'),
527+
'access_hash' => new ExtractFromHereOp($c, 'set', 'stickerSet', 'access_hash'),
528+
'hash' => new LiteralOp(0),
529+
],
530+
),
531+
]
532+
);
533+
}
515534
return;
516535
}
517536
if ($type === 'messages.StickerSet') {

0 commit comments

Comments
 (0)