Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pyrogram #334

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugins/fun/autofastly/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os

from pyrogram import enums
from pyrogram.types import LinkPreviewOptions

from userge import userge, Message, filters, config, get_collection
from ...utils import ocr
Expand Down Expand Up @@ -45,7 +46,9 @@ async def autofastly(msg: Message):
"<code>Oops!!get the OCR API from</code> "
"<a href='https://eepurl.com/bOLOcf'>HERE</a> "
"<code>& add it to Heroku config vars</code> (<code>OCR_SPACE_API_KEY</code>)",
disable_web_page_preview=True,
link_preview_options=LinkPreviewOptions(
is_disabled=True
),
parse_mode=enums.ParseMode.HTML, del_in=0)
return

Expand Down
4 changes: 3 additions & 1 deletion plugins/misc/deezloader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import shutil
from pathlib import Path

from pyrogram.types import LinkPreviewOptions

import deezloader # pylint: disable=W0406
from deezloader.exceptions import NoDataApi

Expand Down Expand Up @@ -51,7 +53,7 @@ async def deezload(message: Message):
os.makedirs(TEMP_PATH)
await message.edit("Checking your Token.")
if ARL_TOKEN is None:
await message.edit(ARL_HELP, disable_web_page_preview=True)
await message.edit(ARL_HELP, link_preview_options=LinkPreviewOptions(is_disabled=True))
return
try:
loader = deezloader.Login(ARL_TOKEN)
Expand Down
8 changes: 7 additions & 1 deletion plugins/misc/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pySmartDL import SmartDL
from pyrogram.types import Message as PyroMessage
from pyrogram import enums
from pyrogram.types import LinkPreviewOptions

from userge import Message, config
from userge.utils import progress, humanbytes, extract_entities
Expand Down Expand Up @@ -112,7 +113,12 @@ async def url_download(message: Message, url: str) -> Tuple[str, int]:
humanbytes(total_length),
speed,
estimated_total_time)
await message.edit(progress_str, disable_web_page_preview=True)
await message.edit(
progress_str,
link_preview_options=LinkPreviewOptions(
is_disabled=True
)
)
await asyncio.sleep(config.Dynamic.EDIT_SLEEP_TIMEOUT)
if message.process_is_canceled:
raise ProcessCanceled
Expand Down
57 changes: 42 additions & 15 deletions plugins/misc/gdrive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from oauth2client.client import (
OAuth2Credentials, OAuth2WebServerFlow, HttpAccessTokenRefreshError, FlowExchangeError)

from pyrogram.types import LinkPreviewOptions

from userge import userge, Message, config, get_collection, pool
from userge.plugins.misc.download import url_download, tg_download
from userge.utils import humanbytes, time_formatter, is_url
Expand Down Expand Up @@ -621,7 +623,7 @@ async def setup(self) -> None:
reply_string += "send back "
reply_string += "<code>.gconf [auth_code or url]</code>"
await self._message.edit(
text=reply_string, disable_web_page_preview=True)
text=reply_string, link_preview_options=LinkPreviewOptions(is_disabled=True))

async def confirm_setup(self) -> None:
""" Finalize GDrive setup """
Expand Down Expand Up @@ -677,8 +679,11 @@ async def share(self) -> None:
_LOG.exception(h_e)
await self._message.err(h_e._get_reason()) # pylint: disable=protected-access
return
await self._message.edit(f"**Shareable Links**\n\n{out}",
disable_web_page_preview=True, log=__name__)
await self._message.edit(
f"**Shareable Links**\n\n{out}",
link_preview_options=LinkPreviewOptions(is_disabled=True),
log=__name__
)

@creds_dec
async def search(self) -> None:
Expand All @@ -692,7 +697,7 @@ async def search(self) -> None:
await self._message.err(h_e._get_reason()) # pylint: disable=protected-access
return
await self._message.edit_or_send_as_file(
out, disable_web_page_preview=True,
out, link_preview_options=LinkPreviewOptions(is_disabled=True),
caption=f"search results for `{self._message.filtered_input_str}`")

@creds_dec
Expand All @@ -710,8 +715,11 @@ async def make_folder(self) -> None:
_LOG.exception(h_e)
await self._message.err(h_e._get_reason()) # pylint: disable=protected-access
return
await self._message.edit(f"**Folder Created Successfully**\n\n{out}",
disable_web_page_preview=True, log=__name__)
await self._message.edit(
f"**Folder Created Successfully**\n\n{out}",
link_preview_options=LinkPreviewOptions(is_disabled=True),
log=__name__
)

@creds_dec
async def list_folder(self) -> None:
Expand All @@ -732,7 +740,10 @@ async def list_folder(self) -> None:
await self._message.err(h_e._get_reason()) # pylint: disable=protected-access
return
await self._message.edit_or_send_as_file(
out, disable_web_page_preview=True, caption=f"list results for `{file_id}`")
out,
link_preview_options=LinkPreviewOptions(is_disabled=True),
caption=f"list results for `{file_id}`"
)

