Skip to content

Commit 5a3b848

Browse files
committed
optimizing code
1 parent f9c54bd commit 5a3b848

10 files changed

+41
-35
lines changed

assistant/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# All rights reserved.
88

9-
from .logger import logging #noqa
10-
from .config import Config #noqa
11-
from .bot import bot #noqa
12-
from . import filters #noqa
9+
from .logger import logging # noqa
10+
from .config import Config # noqa
11+
from .bot import bot # noqa
12+
from . import filters # noqa

assistant/bot.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
#
77
# All rights reserved.
88

9+
__all__ = ["bot", "START_TIME"]
10+
911
import time
1012

1113
from pyrogram import Client
1214

1315
from . import Config, logging
1416

15-
LOG = logging.getLogger(__name__)
17+
_LOG = logging.getLogger(__name__)
1618
START_TIME = time.time()
1719

1820
bot = Client(":memory:",
@@ -21,4 +23,4 @@
2123
bot_token=Config.BOT_TOKEN,
2224
plugins={'root': "assistant.plugins"})
2325

24-
LOG.info("assistant-bot initialized!")
26+
_LOG.info("assistant-bot initialized!")

assistant/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
#
77
# All rights reserved.
88

9+
__all__ = ["Config"]
10+
911
import os
1012

11-
from pyrogram import Filters
1213
from dotenv import load_dotenv
1314

1415
if os.path.isfile("config.env"):
1516
load_dotenv("config.env")
1617

1718

1819
class Config:
20+
""" assistant configs """
1921
APP_ID = int(os.environ.get("APP_ID", 0))
2022
API_HASH = os.environ.get("API_HASH")
2123
BOT_TOKEN = os.environ.get("BOT_TOKEN")

assistant/filters.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# All rights reserved.
88

9-
__all__ = ["auth_chats", "is_admin"]
9+
__all__ = ["auth_chats", "auth_users"]
1010

1111
import asyncio
1212

@@ -19,7 +19,7 @@
1919

2020

2121
async def _is_admin_or_dev(_, msg: Message) -> bool:
22-
global _FETCHING
22+
global _FETCHING # pylint: disable=global-statement
2323
if msg.chat.id not in Config.AUTH_CHATS:
2424
return False
2525
if not msg.from_user:
@@ -32,16 +32,17 @@ async def _is_admin_or_dev(_, msg: Message) -> bool:
3232
if msg.chat.id not in Config.ADMINS:
3333
_FETCHING = True
3434
admins = []
35-
_LOG.info(f"fetching data from [{msg.chat.id}] ...")
35+
_LOG.info("fetching data from [%s] ...", msg.chat.id)
36+
# pylint: disable=protected-access
3637
async for c_m in msg._client.iter_chat_members(msg.chat.id):
3738
if c_m.status in ("creator", "administrator"):
3839
admins.append(c_m.user.id)
3940
Config.ADMINS[msg.chat.id] = tuple(admins)
40-
_LOG.info(f"data fetched from [{msg.chat.id}] !")
41+
_LOG.info("data fetched from [%s] !", msg.chat.id)
4142
del admins
4243
_FETCHING = False
4344
return msg.from_user.id in Config.ADMINS[msg.chat.id]
4445

4546

46-
auth_chats = Filters.chat(list(Config.AUTH_CHATS))
47+
auth_chats = Filters.chat(list(Config.AUTH_CHATS))
4748
auth_users = Filters.create(_is_admin_or_dev)

assistant/logger.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
# All rights reserved.
88

9+
__all__ = ["logging"]
10+
911
import logging
1012

1113
# enable logging

assistant/plugins/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# and is released under the "GNU v3.0 License Agreement".
55
# Please see < https://github.com/Userge-Assistant/blob/master/LICENSE >
66
#
7-
# All rights reserved.
7+
# All rights reserved.

assistant/plugins/alive.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@
2323

2424
@bot.on_message(Filters.command("alive") & filters.auth_chats)
2525
async def _alive(_, message: Message):
26-
27-
output = f"""
28-
**🤖 Bot Uptime** : `{time_formatter(time.time() - START_TIME)}`
29-
**🤖 Bot Version** : `{versions.__assistant_version__}`
30-
**️️⭐ Python** : `{versions.__python_version__}`
31-
**💥 Pyrogram** : `{versions.__pyro_version__}` """
3226
try:
33-
await sendit(message.chat.id, output)
27+
await _sendit(message.chat.id)
3428
except (FileIdInvalid, FileReferenceEmpty, BadRequest):
35-
await refresh_data()
36-
await sendit(message.chat.id, output)
29+
await _refresh_data()
30+
await _sendit(message.chat.id)
3731

3832

39-
async def refresh_data():
33+
async def _refresh_data():
4034
LOGO_DATA.clear()
4135
for msg in await bot.get_messages('UserGeOt', MSG_IDS):
4236
if not msg.animation:
@@ -45,9 +39,14 @@ async def refresh_data():
4539
LOGO_DATA.append((gif.file_id, gif.file_ref))
4640

