From 33bf236af146011d3df28e37d9b6c05f19bb9697 Mon Sep 17 00:00:00 2001
From: Sourcery AI <>
Date: Wed, 12 Apr 2023 14:26:15 +0000
Subject: [PATCH] 'Refactored by Sourcery'
---
config.py | 6 ++---
helper_func.py | 12 ++++------
plugins/button.py | 60 +++++++++++++++++++++++++---------------------
plugins/heroku.py | 19 +++++++--------
plugins/updater.py | 3 +--
5 files changed, 50 insertions(+), 50 deletions(-)
diff --git a/config.py b/config.py
index 5245d9c..52e54d0 100644
--- a/config.py
+++ b/config.py
@@ -29,8 +29,8 @@
PROTECT_CONTENT = strtobool(os.environ.get("PROTECT_CONTENT", "False"))
# Heroku Credentials for updater.
-HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME", None)
-HEROKU_API_KEY = os.environ.get("HEROKU_API_KEY", None)
+HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME")
+HEROKU_API_KEY = os.environ.get("HEROKU_API_KEY")
# Custom Repo for updater.
UPSTREAM_BRANCH = os.environ.get("UPSTREAM_BRANCH", "master")
@@ -61,7 +61,7 @@
)
# Atur Teks Kustom Anda di sini, Simpan (None) untuk Menonaktifkan Teks Kustom
-CUSTOM_CAPTION = os.environ.get("CUSTOM_CAPTION", None)
+CUSTOM_CAPTION = os.environ.get("CUSTOM_CAPTION")
# Setel True jika Anda ingin Menonaktifkan tombol Bagikan Kiriman Saluran Anda
DISABLE_CHANNEL_BUTTON = strtobool(os.environ.get("DISABLE_CHANNEL_BUTTON", "False"))
diff --git a/helper_func.py b/helper_func.py
index bea6978..5f2bc5a 100644
--- a/helper_func.py
+++ b/helper_func.py
@@ -68,15 +68,13 @@ async def is_subscribed(filter, client, update):
async def encode(string):
string_bytes = string.encode("ascii")
base64_bytes = base64.urlsafe_b64encode(string_bytes)
- base64_string = (base64_bytes.decode("ascii")).strip("=")
- return base64_string
+ return (base64_bytes.decode("ascii")).strip("=")
async def decode(base64_string):
base64_string = base64_string.strip("=") # links generated before this commit will be having = sign, hence striping them to handle padding errors.
base64_bytes = (base64_string + "=" * (-len(base64_string) % 4)).encode("ascii")
- string_bytes = base64.urlsafe_b64decode(base64_bytes)
- string = string_bytes.decode("ascii")
- return string
+ string_bytes = base64.urlsafe_b64decode(base64_bytes)
+ return string_bytes.decode("ascii")
async def get_messages(client, message_ids):
@@ -113,8 +111,8 @@ async def get_message_id(client, message):
matches = re.match(pattern, message.text)
if not matches:
return 0
- channel_id = matches.group(1)
- msg_id = int(matches.group(2))
+ channel_id = matches[1]
+ msg_id = int(matches[2])
if channel_id.isdigit():
if f"-100{channel_id}" == str(client.db_channel.id):
return msg_id
diff --git a/plugins/button.py b/plugins/button.py
index 1598667..a1867ec 100644
--- a/plugins/button.py
+++ b/plugins/button.py
@@ -7,40 +7,47 @@
def start_button(client):
- if not FORCE_SUB_CHANNEL and not FORCE_SUB_GROUP:
- buttons = [
+ if not FORCE_SUB_CHANNEL:
+ return (
[
- InlineKeyboardButton(text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"),
- InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close"),
- ],
- ]
- return buttons
- if not FORCE_SUB_CHANNEL and FORCE_SUB_GROUP:
- buttons = [
- [
- InlineKeyboardButton(text="ɢʀᴏᴜᴘ", url=client.invitelink2),
- ],
- [
- InlineKeyboardButton(text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"),
- InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close"),
- ],
- ]
- return buttons
- if FORCE_SUB_CHANNEL and not FORCE_SUB_GROUP:
- buttons = [
+ [
+ InlineKeyboardButton(text="ɢʀᴏᴜᴘ", url=client.invitelink2),
+ ],
+ [
+ InlineKeyboardButton(
+ text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"
+ ),
+ InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close"),
+ ],
+ ]
+ if FORCE_SUB_GROUP
+ else [
+ [
+ InlineKeyboardButton(
+ text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"
+ ),
+ InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close"),
+ ],
+ ]
+ )
+ if not FORCE_SUB_GROUP:
+ return [
[
InlineKeyboardButton(text="ᴄʜᴀɴɴᴇʟ", url=client.invitelink),
],
[
- InlineKeyboardButton(text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"),
+ InlineKeyboardButton(
+ text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"
+ ),
InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close"),
],
]
- return buttons
- if FORCE_SUB_CHANNEL and FORCE_SUB_GROUP:
- buttons = [
+ if FORCE_SUB_CHANNEL:
+ return [
[
- InlineKeyboardButton(text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"),
+ InlineKeyboardButton(
+ text="ʜᴇʟᴘ & ᴄᴏᴍᴍᴀɴᴅs", callback_data="help"
+ ),
],
[
InlineKeyboardButton(text="ᴄʜᴀɴɴᴇʟ", url=client.invitelink),
@@ -48,7 +55,6 @@ def start_button(client):
],
[InlineKeyboardButton(text="ᴛᴜᴛᴜᴘ", callback_data="close")],
]
- return buttons
def fsub_button(client, message):
@@ -88,7 +94,7 @@ def fsub_button(client, message):
except IndexError:
pass
return buttons
- if FORCE_SUB_CHANNEL and FORCE_SUB_GROUP:
+ if FORCE_SUB_CHANNEL:
buttons = [
[
InlineKeyboardButton(text="ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ", url=client.invitelink),
diff --git a/plugins/heroku.py b/plugins/heroku.py
index 8e906ab..2abe2fe 100644
--- a/plugins/heroku.py
+++ b/plugins/heroku.py
@@ -73,13 +73,12 @@ async def varget_(client: Bot, message: Message):
path = dotenv.find_dotenv("config.env")
if not path:
return await message.reply_text(".env file not found.")
- output = dotenv.get_key(path, check_var)
- if not output:
- await message.reply_text(f"Tidak dapat menemukan var {check_var}")
- else:
+ if output := dotenv.get_key(path, check_var):
return await message.reply_text(
f"{check_var}: {str(output)}"
)
+ else:
+ await message.reply_text(f"Tidak dapat menemukan var {check_var}")
@Bot.on_message(filters.command("delvar") & filters.user(ADMINS))
@@ -93,11 +92,10 @@ async def vardel_(client: Bot, message: Message):
"Pastikan HEROKU_API_KEY dan HEROKU_APP_NAME anda dikonfigurasi dengan benar di config vars heroku"
)
heroku_config = HAPP.config()
- if check_var in heroku_config:
- await message.reply_text(f"Berhasil Menghapus var {check_var}")
- del heroku_config[check_var]
- else:
+ if check_var not in heroku_config:
return await message.reply_text(f"Tidak dapat menemukan var {check_var}")
+ await message.reply_text(f"Berhasil Menghapus var {check_var}")
+ del heroku_config[check_var]
else:
path = dotenv.find_dotenv("config.env")
if not path:
@@ -105,9 +103,8 @@ async def vardel_(client: Bot, message: Message):
output = dotenv.unset_key(path, check_var)
if not output[0]:
return await message.reply_text(f"Tidak dapat menemukan var {check_var}")
- else:
- await message.reply_text(f"Berhasil Menghapus var {check_var}")
- os.system(f"kill -9 {os.getpid()} && bash start")
+ await message.reply_text(f"Berhasil Menghapus var {check_var}")
+ os.system(f"kill -9 {os.getpid()} && bash start")
@Bot.on_message(filters.command("setvar") & filters.user(ADMINS))
diff --git a/plugins/updater.py b/plugins/updater.py
index 9f27c25..f527270 100644
--- a/plugins/updater.py
+++ b/plugins/updater.py
@@ -61,8 +61,7 @@ def updater():
async def update_bot(_, message: Message):
message.chat.id
msg = await message.reply_text("Checking updates...")
- update_avail = updater()
- if update_avail:
+ if update_avail := updater():
await msg.edit("✅ Update finished !")
system("git pull -f && pip3 install --no-cache-dir -r requirements.txt")
execle(sys.executable, sys.executable, "main.py", environ)