mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Added shortcuts for ChatMemberUpdate event (#1234)
* Added shortcuts for ChatMemberUpdate event * Added changelog
This commit is contained in:
parent
baad0ebef2
commit
a1513ddb2d
22 changed files with 1343 additions and 3 deletions
68
.butcher/types/ChatMemberUpdated/aliases.yml
Normal file
68
.butcher/types/ChatMemberUpdated/aliases.yml
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
answer:
|
||||
method: sendMessage
|
||||
fill: &fill-answer
|
||||
chat_id: self.chat.id
|
||||
|
||||
answer_animation:
|
||||
method: sendAnimation
|
||||
fill: *fill-answer
|
||||
|
||||
answer_audio:
|
||||
method: sendAudio
|
||||
fill: *fill-answer
|
||||
|
||||
answer_contact:
|
||||
method: sendContact
|
||||
fill: *fill-answer
|
||||
|
||||
answer_document:
|
||||
method: sendDocument
|
||||
fill: *fill-answer
|
||||
|
||||
answer_game:
|
||||
method: sendGame
|
||||
fill: *fill-answer
|
||||
|
||||
answer_invoice:
|
||||
method: sendInvoice
|
||||
fill: *fill-answer
|
||||
|
||||
answer_location:
|
||||
method: sendLocation
|
||||
fill: *fill-answer
|
||||
|
||||
answer_media_group:
|
||||
method: sendMediaGroup
|
||||
fill: *fill-answer
|
||||
|
||||
answer_photo:
|
||||
method: sendPhoto
|
||||
fill: *fill-answer
|
||||
|
||||
answer_poll:
|
||||
method: sendPoll
|
||||
fill: *fill-answer
|
||||
|
||||
answer_dice:
|
||||
method: sendDice
|
||||
fill: *fill-answer
|
||||
|
||||
answer_sticker:
|
||||
method: sendSticker
|
||||
fill: *fill-answer
|
||||
|
||||
answer_venue:
|
||||
method: sendVenue
|
||||
fill: *fill-answer
|
||||
|
||||
answer_video:
|
||||
method: sendVideo
|
||||
fill: *fill-answer
|
||||
|
||||
answer_video_note:
|
||||
method: sendVideoNote
|
||||
fill: *fill-answer
|
||||
|
||||
answer_voice:
|
||||
method: sendVoice
|
||||
fill: *fill-answer
|
||||
2
CHANGES/1234.feature.rst
Normal file
2
CHANGES/1234.feature.rst
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Added new shortcuts for :class:`aiogram.types.chat_member_updated.aiogramChatMemberUpdated`
|
||||
to send message to chat that member joined/left.
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_animation`
|
||||
- :meth:`aiogram.types.message.Message.reply_animation`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_animation`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_audio`
|
||||
- :meth:`aiogram.types.message.Message.reply_audio`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_audio`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_contact`
|
||||
- :meth:`aiogram.types.message.Message.reply_contact`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_contact`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_dice`
|
||||
- :meth:`aiogram.types.message.Message.reply_dice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_dice`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_document`
|
||||
- :meth:`aiogram.types.message.Message.reply_document`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_document`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_game`
|
||||
- :meth:`aiogram.types.message.Message.reply_game`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_game`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_invoice`
|
||||
- :meth:`aiogram.types.message.Message.reply_invoice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_invoice`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_location`
|
||||
- :meth:`aiogram.types.message.Message.reply_location`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_location`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_media_group`
|
||||
- :meth:`aiogram.types.message.Message.reply_media_group`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_media_group`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer`
|
||||
- :meth:`aiogram.types.message.Message.reply`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_photo`
|
||||
- :meth:`aiogram.types.message.Message.reply_photo`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_photo`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_poll`
|
||||
- :meth:`aiogram.types.message.Message.reply_poll`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_poll`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_sticker`
|
||||
- :meth:`aiogram.types.message.Message.reply_sticker`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_sticker`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_venue`
|
||||
- :meth:`aiogram.types.message.Message.reply_venue`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_venue`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_video`
|
||||
- :meth:`aiogram.types.message.Message.reply_video`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_video`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_video_note`
|
||||
- :meth:`aiogram.types.message.Message.reply_video_note`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_video_note`
|
||||
|
|
|
|||
|
|
@ -50,3 +50,4 @@ As shortcut from received object
|
|||
|
||||
- :meth:`aiogram.types.message.Message.answer_voice`
|
||||
- :meth:`aiogram.types.message.Message.reply_voice`
|
||||
- :meth:`aiogram.types.chat_member_updated.ChatMemberUpdated.answer_voice`
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ class TestSendMessage:
|
|||
|
||||
async def test_force_reply(self):
|
||||
# https://github.com/aiogram/aiogram/issues/901
|
||||
print("::::", SendMessage.__pydantic_core_schema__)
|
||||
method = SendMessage(text="test", chat_id=42, reply_markup=ForceReply())
|
||||
assert isinstance(method.reply_markup, ForceReply)
|
||||
|
||||
|
|
|
|||
124
tests/test_api/test_types/test_chat_member_updated.py
Normal file
124
tests/test_api/test_types/test_chat_member_updated.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
import datetime
|
||||
from typing import Any, Dict, Type, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.methods import (
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDice,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
)
|
||||
from aiogram.types import (
|
||||
Chat,
|
||||
ChatMemberLeft,
|
||||
ChatMemberMember,
|
||||
ChatMemberUpdated,
|
||||
User,
|
||||
)
|
||||
from aiogram.types.message import Message
|
||||
|
||||
|
||||
class TestChatMemberUpdated:
|
||||
@pytest.mark.parametrize(
|
||||
"alias_for_method,kwargs,method_class",
|
||||
[
|
||||
["answer_animation", dict(animation="animation"), SendAnimation],
|
||||
["answer_audio", dict(audio="audio"), SendAudio],
|
||||
["answer_contact", dict(phone_number="+000000000000", first_name="Test"), SendContact],
|
||||
["answer_document", dict(document="document"), SendDocument],
|
||||
["answer_game", dict(game_short_name="game"), SendGame],
|
||||
[
|
||||
"answer_invoice",
|
||||
dict(
|
||||
title="title",
|
||||
description="description",
|
||||
payload="payload",
|
||||
provider_token="provider_token",
|
||||
start_parameter="start_parameter",
|
||||
currency="currency",
|
||||
prices=[],
|
||||
),
|
||||
SendInvoice,
|
||||
],
|
||||
["answer_location", dict(latitude=0.42, longitude=0.42), SendLocation],
|
||||
["answer_media_group", dict(media=[]), SendMediaGroup],
|
||||
["answer", dict(text="test"), SendMessage],
|
||||
["answer_photo", dict(photo="photo"), SendPhoto],
|
||||
["answer_poll", dict(question="Q?", options=[]), SendPoll],
|
||||
["answer_dice", dict(), SendDice],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
["answer_sticker", dict(sticker="sticker"), SendSticker],
|
||||
[
|
||||
"answer_venue",
|
||||
dict(
|
||||
latitude=0.42,
|
||||
longitude=0.42,
|
||||
title="title",
|
||||
address="address",
|
||||
),
|
||||
SendVenue,
|
||||
],
|
||||
["answer_video", dict(video="video"), SendVideo],
|
||||
["answer_video_note", dict(video_note="video_note"), SendVideoNote],
|
||||
["answer_voice", dict(voice="voice"), SendVoice],
|
||||
],
|
||||
)
|
||||
def test_answer_aliases(
|
||||
self,
|
||||
alias_for_method: str,
|
||||
kwargs: Dict[str, Any],
|
||||
method_class: Type[
|
||||
Union[
|
||||
SendAnimation,
|
||||
SendAudio,
|
||||
SendContact,
|
||||
SendDocument,
|
||||
SendGame,
|
||||
SendInvoice,
|
||||
SendLocation,
|
||||
SendMediaGroup,
|
||||
SendMessage,
|
||||
SendPhoto,
|
||||
SendPoll,
|
||||
SendSticker,
|
||||
SendSticker,
|
||||
SendVenue,
|
||||
SendVideo,
|
||||
SendVideoNote,
|
||||
SendVoice,
|
||||
]
|
||||
],
|
||||
):
|
||||
user = User(id=42, is_bot=False, first_name="Test")
|
||||
event = ChatMemberUpdated(
|
||||
chat=Chat(id=42, type="private"),
|
||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||
date=datetime.datetime.now(),
|
||||
old_chat_member=ChatMemberLeft(user=user),
|
||||
new_chat_member=ChatMemberMember(user=user),
|
||||
)
|
||||
|
||||
alias = getattr(event, alias_for_method)
|
||||
assert callable(alias)
|
||||
|
||||
api_method = alias(**kwargs)
|
||||
assert isinstance(api_method, method_class)
|
||||
|
||||
assert api_method.chat_id == event.chat.id
|
||||
|
||||
for key, value in kwargs.items():
|
||||
assert getattr(api_method, key) == value
|
||||
Loading…
Add table
Add a link
Reference in a new issue