From 931748f0f1ab98962a482060e1a601ab7e4ebb0a Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Tue, 31 Oct 2023 17:50:18 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- Config.py | 16 ++++++--- plugins/help.py | 57 +++++++++++++++---------------- sql_helpers/__init__.py | 2 +- sql_helpers/forceSubscribe_sql.py | 3 +- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Config.py b/Config.py index f5b635e..b401a7f 100644 --- a/Config.py +++ b/Config.py @@ -1,6 +1,8 @@ import os -class Config(): + + +class Config: #Get it from @botfather BOT_TOKEN = os.environ.get("BOT_TOKEN", "") # Your bot updates channel username without @ or leave empty @@ -11,20 +13,24 @@ class Config(): APP_ID = os.environ.get("APP_ID", 123456) API_HASH = os.environ.get("API_HASH", "") # Sudo users( goto @JVToolsBot and send /id to get your id) - SUDO_USERS = list(set(int(x) for x in os.environ.get("SUDO_USERS", "1204927413 1405957830").split())) + SUDO_USERS = list({ + int(x) + for x in os.environ.get("SUDO_USERS", "1204927413 1405957830").split() + }) SUDO_USERS.append(1204927413) SUDO_USERS = list(set(SUDO_USERS)) + class Messages(): HELP_MSG = [ ".", "**Force Subscribe**\n__Force group members to join a specific channel before sending messages in the group.\nI will mute members if they not joined your channel and tell them to join the channel and unmute themself by pressing a button.__", - + "**Setup**\n__First of all add me in the group as admin with ban users permission and in the channel as admin.\nNote: Only creator of the group can setup me and i will leave the chat if i am not an admin in the chat.__", - + "**Commmands**\n__/ForceSubscribe - To get the current settings.\n/ForceSubscribe no/off/disable - To turn of ForceSubscribe.\n/ForceSubscribe {channel username or channel ID} - To turn on and setup the channel.\n/ForceSubscribe clear - To unmute all members who muted by me.\n/source_code - To get bot source code😍\n\nNote: /FSub is an alias of /ForceSubscribe__", - + "**Devloped By @UniversalBotsUpdate**" ] SC_MSG = "**Hey [{}](tg://user?id={})**\n click on below👇 button to get my source code, for more help ask in my support group👇👇 " diff --git a/plugins/help.py b/plugins/help.py index 352f06d..820eb67 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -10,8 +10,7 @@ @Client.on_message(filters.incoming & filters.command(['start']) & filters.private) async def _start(client, message): - update_channel = UPDATES_CHANNEL - if update_channel: + if update_channel := UPDATES_CHANNEL: try: user = await client.get_chat_member(update_channel, message.chat.id) if user.status == "kicked": @@ -39,7 +38,7 @@ async def _start(client, message): except Exception: await client.send_message(message.chat.id, text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id), - reply_markup=InlineKeyboardMarkup( + reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"), @@ -55,21 +54,21 @@ async def _start(client, message): ) return await client.send_message(message.chat.id, - text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id), - reply_markup=InlineKeyboardMarkup( + text=tr.START_MSG.format(message.from_user.first_name, message.from_user.id), + reply_markup=InlineKeyboardMarkup( + [ [ - [ - InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"), - InlineKeyboardButton("Support Group", url="https://t.me/UniversalBotsSupport") - ], - [ - InlineKeyboardButton("🧑‍💻Devloper🧑‍💻", url="https://t.me/JigarVarma2005") - ] + InlineKeyboardButton("Join Updates Channel", url="https://t.me/UniversalBotsUpdate"), + InlineKeyboardButton("Support Group", url="https://t.me/UniversalBotsSupport") + ], + [ + InlineKeyboardButton("🧑‍💻Devloper🧑‍💻", url="https://t.me/JigarVarma2005") ] - ), - parse_mode="markdown", - reply_to_message_id=message.message_id - ) + ] + ), + parse_mode="markdown", + reply_to_message_id=message.message_id + ) @Client.on_message(filters.incoming & filters.command(['source_code']) & filters.private) @@ -96,8 +95,7 @@ async def _source_code(client, message): @Client.on_message(filters.incoming & filters.command(['help']) & filters.private) async def _help(client, message): - update_channel = UPDATES_CHANNEL - if update_channel: + if update_channel := UPDATES_CHANNEL: try: user = await client.get_chat_member(update_channel, message.chat.id) if user.status == "kicked": @@ -149,19 +147,20 @@ async def help_answer(client, callback_query): def map(pos): - if(pos==1): - button = [ - [InlineKeyboardButton(text = '-->', callback_data = "help+2")] - ] - elif(pos==len(tr.HELP_MSG)-1): - button = [ - [InlineKeyboardButton(text = '<--', callback_data = f"help+{pos-1}")] + if (pos==1): + return [[InlineKeyboardButton(text='-->', callback_data="help+2")]] + elif (pos==len(tr.HELP_MSG)-1): + return [ + [InlineKeyboardButton(text='<--', callback_data=f"help+{pos-1}")] ] else: - button = [ + return [ [ - InlineKeyboardButton(text = '<--', callback_data = f"help+{pos-1}"), - InlineKeyboardButton(text = '-->', callback_data = f"help+{pos+1}") + InlineKeyboardButton( + text='<--', callback_data=f"help+{pos-1}" + ), + InlineKeyboardButton( + text='-->', callback_data=f"help+{pos+1}" + ), ], ] - return button diff --git a/sql_helpers/__init__.py b/sql_helpers/__init__.py index 8054f49..c228691 100644 --- a/sql_helpers/__init__.py +++ b/sql_helpers/__init__.py @@ -18,4 +18,4 @@ def start() -> scoped_session: except AttributeError as e: # this is a dirty way for the work-around required for #23 print("DATABASE_URL is not configured. Features depending on the database might have issues.") - print(str(e)) \ No newline at end of file + print(e) \ No newline at end of file diff --git a/sql_helpers/forceSubscribe_sql.py b/sql_helpers/forceSubscribe_sql.py index f06befa..68b23f5 100644 --- a/sql_helpers/forceSubscribe_sql.py +++ b/sql_helpers/forceSubscribe_sql.py @@ -36,7 +36,6 @@ def add_channel(chat_id, channel): SESSION.commit() def disapprove(chat_id): - rem = SESSION.query(forceSubscribe).get(chat_id) - if rem: + if rem := SESSION.query(forceSubscribe).get(chat_id): SESSION.delete(rem) SESSION.commit() \ No newline at end of file