Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Nov 28, 2021
1 parent 14885d3 commit 43e2031
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 164 deletions.
9 changes: 5 additions & 4 deletions dbplugins/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ async def on_delete_blacklist(event):
to_unblacklist = list(
{trigger.strip() for trigger in text.split("\n") if trigger.strip()}
)
successful = 0
for trigger in to_unblacklist:
if sql.rm_from_blacklist(event.chat_id, trigger.lower()):
successful += 1
successful = sum(
bool(sql.rm_from_blacklist(event.chat_id, trigger.lower()))
for trigger in to_unblacklist
)

await event.edit(f"Removed {successful} / {len(to_unblacklist)} from the blacklist")
2 changes: 1 addition & 1 deletion dbplugins/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ async def on_snip_delete(event):
@borg.on(slitu.admin_cmd(pattern="clearallfilters"))
async def on_all_snip_delete(event):
remove_all_filters(event.chat_id)
await event.edit(f"filters **in current chat** deleted successfully")
await event.edit('filters **in current chat** deleted successfully')
57 changes: 27 additions & 30 deletions dbplugins/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,34 +227,31 @@ async def _(event):
return False
if await slitu.is_admin(event.client, event.chat_id, event.action_message.sender_id):
return
if is_locked(event.chat_id, "bots"):
# bots are limited Telegram accounts,
# and cannot join by themselves
if event.user_added:
users_added_by = event.action_message.sender_id
is_ban_able = False
rights = types.ChatBannedRights(
until_date=None,
view_messages=True
if is_locked(event.chat_id, "bots") and event.user_added:
users_added_by = event.action_message.sender_id
is_ban_able = False
rights = types.ChatBannedRights(
until_date=None,
view_messages=True
)
added_users = event.action_message.action.users
for user_id in added_users:
user_obj = await event.client.get_entity(user_id)
if user_obj.bot:
is_ban_able = True
try:
await event.client(functions.channels.EditBannedRequest(
event.chat_id,
user_obj,
rights
))
except Exception as e:
await event.reply(
"I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
)
update_lock(event.chat_id, "bots", False)
break
if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
ban_reason_msg = await event.reply(
"!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
)
added_users = event.action_message.action.users
for user_id in added_users:
user_obj = await event.client.get_entity(user_id)
if user_obj.bot:
is_ban_able = True
try:
await event.client(functions.channels.EditBannedRequest(
event.chat_id,
user_obj,
rights
))
except Exception as e:
await event.reply(
"I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
)
update_lock(event.chat_id, "bots", False)
break
if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
ban_reason_msg = await event.reply(
"!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
)
14 changes: 6 additions & 8 deletions stdplugins/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ async def _(event):
help_string += f"<b>Total Disk Space</b>: <code>{total}</code>\n"
help_string += f"<b>Used Disk Space</b>: <code>{used}</code>\n"
help_string += f"<b>Free Disk Space</b>: <code>{free}</code>\n\n"
help_string += f"UserBot Forked from https://github.com/udf/uniborg"
borg._iiqsixfourstore[str(event.chat_id)] = {}
borg._iiqsixfourstore[
str(event.chat_id)
][
str(event.id)
] = help_string + "\n\n" + s_help_string
help_string += 'UserBot Forked from https://github.com/udf/uniborg'
borg._iiqsixfourstore[str(event.chat_id)] = {
str(event.id): help_string + "\n\n" + s_help_string
}

tgbotusername = Config.TG_BOT_USER_NAME_BF_HER # pylint:disable=E0602
if tgbotusername is not None:
results = await borg.inline_query( # pylint:disable=E0602
Expand Down Expand Up @@ -138,7 +136,7 @@ def check_data_base_heal_th():
# to check database we will execute raw query
SESSION.execute("SELECT 1")
except Exception as e:
output = f"{str(e)}"
output = f'{e}'
is_database_working = False
else:
output = "✅"
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ async def _(event):
m_list = None
with open(downloaded_file_name, "rb") as fd:
m_list = fd.readlines()
message = ""
for m in m_list:
message += m.decode("UTF-8") + "\r\n"
message = "".join(m.decode("UTF-8") + "\r\n" for m in m_list)
os.remove(downloaded_file_name)
else:
message = previous_message.message
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/chat_file_s_count_er.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ async def _(event):
if message.file.mime_type not in hmm:
hmm[message.file.mime_type] = 0
hmm[message.file.mime_type] += message.file.size
hnm = {}
for key in hmm:
hnm[key] = slitu.humanbytes(hmm[key])
hnm = {key: slitu.humanbytes(hmm[key]) for key in hmm}
await status_message.edit(
slitu.yaml_format(hnm),
parse_mode=slitu.parse_pre
Expand Down
2 changes: 1 addition & 1 deletion stdplugins/checkrestrictionsbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_restriction_string(a) -> str:
b = ""
c = ""
if isinstance(a, Channel):
c = f"[{a.title}](https://t.me/c/{a.id}/{2})"
c = f'[{a.title}](https://t.me/c/{a.id}/2)'
elif isinstance(a, User):
c = f"[{a.first_name}](tg://user?id={a.id})"
elif isinstance(a, Chat):
Expand Down
51 changes: 24 additions & 27 deletions stdplugins/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""Type `.count` and see Magic."""

@borg.on(slitu.admin_cmd(pattern='count'))
async def stats(event: NewMessage.Event) -> None: # pylint: disable = R0912, R0914, R0915
async def stats(event: NewMessage.Event) -> None: # pylint: disable = R0912, R0914, R0915
"""Command to get stats about the account"""
waiting_message = await event.edit('`Collecting stats, Wait Nibba`')
start_time = time.time()
Expand All @@ -30,38 +30,35 @@ async def stats(event: NewMessage.Event) -> None: # pylint: disable = R0912, R0
async for dialog in event.client.iter_dialogs():
entity = dialog.entity

if isinstance(entity, Channel):
# participants_count = (await event.get_participants(dialog, limit=0)).total
if entity.broadcast:
broadcast_channels += 1
if entity.creator or entity.admin_rights:
admin_in_broadcast_channels += 1
if entity.creator:
creator_in_channels += 1

elif entity.megagroup:
groups += 1
# if participants_count > largest_group_member_count:
# largest_group_member_count = participants_count
if entity.creator or entity.admin_rights:
# if participants_count > largest_group_with_admin:
# largest_group_with_admin = participants_count
admin_in_groups += 1
if entity.creator:
creator_in_groups += 1

elif isinstance(entity, User):
private_chats += 1
if entity.bot:
bots += 1

elif isinstance(entity, Chat):
if isinstance(entity, Channel) and entity.broadcast:
broadcast_channels += 1
if entity.creator or entity.admin_rights:
admin_in_broadcast_channels += 1
if entity.creator:
creator_in_channels += 1

elif (
isinstance(entity, Channel)
and entity.megagroup
or not isinstance(entity, Channel)
and not isinstance(entity, User)
and isinstance(entity, Chat)
):
groups += 1
# if participants_count > largest_group_member_count:
# largest_group_member_count = participants_count
if entity.creator or entity.admin_rights:
# if participants_count > largest_group_with_admin:
# largest_group_with_admin = participants_count
admin_in_groups += 1
if entity.creator:
creator_in_groups += 1

elif not isinstance(entity, Channel) and isinstance(entity, User):
private_chats += 1
if entity.bot:
bots += 1

unread_mentions += dialog.unread_mentions_count
unread += dialog.unread_count
stop_time = time.time() - start_time
Expand Down
5 changes: 2 additions & 3 deletions stdplugins/dmcatelegrambot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def _(event):
". . ."
)
if event.reply_to_msg_id:
t_a = dict()
t_a = {}
reply = await event.get_reply_message()
for entity in reply.entities:
if isinstance(entity, MessageEntityUrl):
Expand All @@ -32,8 +32,7 @@ async def _(event):
if len(t_a[chat_id]) >= 100:
await do_delete_NOQA(event.client, t_a[chat_id], chat_id)
t_a[chat_id] = []
for chat in t_a:
m_di = t_a[chat]
for chat, m_di in t_a.items():
if len(m_di) > 0:
await do_delete_NOQA(event.client, m_di, chat)
t_a[chat] = []
Expand Down
2 changes: 1 addition & 1 deletion stdplugins/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def _(event):
display_message = ""
c_time = time.time()
while not downloader.isFinished():
total_length = downloader.filesize if downloader.filesize else None
total_length = downloader.filesize or None
downloaded = downloader.get_dl_size()
now = time.time()
diff = now - c_time
Expand Down
9 changes: 6 additions & 3 deletions stdplugins/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ async def aexec(code, smessatatus):
p = lambda _x: print(slitu.yaml_format(_x))
reply = await event.get_reply_message()
exec(
f'async def __aexec(message, reply, client, p): ' +
'\n event = smessatatus = message' +
''.join(f'\n {l}' for l in code.split('\n'))
(
'async def __aexec(message, reply, client, p): '
+ '\n event = smessatatus = message'
)
+ ''.join(f'\n {l}' for l in code.split('\n'))
)

return await locals()['__aexec'](message, reply, message.client, p)
2 changes: 1 addition & 1 deletion stdplugins/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def _(event):
e = borg.secure_text(e)
o = borg.secure_text(o)

OUTPUT = f"**QUERY:**\n"
OUTPUT = '**QUERY:**\n'
OUTPUT += f"__Command:__\n`{cmd}` \n"
OUTPUT += f"__PID:__\n`{process.pid}`\n\n"
OUTPUT += f"**stderr:** \n`{e}`\n"
Expand Down
6 changes: 3 additions & 3 deletions stdplugins/file_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def _(event):
)
)
)
io = io + 1
io += 1
except Exception as e: # pylint:disable=C0103,W0703
await event.edit(str(e))
else:
Expand Down Expand Up @@ -103,7 +103,7 @@ async def _(event):
]
voice_note = False
supports_streaming = True

logger.info(command_to_run)
t_response, e_response = await slitu.run_command(command_to_run)
os.remove(downloaded_file_name)
Expand Down Expand Up @@ -148,4 +148,4 @@ async def _(event):
await event.edit(
f"[{io} / {tot}] converted in {ms_two} seconds"
)
io = io + 1
io += 1
2 changes: 1 addition & 1 deletion stdplugins/gDrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async def _(event):
# Get mime type and name of given file
def file_ops(file_path):
mime_type = guess_type(file_path)[0]
mime_type = mime_type if mime_type else "text/plain"
mime_type = mime_type or "text/plain"
file_name = file_path.split("/")[-1]
return file_name, mime_type

Expand Down
2 changes: 1 addition & 1 deletion stdplugins/gPhotos.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ async def upload_google_photos(event):
def file_ops(file_path):
file_size = os.stat(file_path).st_size
mime_type = guess_type(file_path)[0]
mime_type = mime_type if mime_type else "text/plain"
mime_type = mime_type or "text/plain"
file_name = file_path.split("/")[-1]
return file_name, mime_type, file_size

5 changes: 2 additions & 3 deletions stdplugins/get_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ async def _(event):
async for x in event.client.iter_participants(chat, filter=ChannelParticipantsAdmins):
if x.deleted:
mentions += "\n `{}`".format(x.id)
else:
if isinstance(x.participant, ChannelParticipantAdmin):
mentions += "\n ⚜️ [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
elif isinstance(x.participant, ChannelParticipantAdmin):
mentions += "\n ⚜️ [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
except Exception as e:
mentions += " " + str(e) + "\n"
if should_mention_admins:
Expand Down
5 changes: 2 additions & 3 deletions stdplugins/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ def get_movie_details(soup):
if tags:
mov_details.append(tags)
if mov_details and len(mov_details) > 1:
mov_details_text = ' | '.join(mov_details)
return ' | '.join(mov_details)
else:
mov_details_text = mov_details[0] if mov_details else ''
return mov_details_text
return mov_details[0] if mov_details else ''


def get_countries_and_languages(soup):
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ async def _(event):
m_list = None
with open(downloaded_file_name, "rb") as fd:
m_list = fd.readlines()
message = ""
for m in m_list:
message += m.decode("UTF-8")
message = "".join(m.decode("UTF-8") for m in m_list)
os.remove(downloaded_file_name)
else:
message = previous_message.message
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/pin_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
async def _(event):
if event.fwd_from:
return
silent = True
input_str = event.pattern_match.group(1)
if input_str:
silent = False
silent = not input_str
if event.message.reply_to_msg_id is not None:
message_id = event.message.reply_to_msg_id
try:
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/qr_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ async def _(event):
m_list = None
with open(downloaded_file_name, "rb") as fd:
m_list = fd.readlines()
message = ""
for m in m_list:
message += m.decode("UTF-8") + "\r\n"
message = "".join(m.decode("UTF-8") + "\r\n" for m in m_list)
os.remove(downloaded_file_name)
else:
message = previous_message.message
Expand Down
4 changes: 1 addition & 3 deletions stdplugins/sca.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ async def _(event):
return
await event.delete()
input_str = event.pattern_match.group(1)
action = "typing"
if input_str:
action = input_str
action = input_str or "typing"
async with event.client.action(event.chat_id, action):
await asyncio.sleep(10) # type for 10 seconds
5 changes: 1 addition & 4 deletions stdplugins/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ async def _(event):
)
return
reply_message = await event.get_reply_message()
sticker_emoji = "🔥"
input_str = event.pattern_match.group(1)
if input_str:
sticker_emoji = input_str

sticker_emoji = input_str or "🔥"
userid = borg.uid
packname = f"{userid}'s @UniBorg Pack"
packshortname = Config.STICKERS_PNG_SHORT_NAME
Expand Down
Loading

0 comments on commit 43e2031

Please sign in to comment.