mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Make some types hashable.
This commit is contained in:
parent
afd76cce9f
commit
44a24b243c
17 changed files with 151 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue