Skip to content

Commit

Permalink
Update Userge to latest Pyrogram (UsergeTeam#224)
Browse files Browse the repository at this point in the history
* updating pyrogram

* updated pyrogram

* i didnt remove lines ?
  • Loading branch information
Krishna-Singhal authored Jan 9, 2021
1 parent 1f67cdd commit fa6a652
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 147 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ oauth2client
Pillow==7.1.0
psutil
pybase64
pyrogram==1.0.7
pyrogram==1.1.6
pySmartDL
python-dotenv
pytz
Expand Down
38 changes: 16 additions & 22 deletions userge/core/types/new/channel_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pyrogram.errors.exceptions import MessageTooLong

from userge import logging, Config
from userge.utils import SafeDict, get_file_id_and_ref, parse_buttons
from userge.utils import SafeDict, get_file_id_of_media, parse_buttons
from ..bound import message as _message # pylint: disable=unused-import
from ... import client as _client # pylint: disable=unused-import

Expand Down Expand Up @@ -80,8 +80,7 @@ async def log(self, text: str, name: str = '') -> int:
async def fwd_msg(self,
message: Union['_message.Message', 'RawMessage'],
name: str = '',
as_copy: bool = True,
remove_caption: bool = False) -> None:
as_copy: bool = True) -> None:
"""\nforward message to log channel.
Parameters:
Expand All @@ -97,12 +96,6 @@ async def fwd_msg(self,
that it appears as originally sent by you).
Defaults to True.
remove_caption (`bool`, *optional*):
If set to True and *as_copy* is enabled as well,
media captions are not preserved when copying the
message. Has no effect if *as_copy* is not enabled.
Defaults to False.
Returns:
None
"""
Expand All @@ -113,11 +106,14 @@ async def fwd_msg(self,
asyncio.get_event_loop().create_task(self.log("**Forwarding Message...**", name))
try:
# pylint: disable=protected-access
await message._client.forward_messages(chat_id=self._id,
if as_copy:
await message._client.copy_message(chat_id=self._id,
from_chat_id=message.chat.id,
message_ids=message.message_id,
as_copy=as_copy,
remove_caption=remove_caption)
message_id=message.message_id)
else:
await message._client.forward_messages(chat_id=self._id,
from_chat_id=message.chat.id,
message_ids=message.message_id)
except ValueError:
pass
else:
Expand All @@ -140,17 +136,16 @@ async def store(self,
message_id on success or None
"""
caption = caption or ''
file_id = file_ref = None
file_id = None
if message and message.caption:
caption = caption + message.caption.html
if message:
file_id, file_ref = get_file_id_and_ref(message)
if message and message.media and file_id and file_ref:
file_id = get_file_id_of_media(message)
if message and message.media and file_id:
if caption:
caption = self._string.format(caption.strip())
msg = await message.client.send_cached_media(chat_id=self._id,
file_id=file_id,
file_ref=file_ref,
caption=caption)
message_id = msg.message_id
else:
Expand All @@ -167,7 +162,7 @@ async def forward_stored(self,
"""\nforward stored message from log channel.
Parameters:
client (`Userge` | `usergeBot`):
client (`Userge` | `UsergeBot`):
Pass Userge or UsergeBot.
message_id (`int`):
Expand All @@ -193,7 +188,7 @@ async def forward_stored(self,
message = await client.get_messages(chat_id=self._id,
message_ids=message_id)
caption = ''
file_id = file_ref = None
file_id = None
if message.caption:
caption = message.caption.html.split('\n\n', maxsplit=1)[-1]
elif message.text:
Expand All @@ -205,13 +200,12 @@ async def forward_stored(self,
'chat': chat.title if chat.title else "this group",
'count': chat.members_count})
caption = caption.format_map(SafeDict(**u_dict))
file_id, file_ref = get_file_id_and_ref(message)
file_id = get_file_id_of_media(message)
caption, buttons = parse_buttons(caption)
if message.media and file_id and file_ref:
if message.media and file_id:
msg = await client.send_cached_media(
chat_id=chat_id,
file_id=file_id,
file_ref=file_ref,
caption=caption,
reply_to_message_id=reply_to_message_id,
reply_markup=buttons if client.is_bot and buttons else None)
Expand Down
8 changes: 6 additions & 2 deletions userge/core/types/new/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ async def _on_conversation(_, msg: RawMessage) -> None:
MessageHandler(
_on_conversation,
_filters.create(
lambda _, __, query: _CONV_DICT and query.chat
and (query.chat.id, client) in _CONV_DICT, 0)))
lambda _, __, query: _CONV_DICT and query.chat and (
query.chat.id, client
) in _CONV_DICT, 0
)
)
)

async def __aenter__(self) -> 'Conversation':
self._chat_id = int(self._chat) if isinstance(self._chat, int) else \
Expand Down
29 changes: 11 additions & 18 deletions userge/plugins/admin/gadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,17 @@ async def pin_msgs(message: Message):
""" pin & unpin message in groups """
chat_id = message.chat.id
flags = message.flags
silent_pin = '-s' in flags
disable_notification = False
if '-s' in flags:
disable_notification = True
unpin_pinned = '-u' in flags
if unpin_pinned:
try:
await message.client.unpin_chat_message(chat_id)
if message.reply_to_message:
await message.client.unpin_chat_message(
chat_id, message.reply_to_message.message_id)
else:
await message.client.unpin_all_chat_messages(chat_id)
await message.delete()
await CHANNEL.log(
f"#UNPIN\n\nCHAT: `{message.chat.title}` (`{chat_id}`)")
Expand All @@ -471,23 +477,11 @@ async def pin_msgs(message: Message):
r"`something went wrong! (⊙_⊙;)`"
"\n`do .help pin for more info..`\n\n"
f"**ERROR:** `{e_f}`")
elif silent_pin:
try:
message_id = message.reply_to_message.message_id
await message.client.pin_chat_message(
chat_id, message_id, disable_notification=True)
await message.delete()
await CHANNEL.log(
f"#PIN-SILENT\n\n{message.chat.title}` (`{chat_id}`)")
except Exception as e_f:
await message.edit(
r"`something went wrong! (⊙_⊙;)`"
"\n`do .help pin for more info..`\n\n"
f"**ERROR:** `{e_f}`")
else:
try:
message_id = message.reply_to_message.message_id
await message.client.pin_chat_message(chat_id, message_id)
await message.client.pin_chat_message(
chat_id, message_id, disable_notification=disable_notification)
await message.delete()
await CHANNEL.log(
f"#PIN\n\nCHAT: `{message.chat.title}` (`{chat_id}`)")
Expand Down Expand Up @@ -518,9 +512,8 @@ async def chatpic_func(message: Message):
if message.reply_to_message.photo:
try:
img_id = message.reply_to_message.photo.file_id
img_ref = message.reply_to_message.photo.file_ref
await message.client.set_chat_photo(
chat_id=chat_id, photo=img_id, file_ref=img_ref)
chat_id=chat_id, photo=img_id)
await message.delete()
await CHANNEL.log(
f"#GPIC-SET\n\nCHAT: `{message.chat.title}` (`{chat_id}`)")
Expand Down
Loading

0 comments on commit fa6a652

Please sign in to comment.