mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added lost files
This commit is contained in:
parent
6253b25158
commit
79f21416c8
14 changed files with 586 additions and 0 deletions
0
aiogram/utils/exceptions/__init__.py
Normal file
0
aiogram/utils/exceptions/__init__.py
Normal file
5
aiogram/utils/exceptions/bad_request.py
Normal file
5
aiogram/utils/exceptions/bad_request.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from aiogram.utils.exceptions.base import DetailedTelegramAPIError
|
||||
|
||||
|
||||
class BadRequest(DetailedTelegramAPIError):
|
||||
pass
|
||||
40
aiogram/utils/exceptions/base.py
Normal file
40
aiogram/utils/exceptions/base.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from typing import ClassVar, List, Match, Optional, TypeVar
|
||||
|
||||
from aiogram.methods import TelegramMethod
|
||||
from aiogram.methods.base import TelegramType
|
||||
|
||||
ErrorType = TypeVar("ErrorType")
|
||||
|
||||
|
||||
class TelegramAPIError(Exception):
|
||||
url: Optional[str] = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
) -> None:
|
||||
self.method = method
|
||||
self.message = message
|
||||
|
||||
def render_description(self) -> str:
|
||||
return self.message
|
||||
|
||||
def __str__(self) -> str:
|
||||
message = [self.render_description()]
|
||||
if self.url:
|
||||
message.append(f"(background on this error at: {self.url})")
|
||||
return "\n".join(message)
|
||||
|
||||
|
||||
class DetailedTelegramAPIError(TelegramAPIError):
|
||||
patterns: ClassVar[List[str]]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
match: Match[str],
|
||||
) -> None:
|
||||
super().__init__(method=method, message=message)
|
||||
self.match: Match[str] = match
|
||||
0
aiogram/utils/exceptions/conflict.py
Normal file
0
aiogram/utils/exceptions/conflict.py
Normal file
5
aiogram/utils/exceptions/network.py
Normal file
5
aiogram/utils/exceptions/network.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from aiogram.utils.exceptions.base import DetailedTelegramAPIError
|
||||
|
||||
|
||||
class NetworkError(DetailedTelegramAPIError):
|
||||
pass
|
||||
5
aiogram/utils/exceptions/not_found.py
Normal file
5
aiogram/utils/exceptions/not_found.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from aiogram.utils.exceptions.base import DetailedTelegramAPIError
|
||||
|
||||
|
||||
class NotFound(DetailedTelegramAPIError):
|
||||
pass
|
||||
0
aiogram/utils/exceptions/server.py
Normal file
0
aiogram/utils/exceptions/server.py
Normal file
46
aiogram/utils/exceptions/special.py
Normal file
46
aiogram/utils/exceptions/special.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from typing import Optional
|
||||
|
||||
from aiogram.methods import TelegramMethod
|
||||
from aiogram.methods.base import TelegramType
|
||||
from aiogram.utils.exceptions.base import TelegramAPIError
|
||||
|
||||
|
||||
class RetryAfter(TelegramAPIError):
|
||||
url = "https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
retry_after: int,
|
||||
) -> None:
|
||||
super().__init__(method=method, message=message)
|
||||
self.retry_after = retry_after
|
||||
|
||||
def render_description(self) -> str:
|
||||
description = f"Flood control exceeded on method {type(self.method).__name__!r}"
|
||||
if chat_id := getattr(self.method, "chat_id", None):
|
||||
description += f" in chat {chat_id}"
|
||||
description += f". Retry in {self.retry_after} seconds."
|
||||
return description
|
||||
|
||||
|
||||
class MigrateToChat(TelegramAPIError):
|
||||
url = "https://core.telegram.org/bots/api#responseparameters"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
method: TelegramMethod[TelegramType],
|
||||
message: str,
|
||||
migrate_to_chat_id: int,
|
||||
) -> None:
|
||||
super().__init__(method=method, message=message)
|
||||
self.migrate_to_chat_id = migrate_to_chat_id
|
||||
|
||||
def render_message(self) -> Optional[str]:
|
||||
description = (
|
||||
f"The group has been migrated to a supergroup with id {self.migrate_to_chat_id}"
|
||||
)
|
||||
if chat_id := getattr(self.method, "chat_id", None):
|
||||
description += f" from {chat_id}"
|
||||
return description
|
||||
0
aiogram/utils/exceptions/unauthorized.py
Normal file
0
aiogram/utils/exceptions/unauthorized.py
Normal file
20
aiogram/utils/exceptions/util.py
Normal file
20
aiogram/utils/exceptions/util.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def mark_line(text: str, offset: int, length: int = 1) -> str:
|
||||
try:
|
||||
if offset > 0 and (new_line_pos := text[:offset].rindex("\n")):
|
||||
text = "..." + text[:new_line_pos]
|
||||
offset -= new_line_pos - 3
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if offset > 10:
|
||||
text = "..." + text[offset - 10 :]
|
||||
offset = 13
|
||||
|
||||
mark = " " * offset
|
||||
mark += "^" * length
|
||||
try:
|
||||
if new_line_pos := text[len(mark) :].index("\n"):
|
||||
text = text[:new_line_pos].rstrip() + "..."
|
||||
except ValueError:
|
||||
pass
|
||||
return text + "\n" + mark
|
||||
Loading…
Add table
Add a link
Reference in a new issue