@creds_dec
async def upload(self) -> None:
Expand Down Expand Up @@ -787,7 +798,11 @@ async def upload(self) -> None:
out = self._output
else:
out = "`failed to upload.. check logs?`"
await self._message.edit(out, disable_web_page_preview=True, log=__name__)
await self._message.edit(
out,
link_preview_options=LinkPreviewOptions(is_disabled=True),
log=__name__
)

@creds_dec
async def download(self) -> None:
Expand All @@ -811,7 +826,13 @@ async def download(self) -> None:
out = self._output
else:
out = "`failed to download.. check logs?`"
await self._message.edit(out, disable_web_page_preview=True, log=__name__)
await self._message.edit(
out,
link_preview_options=LinkPreviewOptions(
is_disabled=True
),
log=__name__
)

@creds_dec
async def copy(self) -> None:
Expand All @@ -838,7 +859,11 @@ async def copy(self) -> None:
out = self._output
else:
out = "`failed to copy.. check logs?`"
await self._message.edit(out, disable_web_page_preview=True, log=__name__)
await self._message.edit(
out,
link_preview_options=LinkPreviewOptions(is_disabled=True),
log=__name__
)

@creds_dec
async def move(self) -> None:
Expand Down Expand Up @@ -897,7 +922,7 @@ async def get(self) -> None:
return
out = f"**I Found these Details for** `{file_id}`\n\n{meta_data}"
await self._message.edit_or_send_as_file(
out, disable_web_page_preview=True,
out, link_preview_options=LinkPreviewOptions(is_disabled=True),
caption=f"metadata for `{file_id}`")

@creds_dec
Expand All @@ -913,7 +938,7 @@ async def get_perms(self) -> None:
return
out = f"**I Found these Permissions for** `{file_id}`\n\n{out}"
await self._message.edit_or_send_as_file(
out, disable_web_page_preview=True,
out, link_preview_options=LinkPreviewOptions(is_disabled=True),
caption=f"view perm results for `{file_id}`")

@creds_dec
Expand All @@ -928,7 +953,7 @@ async def set_perms(self) -> None:
await self._message.err(h_e._get_reason()) # pylint: disable=protected-access
else:
out = f"**Set Permissions successfully for** `{file_id}`\n\n{link}"
await self._message.edit(out, disable_web_page_preview=True)
await self._message.edit(out, link_preview_options=LinkPreviewOptions(is_disabled=True))

@creds_dec
async def del_perms(self) -> None:
Expand All @@ -943,7 +968,7 @@ async def del_perms(self) -> None:
return
out = f"**Removed These Permissions successfully from** `{file_id}`\n\n{out}"
await self._message.edit_or_send_as_file(
out, disable_web_page_preview=True,
out, link_preview_options=LinkPreviewOptions(is_disabled=True),
caption=f"removed perm results for `{file_id}`")


Expand All @@ -960,7 +985,9 @@ async def gsetup_(message: Message):
else:
await message.edit(
"`G_DRIVE_CLIENT_ID` and `G_DRIVE_CLIENT_SECRET` not found!\n"
f"[Read this]({link}) to know more.", disable_web_page_preview=True)
f"[Read this]({link}) to know more.",
link_preview_options=LinkPreviewOptions(is_disabled=True)
)


@userge.on_cmd("gconf", about={
Expand Down
6 changes: 4 additions & 2 deletions plugins/misc/parser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import requests
from bs4 import BeautifulSoup

from pyrogram.types import LinkPreviewOptions

from userge import Message, userge, pool
from .. import parser

Expand Down Expand Up @@ -148,7 +150,7 @@ async def gdtot(message: Message):
f'Date: {info[1].text.strip()}\n'
f'\nGDrive-URL:\n{gdrive_url}'
)
await message.edit(out, disable_web_page_preview=True)
await message.edit(out, link_preview_options=LinkPreviewOptions(is_disabled=True))
except Exception:
await message.err("Unable To parse Link")

Expand Down Expand Up @@ -177,4 +179,4 @@ async def appdrive(message: Message):
'Drive_Link: '
f'{res.get("gdrive_link", "Something Went Wrong")}'
)
await message.edit(output, disable_web_page_preview=True)
await message.edit(output, link_preview_options=LinkPreviewOptions(is_disabled=True))
4 changes: 2 additions & 2 deletions plugins/misc/telegraph/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from aiofiles import os
from html_telegraph_poster import TelegraphPoster
from telegraph import upload_file

from pyrogram.types import LinkPreviewOptions
from userge import userge, Message, config, pool
from userge.utils import progress