4741

48-
async def sendit(chat_id, caption):
42+
async def _sendit(chat_id):
4943
if not LOGO_DATA:
50-
await refresh_data()
44+
await _refresh_data()
45+
caption = f"""
46+
**🤖 Bot Uptime** : `{time_formatter(time.time() - START_TIME)}`
47+
**🤖 Bot Version** : `{versions.__assistant_version__}`
48+
**️️⭐ Python** : `{versions.__python_version__}`
49+
**💥 Pyrogram** : `{versions.__pyro_version__}` """
5150
button = InlineKeyboardMarkup(
5251
[
5352
[

assistant/plugins/antiflood.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
@bot.on_message(
2222
Filters.incoming & ~Filters.edited & filters.auth_chats & ~filters.auth_users, group=1)
23-
async def flood(_, message: Message):
23+
async def _flood(_, message: Message):
2424
chat_flood = DATA.get(message.chat.id)
2525
if chat_flood is None:
2626
data = {

assistant/plugins/paste.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ async def get_paste_(_, message: Message):
129129
await msg.edit(f"`Request timed out -> {e_r}`")
130130
except TooManyRedirects as e_r:
131131
await msg.edit("`Request exceeded the configured `"
132-
f"`number of maximum redirections -> {e_r}`")
132+
f"`number of maximum redirections -> {e_r}`")
133133
except ClientResponseError as e_r:
134134
await msg.edit(f"`Request returned an unsuccessful status code -> {e_r}`")
135135
else:
136136
if len(text) > Config.MAX_MSG_LENGTH:
137137
await msg.edit("`Content Too Large...`")
138138
else:
139139
await msg.edit("--Fetched Content Successfully!--"
140-
f"\n\n**Content** :\n`{text}`")
140+
f"\n\n**Content** :\n`{text}`")

assistant/plugins/warn.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
@bot.on_message(
2525
Filters.command("warn") & filters.auth_chats & filters.auth_users)
26-
async def warn_user(_, msg: Message):
26+
async def _warn_user(_, msg: Message):
2727
global WARN_MODE, WARN_LIMIT # pylint: disable=global-statement
2828

2929
replied = msg.reply_to_message
@@ -110,7 +110,7 @@ async def warn_user(_, msg: Message):
110110

111111

112112
@bot.on_callback_query(Filters.regex(pattern=r"rm_warn\((.+?)\)"))
113-
async def remove_warn(_, c_q: CallbackQuery):
113+
async def _remove_warn(_, c_q: CallbackQuery):
114114
user_id = int(c_q.matches[0].group(1))
115115
if is_admin(c_q.message.chat.id, c_q.from_user.id, check_devs=True):
116116
if DATA.get(user_id):
@@ -133,7 +133,7 @@ async def remove_warn(_, c_q: CallbackQuery):
133133

134134
@bot.on_message(
135135
Filters.command("setwarn") & filters.auth_chats & filters.auth_users)
136-
async def set_warn_mode_and_limit(_, msg: Message):
136+
async def _set_warn_mode_and_limit(_, msg: Message):
137137
global WARN_MODE, WARN_LIMIT # pylint: disable=global-statement
138138
cmd = len(msg.text)
139139
if msg.text and cmd == 8:
@@ -151,7 +151,7 @@ async def set_warn_mode_and_limit(_, msg: Message):
151151
await msg.reply("`Warning Mode Updated to Mute`")
152152
elif args[0].isnumeric():
153153
input_ = int(args[0])
154-
if not input_ >= 3:
154+
if input_ < 3:
155155
await msg.reply("`Can't Warn Limit less then 3`")
156156
return
157157
WARN_LIMIT = input_
@@ -160,10 +160,9 @@ async def set_warn_mode_and_limit(_, msg: Message):
160160
await msg.reply("`Invalid arguments, Exiting...`")
161161

162162

163-
164163
@bot.on_message(
165164
Filters.command("resetwarn") & filters.auth_chats & filters.auth_users)
166-
async def reset_all_warns(_, msg: Message):
165+
async def _reset_all_warns(_, msg: Message):
167166
replied = msg.reply_to_message
168167
if not replied:
169168
return
@@ -185,7 +184,7 @@ async def reset_all_warns(_, msg: Message):
185184

186185

187186
@bot.on_message(Filters.command("warns") & filters.auth_chats)
188-
async def check_warns_of_user(_, msg: Message):
187+
async def _check_warns_of_user(_, msg: Message):
189188
global WARN_LIMIT # pylint: disable=global-statement
190189
replied = msg.reply_to_message
191190
if replied:
@@ -220,6 +219,7 @@ async def check_warns_of_user(_, msg: Message):
220219

221220

222221
async def sed(msg: Message):
222+
""" send default sticker """
223223
sticker = (await bot.get_messages('UserGeOt', 498697)).sticker
224224
file_id = sticker.file_id
225225
fileref = sticker.file_ref

0 commit comments

Comments
 (0)