mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 17:24:40 +01:00
Cleanup
This commit is contained in:
parent
886993a9e4
commit
b343265b32
@ -60,7 +60,8 @@
|
|||||||
"nikic/php-parser": "^5.0.2",
|
"nikic/php-parser": "^5.0.2",
|
||||||
"revolt/event-loop": "^1.0.6",
|
"revolt/event-loop": "^1.0.6",
|
||||||
"danog/async-orm": "^1.0.2",
|
"danog/async-orm": "^1.0.2",
|
||||||
"symfony/thanks": "^1.3"
|
"symfony/thanks": "^1.3",
|
||||||
|
"danog/telegram-entities": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-ctype": "*",
|
"ext-ctype": "*",
|
||||||
@ -72,7 +73,8 @@
|
|||||||
"amphp/http-server": "^3.3",
|
"amphp/http-server": "^3.3",
|
||||||
"revolt/event-loop-adapter-react": "^1.1.1",
|
"revolt/event-loop-adapter-react": "^1.1.1",
|
||||||
"dg/bypass-finals": "dev-master",
|
"dg/bypass-finals": "dev-master",
|
||||||
"brianium/paratest": "^6.11.1"
|
"brianium/paratest": "^6.11.1",
|
||||||
|
"vimeo/psalm": "dev-master"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-primemodule": "Install the primemodule and FFI extensions to speed up MadelineProto (https://prime.madelineproto.xyz)",
|
"ext-primemodule": "Install the primemodule and FFI extensions to speed up MadelineProto (https://prime.madelineproto.xyz)",
|
||||||
@ -132,11 +134,6 @@
|
|||||||
"post-install-cmd": ["@composer bin all install --ansi"],
|
"post-install-cmd": ["@composer bin all install --ansi"],
|
||||||
"post-update-cmd": ["@composer bin all update --ansi"]
|
"post-update-cmd": ["@composer bin all update --ansi"]
|
||||||
},
|
},
|
||||||
"extra": {
|
|
||||||
"phabel": {
|
|
||||||
"revision": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"config": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
"bamarni/composer-bin-plugin": true,
|
"bamarni/composer-bin-plugin": true,
|
||||||
|
2
docs
2
docs
@ -1 +1 @@
|
|||||||
Subproject commit 11626857a0bfe4d094f4f43ad63b6df6364b6547
|
Subproject commit 87f2e3f97142013572b6f5615fc8a336eeebc18e
|
@ -8,9 +8,9 @@
|
|||||||
ignoreInternalFunctionNullReturn="true"
|
ignoreInternalFunctionNullReturn="true"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns="https://getpsalm.org/schema/config"
|
xmlns="https://getpsalm.org/schema/config"
|
||||||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor-bin/check/vendor/vimeo/psalm/config.xsd"
|
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
|
||||||
errorBaseline="psalm-baseline.xml"
|
errorBaseline="psalm-baseline.xml"
|
||||||
autoloader="vendor-bin/check/vendor/autoload.php"
|
autoloader="vendor/autoload.php"
|
||||||
>
|
>
|
||||||
<enableExtensions>
|
<enableExtensions>
|
||||||
<extension name="ffi"/>
|
<extension name="ffi"/>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
namespace danog\MadelineProto;
|
namespace danog\MadelineProto;
|
||||||
|
|
||||||
|
use AssertionError;
|
||||||
use danog\Decoder\FileId;
|
use danog\Decoder\FileId;
|
||||||
use danog\Decoder\FileIdType;
|
use danog\Decoder\FileIdType;
|
||||||
use danog\MadelineProto\EventHandler\Media;
|
use danog\MadelineProto\EventHandler\Media;
|
||||||
@ -54,7 +55,8 @@ final class BotApiFileId
|
|||||||
*/
|
*/
|
||||||
public function getTypeClass(): string
|
public function getTypeClass(): string
|
||||||
{
|
{
|
||||||
return match (FileId::fromBotAPI($this->fileId)->type) {
|
$f = FileId::fromBotAPI($this->fileId);
|
||||||
|
return match ($f->type) {
|
||||||
FileIdType::PHOTO => Photo::class,
|
FileIdType::PHOTO => Photo::class,
|
||||||
FileIdType::VOICE => Voice::class,
|
FileIdType::VOICE => Voice::class,
|
||||||
FileIdType::VIDEO => Video::class,
|
FileIdType::VIDEO => Video::class,
|
||||||
@ -62,7 +64,8 @@ final class BotApiFileId
|
|||||||
FileIdType::STICKER => AbstractSticker::class,
|
FileIdType::STICKER => AbstractSticker::class,
|
||||||
FileIdType::VIDEO_NOTE => RoundVideo::class,
|
FileIdType::VIDEO_NOTE => RoundVideo::class,
|
||||||
FileIdType::AUDIO => Audio::class,
|
FileIdType::AUDIO => Audio::class,
|
||||||
FileIdType::ANIMATION => Gif::class
|
FileIdType::ANIMATION => Gif::class,
|
||||||
|
default => throw new AssertionError("Cannot use bot API file ID of type ".$f->type->value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ use function stream_get_contents;
|
|||||||
final class Conversion
|
final class Conversion
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Prepare API instance.
|
* Import authorization from raw auth key and DC id.
|
||||||
*
|
*
|
||||||
* @param array<int, string> $authorization Authorization info, DC ID => auth key
|
* @param array<int, string> $authorization Authorization info, DC ID => auth key
|
||||||
*/
|
*/
|
||||||
|
@ -140,7 +140,7 @@ final class DataCenter
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
private static function normalizeBindToOption(string $bindTo = null): ?string
|
private static function normalizeBindToOption(?string $bindTo = null): ?string
|
||||||
{
|
{
|
||||||
if ($bindTo === null) {
|
if ($bindTo === null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -128,7 +128,7 @@ final class DoHWrapper
|
|||||||
*
|
*
|
||||||
* @return ConnectionContext[]
|
* @return ConnectionContext[]
|
||||||
*/
|
*/
|
||||||
public function generateContexts(string $uri, ConnectContext $context = null): array
|
public function generateContexts(string $uri, ?ConnectContext $context = null): array
|
||||||
{
|
{
|
||||||
$ctxs = [];
|
$ctxs = [];
|
||||||
$combos = [
|
$combos = [
|
||||||
|
@ -40,8 +40,9 @@ use danog\MadelineProto\EventHandler\Message\Entities\Url;
|
|||||||
use danog\MadelineProto\TL\Conversion\DOMEntities;
|
use danog\MadelineProto\TL\Conversion\DOMEntities;
|
||||||
use danog\MadelineProto\TL\Conversion\Extension;
|
use danog\MadelineProto\TL\Conversion\Extension;
|
||||||
use danog\MadelineProto\TL\Conversion\MarkdownEntities;
|
use danog\MadelineProto\TL\Conversion\MarkdownEntities;
|
||||||
|
use danog\TelegramEntities\Entities;
|
||||||
|
use danog\TelegramEntities\EntityTools;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Webmozart\Assert\Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some tools.
|
* Some tools.
|
||||||
@ -55,15 +56,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function mbStrlen(string $text): int
|
public static function mbStrlen(string $text): int
|
||||||
{
|
{
|
||||||
$length = 0;
|
return EntityTools::mbStrlen($text);
|
||||||
$textlength = \strlen($text);
|
|
||||||
for ($x = 0; $x < $textlength; $x++) {
|
|
||||||
$char = \ord($text[$x]);
|
|
||||||
if (($char & 0xc0) != 0x80) {
|
|
||||||
$length += 1 + ($char >= 0xf0 ? 1 : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $length;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Telegram UTF-8 multibyte substring.
|
* Telegram UTF-8 multibyte substring.
|
||||||
@ -74,15 +67,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function mbSubstr(string $text, int $offset, ?int $length = null): string
|
public static function mbSubstr(string $text, int $offset, ?int $length = null): string
|
||||||
{
|
{
|
||||||
return mb_convert_encoding(
|
return EntityTools::mbSubstr($text, $offset, $length);
|
||||||
substr(
|
|
||||||
mb_convert_encoding($text, 'UTF-16'),
|
|
||||||
$offset<<1,
|
|
||||||
$length === null ? null : ($length<<1),
|
|
||||||
),
|
|
||||||
'UTF-8',
|
|
||||||
'UTF-16',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Telegram UTF-8 multibyte split.
|
* Telegram UTF-8 multibyte split.
|
||||||
@ -93,13 +78,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function mbStrSplit(string $text, int $length): array
|
public static function mbStrSplit(string $text, int $length): array
|
||||||
{
|
{
|
||||||
$result = [];
|
return EntityTools::mbStrSplit($text, $length);
|
||||||
foreach (str_split(mb_convert_encoding($text, 'UTF-16'), $length<<1) as $chunk) {
|
|
||||||
$chunk = mb_convert_encoding($chunk, 'UTF-8', 'UTF-16');
|
|
||||||
Assert::string($chunk);
|
|
||||||
$result []= $chunk;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Manually convert HTML to a message and a set of entities.
|
* Manually convert HTML to a message and a set of entities.
|
||||||
@ -222,7 +201,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function htmlEscape(string $what): string
|
public static function htmlEscape(string $what): string
|
||||||
{
|
{
|
||||||
return htmlspecialchars($what, ENT_QUOTES|ENT_SUBSTITUTE|ENT_XML1);
|
return EntityTools::htmlEscape($what);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Escape string for markdown.
|
* Escape string for markdown.
|
||||||
@ -231,51 +210,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function markdownEscape(string $what): string
|
public static function markdownEscape(string $what): string
|
||||||
{
|
{
|
||||||
return str_replace(
|
return EntityTools::markdownEscape($what);
|
||||||
[
|
|
||||||
'\\',
|
|
||||||
'_',
|
|
||||||
'*',
|
|
||||||
'[',
|
|
||||||
']',
|
|
||||||
'(',
|
|
||||||
')',
|
|
||||||
'~',
|
|
||||||
'`',
|
|
||||||
'>',
|
|
||||||
'#',
|
|
||||||
'+',
|
|
||||||
'-',
|
|
||||||
'=',
|
|
||||||
'|',
|
|
||||||
'{',
|
|
||||||
'}',
|
|
||||||
'.',
|
|
||||||
'!',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'\\\\',
|
|
||||||
'\\_',
|
|
||||||
'\\*',
|
|
||||||
'\\[',
|
|
||||||
'\\]',
|
|
||||||
'\\(',
|
|
||||||
'\\)',
|
|
||||||
'\\~',
|
|
||||||
'\\`',
|
|
||||||
'\\>',
|
|
||||||
'\\#',
|
|
||||||
'\\+',
|
|
||||||
'\\-',
|
|
||||||
'\\=',
|
|
||||||
'\\|',
|
|
||||||
'\\{',
|
|
||||||
'\\}',
|
|
||||||
'\\.',
|
|
||||||
'\\!',
|
|
||||||
],
|
|
||||||
$what
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Escape string for markdown codeblock.
|
* Escape string for markdown codeblock.
|
||||||
@ -284,7 +219,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function markdownCodeblockEscape(string $what): string
|
public static function markdownCodeblockEscape(string $what): string
|
||||||
{
|
{
|
||||||
return str_replace('```', '\\```', $what);
|
return EntityTools::markdownCodeblockEscape($what);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Escape string for markdown code section.
|
* Escape string for markdown code section.
|
||||||
@ -293,7 +228,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function markdownCodeEscape(string $what): string
|
public static function markdownCodeEscape(string $what): string
|
||||||
{
|
{
|
||||||
return str_replace('`', '\\`', $what);
|
return EntityTools::markdownCodeEscape($what);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Escape string for URL.
|
* Escape string for URL.
|
||||||
@ -302,7 +237,7 @@ abstract class StrTools extends Extension
|
|||||||
*/
|
*/
|
||||||
public static function markdownUrlEscape(string $what): string
|
public static function markdownUrlEscape(string $what): string
|
||||||
{
|
{
|
||||||
return str_replace(')', '\\)', $what);
|
return EntityTools::markdownUrlEscape($what);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Escape type name.
|
* Escape type name.
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"vimeo/psalm": "dev-master",
|
|
||||||
"ennexa/amp-update-cache": "dev-master",
|
"ennexa/amp-update-cache": "dev-master",
|
||||||
"phpunit/phpunit": "^9",
|
|
||||||
"amphp/php-cs-fixer-config": "v2.x-dev",
|
"amphp/php-cs-fixer-config": "v2.x-dev",
|
||||||
"slevomat/coding-standard": "^8.7",
|
"slevomat/coding-standard": "^8.7",
|
||||||
"squizlabs/php_codesniffer": "^3.7",
|
"squizlabs/php_codesniffer": "^3.7",
|
||||||
|
Loading…
Reference in New Issue
Block a user