Skip to content

Commit

Permalink
Add reply color, profile color and some known error, and add support …
Browse files Browse the repository at this point in the history
…multiple reaction

Signed-off-by: Yasir Aris M <git@yasirdev.my.id>
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
KurimuzonAkuma authored and wulan17 committed Dec 24, 2023
1 parent 726a622 commit 2543c0f
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 49 deletions.
1 change: 1 addition & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def get_title_list(s: str) -> list:
PeerUser
PeerChannel
BotInfo
ChatColor
""",
messages_media="""
Messages & Media
Expand Down
4 changes: 3 additions & 1 deletion compiler/errors/source/400_BAD_REQUEST.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ CHAT_TOO_BIG The chat is too big for this action
CODE_EMPTY The provided code is empty
CODE_HASH_INVALID The provided code hash invalid
CODE_INVALID The provided code is invalid (i.e. from email)
COLOR_INVALID The provided color is invalid
CONNECTION_API_ID_INVALID The provided API id is invalid
CONNECTION_APP_VERSION_EMPTY App version is empty
CONNECTION_DEVICE_MODEL_EMPTY The device model is empty
Expand Down Expand Up @@ -136,7 +137,8 @@ GAME_BOT_INVALID You cannot send that game with the current bot
GEO_POINT_INVALID Invalid geo point provided
GIF_CONTENT_TYPE_INVALID GIF content-type invalid
GIF_ID_INVALID The provided gif/animation id is invalid
GRAPH_INVALID_RELOAD Invalid graph token provided, please reload the stats and provide the updated token
GIFT_SLUG_EXPIRED The gift slug is expired
GRAPH_INVALID_RELOAD Invalid graph token provided,
GRAPH_OUTDATED_RELOAD The graph data is outdated
GROUPCALL_SSRC_DUPLICATE_MUCH Too many group call synchronization source duplicates
GROUPED_MEDIA_INVALID The album contains invalid media
Expand Down
1 change: 1 addition & 0 deletions compiler/errors/source/403_FORBIDDEN.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANNEL_PUBLIC_GROUP_NA The channel/supergroup is not available
CHAT_ADMIN_INVITE_REQUIRED You don't have rights to invite other users
CHAT_ADMIN_REQUIRED The method requires chat admin privileges
CHAT_FORBIDDEN You cannot write in this chat
CHAT_GUEST_SEND_FORBIDDEN You need to join the discussion group before commentingr
EDIT_BOT_INVITE_FORBIDDEN Bots' chat invite links can't be edited
INLINE_BOT_REQUIRED The action must be performed through an inline bot callback
MESSAGE_AUTHOR_REQUIRED You are not the author of this message
Expand Down
2 changes: 2 additions & 0 deletions compiler/errors/source/406_NOT_ACCEPTABLE.tsv
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
id message
AUTH_KEY_DUPLICATED The same authorization key (session file) was used in more than one place simultaneously. You must delete your session file and log in again with your phone number or bot token
CHANNEL_PRIVATE The channel/supergroup is not accessible
CHANNEL_TOO_LARGE Сhannel is too large to be deleted. Contact support for removal
FILEREF_UPGRADE_NEEDED The file reference has expired and you must use a refreshed one by obtaining the original media message
FRESH_CHANGE_ADMINS_FORBIDDEN You were just elected admin, you can't add or modify other admins yet
FRESH_CHANGE_PHONE_FORBIDDEN You can't change your phone number because your session was logged-in recently
FRESH_RESET_AUTHORISATION_FORBIDDEN You can't terminate other authorized sessions because the current was logged-in recently
GIFTCODE_NOT_ALLOWED Giftcode not allowed
PHONE_NUMBER_INVALID The phone number is invalid
PHONE_PASSWORD_FLOOD You have tried to log-in too many times
STICKERSET_INVALID The sticker set is invalid
Expand Down
4 changes: 4 additions & 0 deletions pyrogram/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from .next_code_type import NextCodeType
from .parse_mode import ParseMode
from .poll_type import PollType
from .profile_color import ProfileColor
from .reply_color import ReplyColor
from .sent_code_type import SentCodeType
from .stories_privacy_rules import StoriesPrivacyRules
from .story_privacy import StoryPrivacy
Expand All @@ -48,6 +50,8 @@
'NextCodeType',
'ParseMode',
'PollType',
'ProfileColor',
'ReplyColor',
'SentCodeType',
"StoriesPrivacyRules",
"StoryPrivacy",
Expand Down
72 changes: 72 additions & 0 deletions pyrogram/enums/profile_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrofork.
#
# Pyrofork is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrofork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.

