-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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("=") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| 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") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| 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]) | ||
|
Comment on lines
-116
to
+115
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if channel_id.isdigit(): | ||
| if f"-100{channel_id}" == str(client.db_channel.id): | ||
| return msg_id | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,48 +7,54 @@ | |
|
|
||
|
|
||
| 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" | ||
| ), | ||
|
Comment on lines
-10
to
+50
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| ], | ||
| [ | ||
| InlineKeyboardButton(text="ᴄʜᴀɴɴᴇʟ", url=client.invitelink), | ||
| InlineKeyboardButton(text="ɢʀᴏᴜᴘ", url=client.invitelink2), | ||
| ], | ||
| [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: | ||
|
Comment on lines
-91
to
+97
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| buttons = [ | ||
| [ | ||
| InlineKeyboardButton(text="ᴊᴏɪɴ ᴄʜᴀɴɴᴇʟ", url=client.invitelink), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"<b>{check_var}:</b> <code>{str(output)}</code>" | ||
| ) | ||
| else: | ||
| await message.reply_text(f"Tidak dapat menemukan var {check_var}") | ||
|
Comment on lines
-76
to
+81
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @Bot.on_message(filters.command("delvar") & filters.user(ADMINS)) | ||
|
|
@@ -93,21 +92,19 @@ 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] | ||
|
Comment on lines
-96
to
+98
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| else: | ||
| path = dotenv.find_dotenv("config.env") | ||
| if not path: | ||
| return await message.reply_text(".env file not found.") | ||
| 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)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
32-64refactored with the following changes:dict.get(x, None)withdict.get(x)[×3] (remove-none-from-default-get)