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