Expand Down Expand Up @@ -71,7 +71,7 @@ async def telegraph_(message: Message):
header = "Pasted content by @theuserge"
t_url = await pool.run_in_thread(post_to_telegraph)(header, text.replace("\n", "<br>"))
jv_text = f"**[Here Your Telegra.ph Link!]({t_url})**"
await message.edit(text=jv_text, disable_web_page_preview=True)
await message.edit(text=jv_text, link_preview_options=LinkPreviewOptions(is_disabled=True))
return
dl_loc = await message.client.download_media(
message=message.reply_to_message,
Expand Down
5 changes: 2 additions & 3 deletions plugins/misc/zippyshare/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
# plugin by @aryanvikash

import re

import requests

from pyrogram.types import LinkPreviewOptions
from userge import userge, Message, pool


Expand All @@ -32,7 +31,7 @@ async def zippyshare(message: Message):
await message.edit(f"**Original** : {url}\n**FileName** : `{fname}`\n"
f"**DirectLink** : {direct_url}\n\n"
"**[HINT]** : use `.download [directLink]`",
disable_web_page_preview=True)
link_preview_options=LinkPreviewOptions(is_disabled=True))
except Exception as z_e: # pylint: disable=broad-except
await message.edit(f"`{z_e}`")

Expand Down
38 changes: 25 additions & 13 deletions plugins/tools/alive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
FileIdInvalid, FileReferenceEmpty, BadRequest, ChannelInvalid, MediaEmpty
)
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import LinkPreviewOptions

from userge import userge, Message, pool, config, versions as ver, logging
from userge.utils import get_file_id_of_media, get_custom_import_re
Expand Down Expand Up @@ -51,7 +52,13 @@ async def _alive(message: Message):

alive_text, markup = await _get_text_and_markup(message)
if _MSG_ID == "text_format":
return await message.edit(alive_text, disable_web_page_preview=True, reply_markup=markup)
return await message.edit(
alive_text,
link_preview_options=LinkPreviewOptions(
is_disabled=True
),
reply_markup=markup
)
await message.delete()
try:
await _send_alive(message, alive_text, markup)
Expand Down Expand Up @@ -118,10 +125,12 @@ async def _send_alive(message: Message,
await _send_telegraph(message, text, reply_markup)
else:
try:
await message.client.send_cached_media(chat_id=message.chat.id,
file_id=_LOGO_ID,
caption=text,
reply_markup=should_mark)
await message.client.send_cached_media(
chat_id=message.chat.id,
file_id=_LOGO_ID,
caption=text,
reply_markup=should_mark
)
if _IS_STICKER:
raise ChatSendMediaForbidden
except SlowmodeWait as s_m:
Expand All @@ -134,10 +143,14 @@ async def _send_alive(message: Message,
await _refresh_id(message)
return await _send_alive(message, text, reply_markup, recurs_count + 1)
except (ChatSendMediaForbidden, Forbidden):
await message.client.send_message(chat_id=message.chat.id,
text=text,
disable_web_page_preview=True,
reply_markup=should_mark)
await message.client.send_message(
chat_id=message.chat.id,
text=text,
link_preview_options=LinkPreviewOptions(
is_disabled=True
),
reply_markup=should_mark
)


async def _refresh_id(message: Message) -> None:
Expand All @@ -147,10 +160,9 @@ async def _refresh_id(message: Message) -> None:
except (ChannelInvalid, PeerIdInvalid, ValueError):
_set_data(True)
return await _refresh_id(message)
else:
if media.sticker:
_IS_STICKER = True
_LOGO_ID = get_file_id_of_media(media)
if media.sticker:
_IS_STICKER = True
_LOGO_ID = get_file_id_of_media(media)


def _set_data(errored: bool = False) -> None:
Expand Down
8 changes: 7 additions & 1 deletion plugins/utils/admins/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from userge import userge, Message
from pyrogram import enums
from pyrogram.types import LinkPreviewOptions


@userge.on_cmd("admins", about={
Expand Down Expand Up @@ -57,4 +58,9 @@ async def mentionadmins(message: Message):
mentions += " " + str(e) + "\n"
await message.delete()
await message.client.send_message(
chat_id=message.chat.id, text=mentions, disable_web_page_preview=True)
chat_id=message.chat.id,
text=mentions,
link_preview_options=LinkPreviewOptions(
is_disabled=True
)
)
4 changes: 2 additions & 2 deletions plugins/utils/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import aiohttp
import bs4

from pyrogram.types import LinkPreviewOptions
from userge import userge, Message


Expand Down Expand Up @@ -57,7 +57,7 @@ async def app(message: Message):
app_details += f"`Developer :` [{app_dev}]({app_dev_link})\n"
app_details += f"`Rating :` {app_rating} ⭐️\n"
app_details += f"`Features :` [View in Play Store]({app_link})"
await message.edit(app_details, disable_web_page_preview=False)
await message.edit(app_details, link_preview_options=LinkPreviewOptions(is_disabled=True))
except IndexError:
await message.edit("No result found in search. Please enter **Valid app name**")
except Exception as err:
Expand Down
Loading