from .auto_name import AutoName


class ProfileColor(AutoName):
"""Profile color enumeration used in :meth:`~pyrogram.Client.update_color` and :obj:`~pyrogram.types.ChatColor`."""

RED = 0
"Red color."

ORANGE = 1
"Orange color."

VIOLET = 2
"Violet color."

GREEN = 3
"Green color."

CYAN = 4
"Cyan color."

BLUE = 5
"Blue color."

PINK = 6
"Pink color."

GRAY = 7
"Gray color."

RED_LIGHT_RED = 8
"Red color with light red gradient."

ORANGE_LIGHT_ORANGE = 9
"Orange color with light red gradient."

VIOLET_LIGHT_VIOLET = 10
"Violet color with light violet gradient."

GREEN_LIGHT_GREEN = 11
"Green color with light green gradien."

CYAN_LIGHT_CYAN = 12
"Cyan color with light cyan gradient."

BLUE_LIGHT_BLUE = 13
"Blue color with light blue gradient."

PINK_LIGHT_PINK = 14
"Pink color with light pink gradient."

GRAY_LIGHT_GRAY = 15
"Gray color with light gray gradient."
94 changes: 94 additions & 0 deletions pyrogram/enums/reply_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrofork.
#
# Pyrofork is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrofork is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.

from .auto_name import AutoName


class ReplyColor(AutoName):
"""Reply color enumeration used in :meth:`~pyrogram.Client.update_color` and :obj:`~pyrogram.types.ChatColor`."""

RED = 0
"Red color."

ORANGE = 1
"Orange color."

VIOLET = 2
"Violet color."

GREEN = 3
"Green color."

CYAN = 4
"Cyan color."

BLUE = 5
"Blue color."

PINK = 6
"Pink color."

RED_DARK_RED = 7
"Red color with dark red stripes."

ORANGE_DARK_ORANGE = 8
"Orange color with dark orange stripes."

VIOLET_DARK_VIOLET = 9
"Violet color with dark violet stripes."

GREEN_DARK_GREEN = 10
"Green color with dark green stripes."

CYAN_DARK_CYAN = 11
"Cyan color with dark cyan stripes."

BLUE_DARK_BLUE = 12
"Blue color with dark blue stripes."

PINK_DARK_PINK = 13
"Pink color with dark pink stripes."

BLUE_WHITE_RED = 14
"Blue color with white and red stripes."

ORANGE_WHITE_GREEN = 15
"Orange color with white and green stripes."

GREEN_WHITE_RED = 16
"Green color with white and red stripes."

CYAN_WHITE_GREEN = 17
"Cyan color with white and red green."

CYAN_YELLOW_PINK = 18
"Cyan color with yellow and pink stripes."

VIOLET_YELLOW_ORANGE = 19
"Violet color with yellow and orange stripes."

BLUE_WHITE_ORANGE = 20
"Blue color with white and orange stripes."

DYNAMIC = 21
"""Secret color that cannot be set.
For now:
Red - If you use Telegram desktop.
Blue - If you are using Telegram android/ios.
"""
34 changes: 14 additions & 20 deletions pyrogram/methods/chats/update_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@

import pyrogram
from pyrogram import raw
from pyrogram import types

# account.updateColor flags: color:int background_emoji_id:flags.0?long = Bool;
# channels.updateColor flags: channel:InputChannel color:int background_emoji_id:flags.0?long = Updates;
from pyrogram import enums

