From 63fe2736a9c011223269c895a88ac132e93e1c47 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Thu, 9 Feb 2023 23:42:42 +0000
Subject: [PATCH 1/2] Update dependency python-telegram-bot to v20
---
requirements.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/requirements.txt b/requirements.txt
index 220d6b13..7d0dd893 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -19,7 +19,7 @@ beautifulsoup4
requests
sqlalchemy==1.3.23
telethon==1.24.0
-python-telegram-bot==13.13
+python-telegram-bot==20.1
pyrogram==2.0.40
psycopg2-binary
feedparser
From 801ca6be8b1579128667fadb2ca69f345aecc265 Mon Sep 17 00:00:00 2001
From: Prince <90893568+Awesome-Prince@users.noreply.github.com>
Date: Thu, 9 Feb 2023 23:43:10 +0000
Subject: [PATCH 2/2] Auto Code Formatting
---
NekoRobot/__main__.py | 3 +-
NekoRobot/modules/anime.py | 1 -
NekoRobot/modules/announcements.py | 1 -
NekoRobot/modules/backups.py | 1 -
NekoRobot/modules/blacklistusers.py | 1 -
NekoRobot/modules/connection.py | 7 --
NekoRobot/modules/crypto.py | 1 -
NekoRobot/modules/dbcleanup.py | 1 -
NekoRobot/modules/debug.py | 1 -
NekoRobot/modules/global_bans.py | 2 -
NekoRobot/modules/guess.py | 1 -
NekoRobot/modules/helper_funcs/handlers.py | 1 -
NekoRobot/modules/helper_funcs/miku_misc.py | 1 -
NekoRobot/modules/helper_funcs/msg_types.py | 1 -
.../helper_funcs/telethn/chatstatus.py | 1 -
NekoRobot/modules/imdb.py | 2 -
NekoRobot/modules/inline.py | 1 -
NekoRobot/modules/meme.py | 1 -
NekoRobot/modules/ping.py | 1 -
NekoRobot/modules/reporting.py | 1 -
NekoRobot/modules/sql/cleaner_sql.py | 2 -
NekoRobot/modules/userinfo.py | 4 -
NekoRobot/modules/welcome.py | 3 -
NekoRobot/modules/wish.py | 1 -
NekoRobot/modules/zombie.py | 2 +-
NekoRobot/services/sections.py | 1 -
NekoRobot/services/tasks.py | 1 -
NekoRobot/utils/errors.py | 11 --
NekoRobot/utils/pluginhelpers.py | 116 ------------------
29 files changed, 2 insertions(+), 169 deletions(-)
diff --git a/NekoRobot/__main__.py b/NekoRobot/__main__.py
index b077fbae..1222e64c 100644
--- a/NekoRobot/__main__.py
+++ b/NekoRobot/__main__.py
@@ -346,7 +346,7 @@ def error_handler(update: Update, context: CallbackContext):
def error_callback(_, context: CallbackContext):
try:
raise context.error
- except (BadRequest):
+ except BadRequest:
pass
# remove update.message.chat_id from conversation list
except TimedOut:
@@ -465,7 +465,6 @@ def get_help(update: Update, context: CallbackContext) -> None:
# ONLY send help in PM
if chat.type != chat.PRIVATE:
-
update.effective_message.reply_photo(
HELP_IMG,
HELP_MSG,
diff --git a/NekoRobot/modules/anime.py b/NekoRobot/modules/anime.py
index 29af53a1..dd2c1396 100644
--- a/NekoRobot/modules/anime.py
+++ b/NekoRobot/modules/anime.py
@@ -526,7 +526,6 @@ def site_search(update: Update, context: CallbackContext, site: str):
result = f"Search results for {html.escape(search_query)}
on AnimeKayo
: \n"
for entry in search_result:
-
if entry.text.strip() == "Nothing Found":
result = f"No result found for {html.escape(search_query)}
on AnimeKayo
"
more_results = False
diff --git a/NekoRobot/modules/announcements.py b/NekoRobot/modules/announcements.py
index d52378aa..9edc758f 100644
--- a/NekoRobot/modules/announcements.py
+++ b/NekoRobot/modules/announcements.py
@@ -48,7 +48,6 @@ def chatmemberupdates(update: Update, context: CallbackContext) -> Optional[str]
cause_name = update.chat_member.from_user.mention_html()
member_name = update.chat_member.new_chat_member.user.mention_html()
if oldtitle != newtitle:
-
if str(update.chat_member.from_user.id) == str(bot.id):
return "" # we handle these in their respective modules
if oldtitle is None:
diff --git a/NekoRobot/modules/backups.py b/NekoRobot/modules/backups.py
index db55aec6..44b4287d 100644
--- a/NekoRobot/modules/backups.py
+++ b/NekoRobot/modules/backups.py
@@ -135,7 +135,6 @@ def import_data(update, context):
# TODO: some of that link logic
# NOTE: consider default permissions stuff?
if conn:
-
text = f"Backup fully restored on *{chat_name}*."
else:
text = "Backup fully restored"
diff --git a/NekoRobot/modules/blacklistusers.py b/NekoRobot/modules/blacklistusers.py
index ce5a28c5..87028364 100644
--- a/NekoRobot/modules/blacklistusers.py
+++ b/NekoRobot/modules/blacklistusers.py
@@ -85,7 +85,6 @@ def unbl_user(update: Update, context: CallbackContext) -> str:
message.reply_text("I can't seem to find this user.")
return ""
if sql.is_user_blacklisted(user_id):
-
sql.unblacklist_user(user_id)
message.reply_text("*notices user*")
return f"#UNBLACKLIST\nAdmin: {mention_html(user.id, html.escape(user.first_name))}\nUser: {mention_html(target_user.id, html.escape(target_user.first_name))}"
diff --git a/NekoRobot/modules/connection.py b/NekoRobot/modules/connection.py
index 68c4db39..f47038e6 100644
--- a/NekoRobot/modules/connection.py
+++ b/NekoRobot/modules/connection.py
@@ -41,7 +41,6 @@
@user_admin
@typing_action
def allow_connections(update, context) -> str:
-
chat = update.effective_chat
args = context.args
@@ -87,7 +86,6 @@ def allow_connections(update, context) -> str:
@typing_action
def connection_chat(update, context):
-
chat = update.effective_chat
user = update.effective_user
@@ -111,7 +109,6 @@ def connection_chat(update, context):
@typing_action
def connect_chat(update, context):
-
chat = update.effective_chat
user = update.effective_user
if update.effective_chat.type == "private":
@@ -273,7 +270,6 @@ def connect_chat(update, context):
def disconnect_chat(update, context):
-
if update.effective_chat.type == "private":
if disconnection_status := sql.disconnect(
update.effective_message.from_user.id
@@ -292,7 +288,6 @@ def connected(bot: Bot, update: Update, chat, user_id, need_admin=True):
user = update.effective_user
if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
-
conn_id = sql.get_connected_chat(user_id).chat_id
getstatusadmin = bot.get_chat_member(
conn_id,
@@ -353,7 +348,6 @@ def connected(bot: Bot, update: Update, chat, user_id, need_admin=True):
def help_connect_chat(update, context):
-
context.args
if update.effective_message.chat.type != "private":
@@ -363,7 +357,6 @@ def help_connect_chat(update, context):
def connect_button(update, context):
-
query = update.callback_query
chat = update.effective_chat
user = update.effective_user
diff --git a/NekoRobot/modules/crypto.py b/NekoRobot/modules/crypto.py
index ff795764..67244f12 100644
--- a/NekoRobot/modules/crypto.py
+++ b/NekoRobot/modules/crypto.py
@@ -28,7 +28,6 @@ def section(
indent: int = 2,
underline: bool = False,
) -> str:
-
text = (bold_ul(title) + n) if underline else bold(title) + n
for key, value in body.items():
diff --git a/NekoRobot/modules/dbcleanup.py b/NekoRobot/modules/dbcleanup.py
index 56726e81..389f8b92 100644
--- a/NekoRobot/modules/dbcleanup.py
+++ b/NekoRobot/modules/dbcleanup.py
@@ -19,7 +19,6 @@ def get_invalid_chats(update: Update, context: CallbackContext, remove: bool = F
progress_message = None
for chat in chats:
-
if ((100 * chats.index(chat)) / len(chats)) > progress:
progress_bar = f"{progress}% completed in getting invalid chats."
if progress_message:
diff --git a/NekoRobot/modules/debug.py b/NekoRobot/modules/debug.py
index 5845e97c..49c7daa8 100644
--- a/NekoRobot/modules/debug.py
+++ b/NekoRobot/modules/debug.py
@@ -59,7 +59,6 @@ def logs(update: Update, context: CallbackContext):
return
user = update.effective_user
with open("log.txt", "rb") as f:
-
context.bot.send_document(document=f, filename=f.name, chat_id=user.id)
diff --git a/NekoRobot/modules/global_bans.py b/NekoRobot/modules/global_bans.py
index 180ba26c..2d313d94 100644
--- a/NekoRobot/modules/global_bans.py
+++ b/NekoRobot/modules/global_bans.py
@@ -129,7 +129,6 @@ def gban(update: Update, context: CallbackContext):
return
if sql.is_user_gbanned(user_id):
-
if not reason:
message.reply_text(
"This user is already gbanned; I'd change the reason, but you haven't given me one..."
@@ -394,7 +393,6 @@ def gbanlist(update: Update, context: CallbackContext):
def check_and_ban(update, user_id, should_message=True):
-
chat = update.effective_chat # type: Optional[Chat]
try:
sw_ban = sw.get_ban(int(user_id))
diff --git a/NekoRobot/modules/guess.py b/NekoRobot/modules/guess.py
index 73cdb8d7..c7aa5bb9 100644
--- a/NekoRobot/modules/guess.py
+++ b/NekoRobot/modules/guess.py
@@ -7,7 +7,6 @@
@neko.on(events.NewMessage(pattern="/guess ?(.*)"))
async def wish(e):
-
if e.is_reply:
mm = random.randint(1, 100)
lol = await e.get_reply_message()
diff --git a/NekoRobot/modules/helper_funcs/handlers.py b/NekoRobot/modules/helper_funcs/handlers.py
index 62aae50d..09974d6b 100644
--- a/NekoRobot/modules/helper_funcs/handlers.py
+++ b/NekoRobot/modules/helper_funcs/handlers.py
@@ -81,7 +81,6 @@ def check_update(self, update):
if len(fst_word) > 1 and any(
fst_word.startswith(start) for start in CMD_STARTERS
):
-
args = message.text.split()[1:]
command = fst_word[1:].split("@")
command.append(message.bot.username)
diff --git a/NekoRobot/modules/helper_funcs/miku_misc.py b/NekoRobot/modules/helper_funcs/miku_misc.py
index 5a08396b..9568eb28 100644
--- a/NekoRobot/modules/helper_funcs/miku_misc.py
+++ b/NekoRobot/modules/helper_funcs/miku_misc.py
@@ -102,7 +102,6 @@ def article(
reply_markup: InlineKeyboardMarkup = None,
disable_web_page_preview: bool = False,
) -> InlineQueryResultArticle:
-
return InlineQueryResultArticle(
id=uuid4(),
title=title,
diff --git a/NekoRobot/modules/helper_funcs/msg_types.py b/NekoRobot/modules/helper_funcs/msg_types.py
index 59abfb18..6e59fbb1 100644
--- a/NekoRobot/modules/helper_funcs/msg_types.py
+++ b/NekoRobot/modules/helper_funcs/msg_types.py
@@ -166,7 +166,6 @@ def get_welcome_type(msg: Message):
def get_filter_type(msg: Message):
-
if not msg.reply_to_message and msg.text and len(msg.text.split()) >= 3:
content = None
text = msg.text.split(None, 2)[2]
diff --git a/NekoRobot/modules/helper_funcs/telethn/chatstatus.py b/NekoRobot/modules/helper_funcs/telethn/chatstatus.py
index 2aa563f3..2150613f 100644
--- a/NekoRobot/modules/helper_funcs/telethn/chatstatus.py
+++ b/NekoRobot/modules/helper_funcs/telethn/chatstatus.py
@@ -118,7 +118,6 @@ async def can_add_admins(message):
async def can_delete_messages(message):
-
if message.is_private:
return True
if message.chat.admin_rights:
diff --git a/NekoRobot/modules/imdb.py b/NekoRobot/modules/imdb.py
index 89e596b9..6402bb92 100644
--- a/NekoRobot/modules/imdb.py
+++ b/NekoRobot/modules/imdb.py
@@ -13,7 +13,6 @@
async def is_register_admin(chat, user):
if isinstance(chat, (types.InputPeerChannel, types.InputChannel)):
-
return isinstance(
(
await tbot(functions.channels.GetParticipantRequest(chat, user))
@@ -21,7 +20,6 @@ async def is_register_admin(chat, user):
(types.ChannelParticipantAdmin, types.ChannelParticipantCreator),
)
if isinstance(chat, types.InputPeerChat):
-
ui = await tbot.get_peer_id(user)
ps = (
await tbot(functions.messages.GetFullChatRequest(chat.chat_id))
diff --git a/NekoRobot/modules/inline.py b/NekoRobot/modules/inline.py
index 6342e29a..3ab03c53 100644
--- a/NekoRobot/modules/inline.py
+++ b/NekoRobot/modules/inline.py
@@ -472,7 +472,6 @@ def media_query(query: str, update: Update, context: CallbackContext) -> None:
)
)
except Exception as e:
-
kb = InlineKeyboardMarkup(
[
[
diff --git a/NekoRobot/modules/meme.py b/NekoRobot/modules/meme.py
index 920f1a70..57f94163 100644
--- a/NekoRobot/modules/meme.py
+++ b/NekoRobot/modules/meme.py
@@ -162,7 +162,6 @@ def slap(update: Update, context: CallbackContext):
return
if user_id:
-
slapped_user = bot.get_chat(user_id)
user1 = curr_user
user2 = html.escape(slapped_user.first_name)
diff --git a/NekoRobot/modules/ping.py b/NekoRobot/modules/ping.py
index 8c653b8f..6f6c23c3 100644
--- a/NekoRobot/modules/ping.py
+++ b/NekoRobot/modules/ping.py
@@ -71,7 +71,6 @@ def ping_func(to_ping: List[str]) -> List[str]:
ping_result = []
for each_ping in to_ping:
-
start_time = time.time()
site_to_ping = sites_list[each_ping]
r = requests.get(site_to_ping)
diff --git a/NekoRobot/modules/reporting.py b/NekoRobot/modules/reporting.py
index 95bd687b..4902172f 100644
--- a/NekoRobot/modules/reporting.py
+++ b/NekoRobot/modules/reporting.py
@@ -121,7 +121,6 @@ def report(update: Update, context: CallbackContext) -> str:
return ""
if chat.username and chat.type == Chat.SUPERGROUP:
-
reported = f"{mention_html(user.id, user.first_name)} reported {mention_html(reported_user.id, reported_user.first_name)} to the admins!"
msg = (
diff --git a/NekoRobot/modules/sql/cleaner_sql.py b/NekoRobot/modules/sql/cleaner_sql.py
index 235e515a..e913ae72 100644
--- a/NekoRobot/modules/sql/cleaner_sql.py
+++ b/NekoRobot/modules/sql/cleaner_sql.py
@@ -99,7 +99,6 @@ def chat_ignore_command(chat_id, ignore):
ignored = SESSION.query(CleanerBlueTextChat).get((str(chat_id), ignore))
if not ignored:
-
if str(chat_id) not in CLEANER_CHATS:
CLEANER_CHATS.setdefault(
str(chat_id), {"setting": False, "commands": set()}
@@ -121,7 +120,6 @@ def chat_unignore_command(chat_id, unignore):
unignored = SESSION.query(CleanerBlueTextChat).get((str(chat_id), unignore))
if unignored:
-
if str(chat_id) not in CLEANER_CHATS:
CLEANER_CHATS.setdefault(
str(chat_id), {"setting": False, "commands": set()}
diff --git a/NekoRobot/modules/userinfo.py b/NekoRobot/modules/userinfo.py
index d03148f4..4b8a20aa 100644
--- a/NekoRobot/modules/userinfo.py
+++ b/NekoRobot/modules/userinfo.py
@@ -97,7 +97,6 @@ def hpmanager(user):
total_hp = (get_user_num_chats(user.id) + 10) * 10
if not is_user_gbanned(user.id):
-
# Assign new var `new_hp` since we need `total_hp` in
# end to calculate percentage.
new_hp = total_hp
@@ -150,9 +149,7 @@ def get_id(update: Update, context: CallbackContext):
user_id = extract_user(msg, args)
if user_id:
-
if msg.reply_to_message and msg.reply_to_message.forward_from:
-
user1 = message.reply_to_message.from_user
user2 = message.reply_to_message.forward_from
@@ -164,7 +161,6 @@ def get_id(update: Update, context: CallbackContext):
)
else:
-
user = bot.get_chat(user_id)
msg.reply_text(
f"{html.escape(user.first_name)}'s id is {user.id}
.",
diff --git a/NekoRobot/modules/welcome.py b/NekoRobot/modules/welcome.py
index 4adc1875..73087fe7 100644
--- a/NekoRobot/modules/welcome.py
+++ b/NekoRobot/modules/welcome.py
@@ -160,7 +160,6 @@ def new_member(update: Update, context: CallbackContext):
new_members = update.effective_message.new_chat_members
for new_mem in new_members:
-
welcome_log = None
res = None
sent = None
@@ -174,7 +173,6 @@ def new_member(update: Update, context: CallbackContext):
return
if should_welc:
-
reply = update.message.message_id
cleanserv = sql.clean_service(chat.id)
# Clean service welcome
@@ -502,7 +500,6 @@ def left_member(update: Update, context: CallbackContext):
left_mem = update.effective_message.left_chat_member
if left_mem:
-
# Thingy for spamwatched users
if sw is not None:
sw_ban = sw.get_ban(left_mem.id)
diff --git a/NekoRobot/modules/wish.py b/NekoRobot/modules/wish.py
index 53715ac4..c32d89ca 100644
--- a/NekoRobot/modules/wish.py
+++ b/NekoRobot/modules/wish.py
@@ -7,7 +7,6 @@
@neko.on(events.NewMessage(pattern="/wish ?(.*)"))
async def wish(e):
-
if e.is_reply:
mm = random.randint(1, 100)
lol = await e.get_reply_message()
diff --git a/NekoRobot/modules/zombie.py b/NekoRobot/modules/zombie.py
index 2e13be22..c2ba4ab7 100644
--- a/NekoRobot/modules/zombie.py
+++ b/NekoRobot/modules/zombie.py
@@ -60,6 +60,7 @@
OFFICERS = [OWNER_ID] + DEV_USERS + DRAGONS + DEMONS
+
# Check if user has admin rights
async def is_administrator(user_id: int, message):
admin = False
@@ -83,7 +84,6 @@ async def zombies(event):
if con != "clean":
find_zombies = await event.respond("Searching For Zombies...")
async for user in event.client.iter_participants(event.chat_id):
-
if user.deleted:
del_u += 1
await sleep(1)
diff --git a/NekoRobot/services/sections.py b/NekoRobot/services/sections.py
index e19293a9..730f364a 100644
--- a/NekoRobot/services/sections.py
+++ b/NekoRobot/services/sections.py
@@ -14,7 +14,6 @@ def section(
indent: int = 2,
underline: bool = False,
) -> str:
-
text = (bold_ul(title) + n) if underline else bold(title) + n
for key, value in body.items():
diff --git a/NekoRobot/services/tasks.py b/NekoRobot/services/tasks.py
index 8873fc61..0c19f280 100644
--- a/NekoRobot/services/tasks.py
+++ b/NekoRobot/services/tasks.py
@@ -18,7 +18,6 @@ async def add_task(
*args,
**kwargs,
):
-
async with TASKS_LOCK:
global tasks
diff --git a/NekoRobot/utils/errors.py b/NekoRobot/utils/errors.py
index a8e8bbec..98bdeb1a 100644
--- a/NekoRobot/utils/errors.py
+++ b/NekoRobot/utils/errors.py
@@ -35,9 +35,7 @@
def split_limits(text):
-
if len(text) < 2048:
-
return [text]
lines = text.splitlines(True)
@@ -47,19 +45,15 @@ def split_limits(text):
result = []
for line in lines:
-
if len(small_msg) + len(line) < 2048:
-
small_msg += line
else:
-
result.append(small_msg)
small_msg = line
else:
-
result.append(small_msg)
return result
@@ -68,19 +62,15 @@ def split_limits(text):
def capture_err(func):
@wraps(func)
async def capture(client, message, *args, **kwargs):
-
try:
-
return await func(client, message, *args, **kwargs)
except ChatWriteForbidden:
-
await app.leave_chat(message.chat.id)
return
except Exception as err:
-
exc_type, exc_obj, exc_tb = sys.exc_info()
errors = traceback.format_exception(
@@ -99,7 +89,6 @@ async def capture(client, message, *args, **kwargs):
)
for x in error_feedback:
-
await app.send_message(LOG_GROUP_ID, x)
raise err
diff --git a/NekoRobot/utils/pluginhelpers.py b/NekoRobot/utils/pluginhelpers.py
index 30f5c3b3..64e322fd 100644
--- a/NekoRobot/utils/pluginhelpers.py
+++ b/NekoRobot/utils/pluginhelpers.py
@@ -43,7 +43,6 @@
def get_user(message: Message, text: str) -> [int, str, None]:
-
asplit = None if text is None else text.split(" ", 1)
user_s = None
@@ -51,43 +50,35 @@ def get_user(message: Message, text: str) -> [int, str, None]:
reason_ = None
if message.reply_to_message:
-
user_s = message.reply_to_message.from_user.id
reason_ = text or None
elif asplit is None:
-
return None, None
elif len(asplit[0]) > 0:
-
user_s = int(asplit[0]) if asplit[0].isdigit() else asplit[0]
if len(asplit) == 2:
-
reason_ = asplit[1]
return user_s, reason_
async def is_admin(event, user):
-
try:
-
sed = await event.client.get_permissions(event.chat_id, user)
is_mod = bool(sed.is_admin)
except:
-
is_mod = False
return is_mod
def get_readable_time(seconds: int) -> int:
-
count = 0
ping_time = ""
@@ -97,13 +88,11 @@ def get_readable_time(seconds: int) -> int:
time_suffix_list = ["s", "m", "h", "days"]
while count < 4:
-
count += 1
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
if seconds == 0 and remainder == 0:
-
break
time_list.append(int(result))
@@ -111,11 +100,9 @@ def get_readable_time(seconds: int) -> int:
seconds = int(remainder)
for x in range(len(time_list)):
-
time_list[x] = str(time_list[x]) + time_suffix_list[x]
if len(time_list) == 4:
-
ping_time += time_list.pop() + ", "
time_list.reverse()
@@ -126,7 +113,6 @@ def get_readable_time(seconds: int) -> int:
def time_formatter(milliseconds: int) -> str:
-
seconds, milliseconds = divmod(int(milliseconds), 1000)
minutes, seconds = divmod(seconds, 60)
@@ -147,18 +133,14 @@ def time_formatter(milliseconds: int) -> str:
async def delete_or_pass(message):
-
if message.from_user.id == 1141839926:
-
return message
return await message.delete()
def humanbytes(size):
-
if not size:
-
return ""
power = 2**10
@@ -168,7 +150,6 @@ def humanbytes(size):
dict_power_n = {0: "", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power:
-
size /= power
raised_to_pow += 1
@@ -177,13 +158,11 @@ def humanbytes(size):
async def progress(current, total, message, start, type_of_ps, file_name=None):
-
now = time.time()
diff = now - start
if round(diff % 10.00) == 0 or current == total:
-
percentage = current * 100 / total
speed = current / diff
@@ -191,7 +170,6 @@ async def progress(current, total, message, start, type_of_ps, file_name=None):
elapsed_time = round(diff) * 1000
if elapsed_time == 0:
-
return
time_to_completion = round((total - current) / speed) * 1000
@@ -209,76 +187,58 @@ async def progress(current, total, message, start, type_of_ps, file_name=None):
)
if file_name:
-
try:
-
await message.edit(
"{}\n**File Name:** `{}`\n{}".format(type_of_ps, file_name, tmp)
)
except FloodWait as e:
-
await asyncio.sleep(e.x)
except MessageNotModified:
-
pass
else:
-
try:
-
await message.edit("{}\n{}".format(type_of_ps, tmp))
except FloodWait as e:
-
await asyncio.sleep(e.x)
except MessageNotModified:
-
pass
def get_text(message: Message) -> [None, str]:
-
text_to_return = message.text
if message.text is None:
-
return None
if " " not in text_to_return:
-
return None
try:
-
return message.text.split(None, 1)[1]
except IndexError:
-
return None
async def iter_chats(client):
-
chats = []
async for dialog in client.iter_dialogs():
-
if dialog.chat.type in ["supergroup", "channel"]:
-
chats.append(dialog.chat.id)
return chats
async def fetch_audio(client, message):
-
time.time()
if not message.reply_to_message:
-
await message.reply("`Reply To A Video / Audio.`")
return
@@ -286,13 +246,11 @@ async def fetch_audio(client, message):
warner_stark = message.reply_to_message
if warner_stark.audio is None and warner_stark.video is None:
-
await message.reply("`Format Not Supported`")
return
if warner_stark.video:
-
lel = await message.reply("`Video Detected, Converting To Audio !`")
warner_bros = await message.reply_to_message.download()
@@ -304,7 +262,6 @@ async def fetch_audio(client, message):
final_warner = "friday.mp3"
elif warner_stark.audio:
-
lel = await edit_or_reply(message, "`Download Started !`")
final_warner = await message.reply_to_message.download()
@@ -317,11 +274,8 @@ async def fetch_audio(client, message):
async def edit_or_reply(message, text, parse_mode="md"):
-
if message.from_user.id:
-
if message.reply_to_message:
-
kk = message.reply_to_message.message_id
return await message.reply_text(
@@ -334,7 +288,6 @@ async def edit_or_reply(message, text, parse_mode="md"):
async def runcmd(cmd: str) -> Tuple[str, str, int, int]:
-
"""run command in terminal"""
args = shlex.split(cmd)
@@ -354,7 +307,6 @@ async def runcmd(cmd: str) -> Tuple[str, str, int, int]:
async def convert_to_image(message, client) -> [None, str]:
-
"""Convert Most Media Formats To Raw Image"""
final_path = None
@@ -366,17 +318,13 @@ async def convert_to_image(message, client) -> [None, str]:
or message.reply_to_message.animation
or message.reply_to_message.audio
):
-
return None
if message.reply_to_message.photo:
-
final_path = await message.reply_to_message.download()
elif message.reply_to_message.sticker:
-
if message.reply_to_message.sticker.mime_type == "image/webp":
-
final_path = "webp_to_png_s_proton.png"
path_s = await message.reply_to_message.download()
@@ -386,7 +334,6 @@ async def convert_to_image(message, client) -> [None, str]:
im.save(final_path, "PNG")
else:
-
path_s = await client.download_media(message.reply_to_message)
final_path = "lottie_proton.png"
@@ -398,13 +345,11 @@ async def convert_to_image(message, client) -> [None, str]:
await runcmd(cmd)
elif message.reply_to_message.audio:
-
thumb = message.reply_to_message.audio.thumbs[0].file_id
final_path = await client.download_media(thumb)
elif message.reply_to_message.video or message.reply_to_message.animation:
-
final_path = "fetched_thumb.png"
vid_path = await client.download_media(message.reply_to_message)
@@ -415,25 +360,20 @@ async def convert_to_image(message, client) -> [None, str]:
def get_text(message: Message) -> [None, str]:
-
"""Extract Text From Commands"""
text_to_return = message.text
if message.text is None:
-
return None
if " " not in text_to_return:
-
return None
try:
-
return message.text.split(None, 1)[1]
except IndexError:
-
return None
@@ -443,33 +383,26 @@ def get_text(message: Message) -> [None, str]:
def set(chat_id: Union[str, int], admins_: List[User]):
-
if isinstance(chat_id, int):
-
chat_id = str(chat_id)
admins[chat_id] = admins_
def get(chat_id: Union[str, int]) -> Union[List[User], bool]:
-
if isinstance(chat_id, int):
-
chat_id = str(chat_id)
if chat_id in admins:
-
return admins[chat_id]
return False
async def get_administrators(chat: Chat) -> List[User]:
-
_get = get(chat.id)
if _get:
-
return _get
set(
@@ -482,17 +415,13 @@ async def get_administrators(chat: Chat) -> List[User]:
def admins_only(func: Callable) -> Coroutine:
async def wrapper(client: Client, message: Message):
-
if message.from_user.id == OWNER_ID:
-
return await func(client, message)
admins = await get_administrators(message.chat)
for admin in admins:
-
if admin.id == message.from_user.id:
-
return await func(client, message)
return wrapper
@@ -504,13 +433,10 @@ async def wrapper(client: Client, message: Message):
def capture_err(func):
@wraps(func)
async def capture(client, message, *args, **kwargs):
-
try:
-
return await func(client, message, *args, **kwargs)
except Exception as err:
-
exc_type, exc_obj, exc_tb = sys.exc_info()
errors = traceback.format_exception(
@@ -529,7 +455,6 @@ async def capture(client, message, *args, **kwargs):
)
for x in error_feedback:
-
await pgram.send_message(SUPPORT_CHAT, x)
raise err
@@ -541,94 +466,73 @@ async def capture(client, message, *args, **kwargs):
async def member_permissions(chat_id, user_id):
-
perms = []
member = await pgram.get_chat_member(chat_id, user_id)
if member.can_post_messages:
-
perms.append("can_post_messages")
if member.can_edit_messages:
-
perms.append("can_edit_messages")
if member.can_delete_messages:
-
perms.append("can_delete_messages")
if member.can_restrict_members:
-
perms.append("can_restrict_members")
if member.can_promote_members:
-
perms.append("can_promote_members")
if member.can_change_info:
-
perms.append("can_change_info")
if member.can_invite_users:
-
perms.append("can_invite_users")
if member.can_pin_messages:
-
perms.append("can_pin_messages")
return perms
async def current_chat_permissions(chat_id):
-
perms = []
perm = (await pgram.get_chat(chat_id)).permissions
if perm.can_send_messages:
-
perms.append("can_send_messages")
if perm.can_send_media_messages:
-
perms.append("can_send_media_messages")
if perm.can_send_stickers:
-
perms.append("can_send_stickers")
if perm.can_send_animations:
-
perms.append("can_send_animations")
if perm.can_send_games:
-
perms.append("can_send_games")
if perm.can_use_inline_bots:
-
perms.append("can_use_inline_bots")
if perm.can_add_web_page_previews:
-
perms.append("can_add_web_page_previews")
if perm.can_send_polls:
-
perms.append("can_send_polls")
if perm.can_change_info:
-
perms.append("can_change_info")
if perm.can_invite_users:
-
perms.append("can_invite_users")
if perm.can_pin_messages:
-
perms.append("can_pin_messages")
return perms
@@ -638,11 +542,9 @@ async def current_chat_permissions(chat_id):
def get_url(message_1: Message) -> Union[str, None]:
-
messages = [message_1]
if message_1.reply_to_message:
-
messages.append(message_1.reply_to_message)
text = ""
@@ -652,17 +554,12 @@ def get_url(message_1: Message) -> Union[str, None]:
length = None
for message in messages:
-
if offset:
-
break
if message.entities:
-
for entity in message.entities:
-
if entity.type == "url":
-
text = message.text or message.caption
offset, length = entity.offset, entity.length
@@ -670,29 +567,23 @@ def get_url(message_1: Message) -> Union[str, None]:
break
if offset in (None,):
-
return None
return text[offset : offset + length]
async def fetch(url):
-
async with aiohttp.ClientSession() as session, session.get(url) as resp:
-
try:
-
data = await resp.json()
except Exception:
-
data = await resp.text()
return data
async def convert_seconds_to_minutes(seconds: int):
-
seconds = int(seconds)
seconds %= 24 * 3600
@@ -707,7 +598,6 @@ async def convert_seconds_to_minutes(seconds: int):
async def json_object_prettify(objecc):
-
dicc = objecc.__dict__
return "".join(
@@ -718,21 +608,15 @@ async def json_object_prettify(objecc):
async def json_prettify(data):
-
output = ""
try:
-
for key, value in data.items():
-
output += f"**{key}:** `{value}`\n"
except Exception:
-
for datas in data:
-
for key, value in datas.items():
-
output += f"**{key}:** `{value}`\n"
output += "------------------------\n"