diff --git a/aiogram/types/animation.py b/aiogram/types/animation.py index 4498b9e1..dcdd4b18 100644 --- a/aiogram/types/animation.py +++ b/aiogram/types/animation.py @@ -17,3 +17,11 @@ class Animation(base.TelegramObject): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py index 88fe5b73..96a85fc1 100644 --- a/aiogram/types/audio.py +++ b/aiogram/types/audio.py @@ -14,3 +14,11 @@ class Audio(base.TelegramObject): title: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/callback_query.py b/aiogram/types/callback_query.py index 69f43a48..7ad12271 100644 --- a/aiogram/types/callback_query.py +++ b/aiogram/types/callback_query.py @@ -25,3 +25,11 @@ class CallbackQuery(base.TelegramObject): chat_instance: base.String = fields.Field() data: base.String = fields.Field() game_short_name: base.String = fields.Field() + + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other diff --git a/aiogram/types/chat.py b/aiogram/types/chat.py index e84d352f..37602d82 100644 --- a/aiogram/types/chat.py +++ b/aiogram/types/chat.py @@ -92,6 +92,17 @@ class Chat(base.TelegramObject): async def do(self, action): return await self.bot.send_chat_action(self.id, action) + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other + + def __int__(self): + return self.id + class ChatType(helper.Helper): """ diff --git a/aiogram/types/chat_member.py b/aiogram/types/chat_member.py index e74e84d6..96be7b76 100644 --- a/aiogram/types/chat_member.py +++ b/aiogram/types/chat_member.py @@ -29,6 +29,17 @@ class ChatMember(base.TelegramObject): can_send_other_messages: base.Boolean = fields.Field() can_add_web_page_previews: base.Boolean = fields.Field() + def __hash__(self): + return self.user.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.user.id == self.user.id + return self.user.id == other + + def __int__(self): + return self.user.id + class ChatMemberStatus(helper.Helper): """ diff --git a/aiogram/types/document.py b/aiogram/types/document.py index 5b3a3ed4..8caa6799 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -14,3 +14,11 @@ class Document(base.TelegramObject): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/file.py b/aiogram/types/file.py index 300816c8..01436666 100644 --- a/aiogram/types/file.py +++ b/aiogram/types/file.py @@ -30,3 +30,11 @@ class File(base.TelegramObject): :return: destination """ return await self.bot.download_file(self.file_path, destination, timeout, chunk_size, seek) + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/inline_query.py b/aiogram/types/inline_query.py index a6332990..c4050153 100644 --- a/aiogram/types/inline_query.py +++ b/aiogram/types/inline_query.py @@ -17,3 +17,11 @@ class InlineQuery(base.TelegramObject): location: Location = fields.Field(base=Location) query: base.String = fields.Field() offset: base.String = fields.Field() + + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 02315272..2a0fe754 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -1,7 +1,6 @@ import typing from aiogram.utils import helper -from aiogram.utils.exceptions import TelegramAPIError from . import base from . import fields from .audio import Audio @@ -202,6 +201,17 @@ class Message(base.TelegramObject): async def pin(self, disable_notification: bool = False): return await self.chat.pin_message(self.message_id, disable_notification) + def __hash__(self): + return self.message_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.message_id == self.message_id + return self.message_id == other + + def __int__(self): + return self.message_id + class ContentType(helper.Helper): """ diff --git a/aiogram/types/pre_checkout_query.py b/aiogram/types/pre_checkout_query.py index 5ed8fc28..b9bcbb12 100644 --- a/aiogram/types/pre_checkout_query.py +++ b/aiogram/types/pre_checkout_query.py @@ -24,3 +24,11 @@ class PreCheckoutQuery(base.TelegramObject): invoice_payload: base.String = fields.Field() shipping_option_id: base.String = fields.Field() order_info: OrderInfo = fields.Field(base=OrderInfo) + + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other \ No newline at end of file diff --git a/aiogram/types/shipping_query.py b/aiogram/types/shipping_query.py index 18b99b4d..0de540a3 100644 --- a/aiogram/types/shipping_query.py +++ b/aiogram/types/shipping_query.py @@ -14,3 +14,11 @@ class ShippingQuery(base.TelegramObject): from_user: User = fields.Field(alias='from', base=User) invoice_payload: base.String = fields.Field() shipping_address: ShippingAddress = fields.Field(base=ShippingAddress) + + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index 710704d4..5b68d458 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -18,3 +18,11 @@ class Sticker(base.TelegramObject): set_name: base.String = fields.Field() mask_position: MaskPosition = fields.Field(base=MaskPosition) file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/update.py b/aiogram/types/update.py index ea5a2779..210a3343 100644 --- a/aiogram/types/update.py +++ b/aiogram/types/update.py @@ -27,6 +27,17 @@ class Update(base.TelegramObject): shipping_query: ShippingQuery = fields.Field(base=ShippingQuery) pre_checkout_query: PreCheckoutQuery = fields.Field(base=PreCheckoutQuery) + def __hash__(self): + return self.update_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.update_id == self.update_id + return self.update_id == other + + def __int__(self): + return self.update_id + class AllowedUpdates(helper.Helper): """ diff --git a/aiogram/types/user.py b/aiogram/types/user.py index a0c99356..537c091e 100644 --- a/aiogram/types/user.py +++ b/aiogram/types/user.py @@ -73,3 +73,14 @@ class User(base.TelegramObject): async def get_user_profile_photos(self, offset=None, limit=None): return await self.bot.get_user_profile_photos(self.id, offset, limit) + + def __hash__(self): + return self.id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.id == self.id + return self.id == other + + def __int__(self): + return self.id diff --git a/aiogram/types/video.py b/aiogram/types/video.py index 636d6295..36fc0f90 100644 --- a/aiogram/types/video.py +++ b/aiogram/types/video.py @@ -16,3 +16,11 @@ class Video(base.TelegramObject): thumb: PhotoSize = fields.Field(base=PhotoSize) mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py index 69fb11a4..286ca762 100644 --- a/aiogram/types/video_note.py +++ b/aiogram/types/video_note.py @@ -14,3 +14,11 @@ class VideoNote(base.TelegramObject): duration: base.Integer = fields.Field() thumb: PhotoSize = fields.Field(base=PhotoSize) file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other diff --git a/aiogram/types/voice.py b/aiogram/types/voice.py index 192be48f..ba006bec 100644 --- a/aiogram/types/voice.py +++ b/aiogram/types/voice.py @@ -12,3 +12,11 @@ class Voice(base.TelegramObject): duration: base.Integer = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __hash__(self): + return self.file_id + + def __eq__(self, other): + if isinstance(other, type(self)): + return other.file_id == self.file_id + return self.file_id == other