class UpdateColor:
async def update_color(
self: "pyrogram.Client",
chat_id: Union[int, str],
color: int,
background_emoji_id: int = None,
) -> "types.Chat":
color: Union["enums.ReplyColor", "enums.ProfileColor"],
background_emoji_id: int = None
) -> bool:
"""Update color
.. include:: /_includes/usable-by/users.rst
Expand All @@ -40,41 +37,38 @@ async def update_color(
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
color (``int``):
Numeric color identifier.
color (:obj:`~pyrogram.enums.ReplyColor` | :obj:`~pyrogram.enums.ProfileColor`):
Color type.
Profile color can only be set for the user.
background_emoji_id (``int``, *optional*):
Unique identifier of the custom emoji.
Returns:
:obj:`~pyrogram.types.Chat`: On success, a chat object is returned.
``bool``: On success, in case the passed-in session is authorized, True is returned.
Example:
.. code-block:: python
await app.update_color(chat_id, 1)
await app.update_color(chat_id, enums.ReplyColor.RED)
"""

peer = await self.resolve_peer(chat_id)

if isinstance(peer, raw.types.InputPeerSelf):
await self.invoke(
r = await self.invoke(
raw.functions.account.UpdateColor(
color=color,
for_profile=isinstance(color, enums.ProfileColor),
color=color.value,
background_emoji_id=background_emoji_id
)
)

r = await self.invoke(raw.functions.users.GetUsers(id=[raw.types.InputPeerSelf()]))
chat = r[0]
else:
r = await self.invoke(
raw.functions.channels.UpdateColor(
channel=peer,
color=color,
color=color.value,
background_emoji_id=background_emoji_id
)
)
chat = r.chats[0]

return types.Chat._parse_chat(self, chat)
return bool(r)
26 changes: 21 additions & 5 deletions pyrogram/methods/messages/send_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union
from typing import Union, List

import pyrogram
from pyrogram import raw
Expand All @@ -28,7 +28,7 @@ async def send_reaction(
chat_id: Union[int, str],
message_id: int = None,
story_id: int = None,
emoji: str = "",
emoji: Union[int, str, List[Union[int, str]]] = None,
big: bool = False
) -> bool:
"""Send a reaction to a message.
Expand All @@ -45,9 +45,10 @@ async def send_reaction(
story_id (``int``, *optional*):
Identifier of the story.
emoji (``str``, *optional*):
emoji (``int`` | ``str`` | List of ``int`` | ``str``, *optional*):
Reaction emoji.
Pass "" as emoji (default) to retract the reaction.
Pass None as emoji (default) to retract the reaction.
Pass list of int or str to react multiple emojis.
big (``bool``, *optional*):
Pass True to show a bigger and longer reaction.
Expand All @@ -64,16 +65,31 @@ async def send_reaction(
await app.send_reaction(chat_id, message_id=message_id, emoji="🔥")
await app.send_reaction(chat_id, story_id=story_id, emoji="🔥")
# Send a multiple reactions
await app.send_reaction(chat_id, message_id=message_id, emoji=["🔥", "❤️"])
# Retract a reaction
await app.send_reaction(chat_id, message_id=message_id)
await app.send_reaction(chat_id, story_id=story_id)
"""
if isinstance(emoji, list):
emoji = [
raw.types.ReactionCustomEmoji(document_id=i)
if isinstance(i, int)
else raw.types.ReactionEmoji(emoticon=i)
for i in emoji
] if emoji else None
else:
if isinstance(emoji, int):
emoji = [raw.types.ReactionCustomEmoji(document_id=emoji)]
else:
emoji = [raw.types.ReactionEmoji(emoticon=emoji)] if emoji else None
if message_id is not None:
await self.invoke(
raw.functions.messages.SendReaction(
peer=await self.resolve_peer(chat_id),
msg_id=message_id,
reaction=[raw.types.ReactionEmoji(emoticon=emoji)] if emoji else None,
reaction=emoji,
big=big
)
)
Expand Down
2 changes: 2 additions & 0 deletions pyrogram/types/user_and_chats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .chat import Chat
from .chat_admin_with_invite_links import ChatAdminWithInviteLinks
from .chat_color import ChatColor
from .chat_event import ChatEvent
from .chat_event_filter import ChatEventFilter
from .chat_invite_link import ChatInviteLink
Expand Down Expand Up @@ -67,6 +68,7 @@
"ChatInviteLink",
"InviteLinkImporter",
"ChatAdminWithInviteLinks",
"ChatColor",
"ForumTopic",
"ForumTopicCreated",
"ForumTopicClosed",
Expand Down
Loading

0 comments on commit 2543c0f

Please sign in to comment.