Skip to content

Commit 363be3a

Browse files
author
Sourcery AI
committed
'Refactored by Sourcery'
1 parent f694030 commit 363be3a

30 files changed

+125
-177
lines changed

dbplugins/blacklist.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ async def on_delete_blacklist(event):
7575
to_unblacklist = list(
7676
{trigger.strip() for trigger in text.split("\n") if trigger.strip()}
7777
)
78-
successful = 0
79-
for trigger in to_unblacklist:
80-
if sql.rm_from_blacklist(event.chat_id, trigger.lower()):
81-
successful += 1
78+
successful = sum(
79+
bool(sql.rm_from_blacklist(event.chat_id, trigger.lower()))
80+
for trigger in to_unblacklist
81+
)
82+
8283
await event.edit(f"Removed {successful} / {len(to_unblacklist)} from the blacklist")

dbplugins/filters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,4 @@ async def on_snip_delete(event):
110110
@borg.on(slitu.admin_cmd(pattern="clearallfilters"))
111111
async def on_all_snip_delete(event):
112112
remove_all_filters(event.chat_id)
113-
await event.edit(f"filters **in current chat** deleted successfully")
113+
await event.edit('filters **in current chat** deleted successfully')

dbplugins/locks.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -227,34 +227,31 @@ async def _(event):
227227
return False
228228
if await slitu.is_admin(event.client, event.chat_id, event.action_message.sender_id):
229229
return
230-
if is_locked(event.chat_id, "bots"):
231-
# bots are limited Telegram accounts,
232-
# and cannot join by themselves
233-
if event.user_added:
234-
users_added_by = event.action_message.sender_id
235-
is_ban_able = False
236-
rights = types.ChatBannedRights(
237-
until_date=None,
238-
view_messages=True
230+
if is_locked(event.chat_id, "bots") and event.user_added:
231+
users_added_by = event.action_message.sender_id
232+
is_ban_able = False
233+
rights = types.ChatBannedRights(
234+
until_date=None,
235+
view_messages=True
236+
)
237+
added_users = event.action_message.action.users
238+
for user_id in added_users:
239+
user_obj = await event.client.get_entity(user_id)
240+
if user_obj.bot:
241+
is_ban_able = True
242+
try:
243+
await event.client(functions.channels.EditBannedRequest(
244+
event.chat_id,
245+
user_obj,
246+
rights
247+
))
248+
except Exception as e:
249+
await event.reply(
250+
"I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
251+
)
252+
update_lock(event.chat_id, "bots", False)
253+
break
254+
if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
255+
ban_reason_msg = await event.reply(
256+
"!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
239257
)
240-
added_users = event.action_message.action.users
241-
for user_id in added_users:
242-
user_obj = await event.client.get_entity(user_id)
243-
if user_obj.bot:
244-
is_ban_able = True
245-
try:
246-
await event.client(functions.channels.EditBannedRequest(
247-
event.chat_id,
248-
user_obj,
249-
rights
250-
))
251-
except Exception as e:
252-
await event.reply(
253-
"I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
254-
)
255-
update_lock(event.chat_id, "bots", False)
256-
break
257-
if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
258-
ban_reason_msg = await event.reply(
259-
"!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
260-
)

sql_helpers/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def start() -> scoped_session:
2121
except AttributeError as e:
2222
# this is a dirty way for the work-around required for #23
2323
print("DB_URI is not configured. Features depending on the database might have issues.")
24-
print(str(e))
24+
print(e)
2525

stdplugins/_help.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ async def _(event):
4040
help_string += f"<b>Total Disk Space</b>: <code>{total}</code>\n"
4141
help_string += f"<b>Used Disk Space</b>: <code>{used}</code>\n"
4242
help_string += f"<b>Free Disk Space</b>: <code>{free}</code>\n\n"
43-
help_string += f"UserBot Forked from https://github.com/udf/uniborg"
44-
borg._iiqsixfourstore[str(event.chat_id)] = {}
45-
borg._iiqsixfourstore[
46-
str(event.chat_id)
47-
][
48-
str(event.id)
49-
] = help_string + "\n\n" + s_help_string
43+
help_string += 'UserBot Forked from https://github.com/udf/uniborg'
44+
borg._iiqsixfourstore[str(event.chat_id)] = {
45+
str(event.id): help_string + "\n\n" + s_help_string
46+
}
47+
5048
if borg.tgbot:
5149
tgbot_username = await tgbot.get_me()
5250
results = await borg.inline_query( # pylint:disable=E0602
@@ -138,7 +136,7 @@ def check_data_base_heal_th():
138136
# to check database we will execute raw query
139137
SESSION.execute("SELECT 1")
140138
except Exception as e:
141-
output = f"{str(e)}"
139+
output = f'{e}'
142140
is_database_working = False
143141
else:
144142
output = "✅"

stdplugins/barcode.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ async def _(event):
3333
m_list = None
3434
with open(downloaded_file_name, "rb") as fd:
3535
m_list = fd.readlines()
36-
message = ""
37-
for m in m_list:
38-
message += m.decode("UTF-8") + "\r\n"
36+
message = "".join(m.decode("UTF-8") + "\r\n" for m in m_list)
3937
os.remove(downloaded_file_name)
4038
else:
4139
message = previous_message.message

stdplugins/chat_file_s_count_er.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ async def _(event):
2525
if message.file.mime_type not in hmm:
2626
hmm[message.file.mime_type] = 0
2727
hmm[message.file.mime_type] += message.file.size
28-
hnm = {}
29-
for key in hmm:
30-
hnm[key] = slitu.humanbytes(hmm[key])
28+
hnm = {key: slitu.humanbytes(hmm[key]) for key in hmm}
3129
await status_message.edit(
3230
slitu.yaml_format(hnm),
3331
parse_mode=slitu.parse_pre

stdplugins/checkrestrictionsbot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_restriction_string(a) -> str:
3434
b = ""
3535
c = ""
3636
if isinstance(a, Channel):
37-
c = f"[{a.title}](https://t.me/c/{a.id}/{2})"
37+
c = f'[{a.title}](https://t.me/c/{a.id}/2)'
3838
elif isinstance(a, User):
3939
c = f"[{a.first_name}](tg://user?id={a.id})"
4040
elif isinstance(a, Chat):

stdplugins/count.py

+24-27
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""Type `.count` and see Magic."""
1111

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

33-
if isinstance(entity, Channel):
34-
# participants_count = (await event.get_participants(dialog, limit=0)).total
35-
if entity.broadcast:
36-
broadcast_channels += 1
37-
if entity.creator or entity.admin_rights:
38-
admin_in_broadcast_channels += 1
39-
if entity.creator:
40-
creator_in_channels += 1
41-
42-
elif entity.megagroup:
43-
groups += 1
44-
# if participants_count > largest_group_member_count:
45-
# largest_group_member_count = participants_count
46-
if entity.creator or entity.admin_rights:
47-
# if participants_count > largest_group_with_admin:
48-
# largest_group_with_admin = participants_count
49-
admin_in_groups += 1
50-
if entity.creator:
51-
creator_in_groups += 1
52-
53-
elif isinstance(entity, User):
54-
private_chats += 1
55-
if entity.bot:
56-
bots += 1
57-
58-
elif isinstance(entity, Chat):
33+
if isinstance(entity, Channel) and entity.broadcast:
34+
broadcast_channels += 1
35+
if entity.creator or entity.admin_rights:
36+
admin_in_broadcast_channels += 1
37+
if entity.creator:
38+
creator_in_channels += 1
39+
40+
elif (
41+
isinstance(entity, Channel)
42+
and entity.megagroup
43+
or not isinstance(entity, Channel)
44+
and not isinstance(entity, User)
45+
and isinstance(entity, Chat)
46+
):
5947
groups += 1
48+
# if participants_count > largest_group_member_count:
49+
# largest_group_member_count = participants_count
6050
if entity.creator or entity.admin_rights:
51+
# if participants_count > largest_group_with_admin:
52+
# largest_group_with_admin = participants_count
6153
admin_in_groups += 1
6254
if entity.creator:
6355
creator_in_groups += 1
6456

57+
elif not isinstance(entity, Channel) and isinstance(entity, User):
58+
private_chats += 1
59+
if entity.bot:
60+
bots += 1
61+
6562
unread_mentions += dialog.unread_mentions_count
6663
unread += dialog.unread_count
6764
stop_time = time.time() - start_time

stdplugins/dmcatelegrambot.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def _(event):
1818
". . ."
1919
)
2020
if event.reply_to_msg_id:
21-
t_a = dict()
21+
t_a = {}
2222
reply = await event.get_reply_message()
2323
for entity in reply.entities:
2424
if isinstance(entity, MessageEntityUrl):
@@ -32,8 +32,7 @@ async def _(event):
3232
if len(t_a[chat_id]) >= 100:
3333
await do_delete_NOQA(event.client, t_a[chat_id], chat_id)
3434
t_a[chat_id] = []
35-
for chat in t_a:
36-
m_di = t_a[chat]
35+
for chat, m_di in t_a.items():
3736
if len(m_di) > 0:
3837
await do_delete_NOQA(event.client, m_di, chat)
3938
t_a[chat] = []

stdplugins/download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def _(event):
5555
display_message = ""
5656
c_time = time.time()
5757
while not downloader.isFinished():
58-
total_length = downloader.filesize if downloader.filesize else None
58+
total_length = downloader.filesize or None
5959
downloaded = downloader.get_dl_size()
6060
now = time.time()
6161
diff = now - c_time

stdplugins/eval.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ async def aexec(code, smessatatus):
7272
p = lambda _x: print(slitu.yaml_format(_x))
7373
reply = await event.get_reply_message()
7474
exec(
75-
f'async def __aexec(message, reply, client, p): ' +
76-
'\n event = smessatatus = message' +
77-
''.join(f'\n {l}' for l in code.split('\n'))
75+
(
76+
'async def __aexec(message, reply, client, p): '
77+
+ '\n event = smessatatus = message'
78+
)
79+
+ ''.join(f'\n {l}' for l in code.split('\n'))
7880
)
81+
7982
return await locals()['__aexec'](message, reply, message.client, p)

stdplugins/exec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def _(event):
3535
e = borg.secure_text(e)
3636
o = borg.secure_text(o)
3737

38-
OUTPUT = f"**QUERY:**\n"
38+
OUTPUT = '**QUERY:**\n'
3939
OUTPUT += f"__Command:__\n`{cmd}` \n"
4040
OUTPUT += f"__PID:__\n`{process.pid}`\n\n"
4141
OUTPUT += f"**stderr:** \n`{e}`\n"

stdplugins/file_converter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def _(event):
4848
)
4949
)
5050
)
51-
io = io + 1
51+
io += 1
5252
except Exception as e: # pylint:disable=C0103,W0703
5353
await event.edit(str(e))
5454
else:
@@ -103,7 +103,7 @@ async def _(event):
103103
]
104104
voice_note = False
105105
supports_streaming = True
106-
106+
107107
logger.info(command_to_run)
108108
t_response, e_response = await slitu.run_command(command_to_run)
109109
os.remove(downloaded_file_name)
@@ -148,4 +148,4 @@ async def _(event):
148148
await event.edit(
149149
f"[{io} / {tot}] converted in {ms_two} seconds"
150150
)
151-
io = io + 1
151+
io += 1

stdplugins/gDrive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ async def _(event):
233233
# Get mime type and name of given file
234234
def file_ops(file_path):
235235
mime_type = guess_type(file_path)[0]
236-
mime_type = mime_type if mime_type else "text/plain"
236+
mime_type = mime_type or "text/plain"
237237
file_name = file_path.split("/")[-1]
238238
return file_name, mime_type
239239

stdplugins/gPhotos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ async def upload_google_photos(event):
324324
def file_ops(file_path):
325325
file_size = os.stat(file_path).st_size
326326
mime_type = guess_type(file_path)[0]
327-
mime_type = mime_type if mime_type else "text/plain"
327+
mime_type = mime_type or "text/plain"
328328
file_name = file_path.split("/")[-1]
329329
return file_name, mime_type, file_size
330330

stdplugins/get_admin.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ async def _(event):
4040
async for x in event.client.iter_participants(chat, filter=ChannelParticipantsAdmins):
4141
if x.deleted:
4242
mentions += "\n `{}`".format(x.id)
43-
else:
44-
if isinstance(x.participant, ChannelParticipantAdmin):
45-
mentions += "\n ⚜️ [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
43+
elif isinstance(x.participant, ChannelParticipantAdmin):
44+
mentions += "\n ⚜️ [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
4645
except Exception as e:
4746
mentions += " " + str(e) + "\n"
4847
if should_mention_admins:

stdplugins/imdb.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ def get_movie_details(soup):
8282
if tags:
8383
mov_details.append(tags)
8484
if mov_details and len(mov_details) > 1:
85-
mov_details_text = ' | '.join(mov_details)
85+
return ' | '.join(mov_details)
8686
else:
87-
mov_details_text = mov_details[0] if mov_details else ''
88-
return mov_details_text
87+
return mov_details[0] if mov_details else ''
8988

9089

9190
def get_countries_and_languages(soup):

stdplugins/pastebin.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ async def _(event):
3333
m_list = None
3434
with open(downloaded_file_name, "rb") as fd:
3535
m_list = fd.readlines()
36-
message = ""
37-
for m in m_list:
38-
message += m.decode("UTF-8")
36+
message = "".join(m.decode("UTF-8") for m in m_list)
3937
os.remove(downloaded_file_name)
4038
else:
4139
message = previous_message.message

stdplugins/pin_message.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
async def _(event):
88
if event.fwd_from:
99
return
10-
silent = True
1110
input_str = event.pattern_match.group(1)
12-
if input_str:
13-
silent = False
11+
silent = not input_str
1412
if event.message.reply_to_msg_id is not None:
1513
message_id = event.message.reply_to_msg_id
1614
try:

stdplugins/purge.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def _(event):
2424
if len(msgs) >= 100:
2525
await event.client.delete_messages(event.chat_id, msgs, revoke=True)
2626
msgs = []
27-
if len(msgs) > 0:
27+
if msgs:
2828
await event.client.delete_messages(event.chat_id, msgs, revoke=True)
2929
msgs = []
3030
await event.delete()

stdplugins/qr_code.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ async def _(event):
7070
m_list = None
7171
with open(downloaded_file_name, "rb") as fd:
7272
m_list = fd.readlines()
73-
message = ""
74-
for m in m_list:
75-
message += m.decode("UTF-8") + "\r\n"
73+
message = "".join(m.decode("UTF-8") + "\r\n" for m in m_list)
7674
os.remove(downloaded_file_name)
7775
else:
7876
message = previous_message.message

stdplugins/sca.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ async def _(event):
99
return
1010
await event.delete()
1111
input_str = event.pattern_match.group(1)
12-
action = "typing"
13-
if input_str:
14-
action = input_str
12+
action = input_str or "typing"
1513
async with event.client.action(event.chat_id, action):
1614
await asyncio.sleep(10) # type for 10 seconds

0 commit comments

Comments
 (0)