-
-
Notifications
You must be signed in to change notification settings - Fork 82
Sourcery refactored master branch #65
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: master
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 |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ | |
| if not hasattr(imported_module, "__mod_name__"): | ||
| imported_module.__mod_name__ = imported_module.__name__ | ||
|
|
||
| if not imported_module.__mod_name__.lower() in IMPORTED: | ||
| if imported_module.__mod_name__.lower() not in IMPORTED: | ||
| IMPORTED[imported_module.__mod_name__.lower()] = imported_module | ||
| else: | ||
| raise Exception( | ||
|
|
@@ -242,13 +242,11 @@ def help_button(bot: Bot, update: Update): | |
| bot.answer_callback_query(query.id) | ||
| query.message.delete() | ||
| except BadRequest as excp: | ||
| if excp.message == "Message is not modified": | ||
| pass | ||
| elif excp.message == "Query_id_invalid": | ||
| pass | ||
| elif excp.message == "Message can't be deleted": | ||
| pass | ||
| else: | ||
| if ( | ||
| excp.message != "Message is not modified" | ||
| and excp.message != "Query_id_invalid" | ||
| and excp.message != "Message can't be deleted" | ||
| ): | ||
|
Comment on lines
-245
to
+249
Contributor
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
|
||
| LOGGER.exception("Exception in help buttons. %s", str(query.data)) | ||
|
|
||
|
|
||
|
|
@@ -379,13 +377,11 @@ def settings_button(bot: Bot, update: Update): | |
| bot.answer_callback_query(query.id) | ||
| query.message.delete() | ||
| except BadRequest as excp: | ||
| if excp.message == "Message is not modified": | ||
| pass | ||
| elif excp.message == "Query_id_invalid": | ||
| pass | ||
| elif excp.message == "Message can't be deleted": | ||
| pass | ||
| else: | ||
| if ( | ||
| excp.message != "Message is not modified" | ||
| and excp.message != "Query_id_invalid" | ||
| and excp.message != "Message can't be deleted" | ||
| ): | ||
|
Comment on lines
-382
to
+384
Contributor
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
|
||
| LOGGER.exception( | ||
| "Exception in settings buttons. %s", str( | ||
| query.data)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ def promote(bot: Bot, update: Update, args: List[str]) -> str: | |
| except Exception: | ||
| return log_message | ||
|
|
||
| if user_member.status == 'administrator' or user_member.status == 'creator': | ||
| if user_member.status in ['administrator', 'creator']: | ||
|
Contributor
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
|
||
| message.reply_text("How am I meant to promote someone that's already an admin?") | ||
| return log_message | ||
|
|
||
|
|
@@ -61,11 +61,9 @@ def promote(bot: Bot, update: Update, args: List[str]) -> str: | |
| except BadRequest as err: | ||
| if err.message == "User_not_mutual_contact": | ||
| message.reply_text("I can't promote someone who isn't in the group.") | ||
| return log_message | ||
| else: | ||
| message.reply_text("An error occured while promoting.") | ||
| return log_message | ||
|
|
||
| return log_message | ||
| bot.sendMessage(chat.id, f"Sucessfully promoted <b>{user_member.user.first_name or user_id}</b>!", | ||
| parse_mode=ParseMode.HTML) | ||
|
|
||
|
|
@@ -104,7 +102,7 @@ def demote(bot: Bot, update: Update, args: List[str]) -> str: | |
| message.reply_text("This person CREATED the chat, how would I demote them?") | ||
| return log_message | ||
|
|
||
| if not user_member.status == 'administrator': | ||
| if user_member.status != 'administrator': | ||
|
Comment on lines
-107
to
+105
Contributor
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
|
||
| message.reply_text("Can't demote what wasn't promoted!") | ||
| return log_message | ||
|
|
||
|
|
@@ -163,7 +161,7 @@ def set_title(bot: Bot, update: Update, args: List[str]): | |
| message.reply_text("This person CREATED the chat, how can i set custom title for him?") | ||
| return | ||
|
|
||
| if not user_member.status == 'administrator': | ||
| if user_member.status != 'administrator': | ||
|
Comment on lines
-166
to
+164
Contributor
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
|
||
| message.reply_text("Can't set title for non-admins!\nPromote them first to set custom title!") | ||
| return | ||
|
|
||
|
|
@@ -256,7 +254,7 @@ def invite(bot: Bot, update: Update): | |
|
|
||
| if chat.username: | ||
| update.effective_message.reply_text(chat.username) | ||
| elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL: | ||
| elif chat.type in [chat.SUPERGROUP, chat.CHANNEL]: | ||
|
Comment on lines
-259
to
+257
Contributor
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_member = chat.get_member(bot.id) | ||
| if bot_member.can_invite_users: | ||
| invitelink = bot.exportChatInviteLink(chat.id) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,6 @@ def formatJSON(outData): | |
| res = list(jsonData.keys()) | ||
| if "errors" in res: | ||
| msg += f"**Error** : `{jsonData['errors'][0]['message']}`" | ||
| return msg | ||
|
Contributor
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: | ||
| jsonData = jsonData['data']['Media'] | ||
| if "bannerImage" in jsonData.keys(): | ||
|
|
@@ -78,7 +77,8 @@ def formatJSON(outData): | |
| msg += f"\n**Score** : {jsonData['averageScore']}" | ||
| msg += f"\n**Duration** : {jsonData['duration']} min" | ||
| msg += f"\n\n __{jsonData['description']}__" | ||
| return msg | ||
|
|
||
| return msg | ||
|
|
||
|
|
||
| @run_async | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,12 +104,9 @@ def set_flood(_bot: Bot, update: Update, args: List[str]) -> str: | |
| f"<b>Admin</b>: {mention_html(user.id, user.first_name)}\n" | ||
| f"Disabled antiflood.") | ||
|
|
||
| return log_message | ||
| elif amount < 3: | ||
| message.reply_text( | ||
| "Antiflood has to be either 0 (disabled), or a number bigger than 3!") | ||
| return log_message | ||
|
|
||
|
Comment on lines
-107
to
-112
Contributor
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: | ||
| sql.set_flood(chat.id, amount) | ||
| message.reply_text( | ||
|
|
@@ -121,7 +118,7 @@ def set_flood(_bot: Bot, update: Update, args: List[str]) -> str: | |
| f"<b>Admin</b>: {mention_html(user.id, user.first_name)}\n" | ||
| f"Set antiflood to <code>{amount}</code>.") | ||
|
|
||
| return log_message | ||
| return log_message | ||
| else: | ||
| message.reply_text( | ||
| "Unrecognised argument - please use a number, 'off', or 'no'.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,11 +153,7 @@ def temp_ban(bot: Bot, update: Update, args: List[str]) -> str: | |
| split_reason = reason.split(None, 1) | ||
|
|
||
| time_val = split_reason[0].lower() | ||
| if len(split_reason) > 1: | ||
| reason = split_reason[1] | ||
| else: | ||
| reason = "" | ||
|
|
||
| reason = split_reason[1] if len(split_reason) > 1 else "" | ||
|
Contributor
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
|
||
| bantime = extract_time(message, time_val) | ||
|
|
||
| if not bantime: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ def blacklist(_bot: Bot, update: Update, args: List[str]): | |
|
|
||
| filter_list = base_blacklist_string | ||
|
|
||
| if len(args) > 0 and args[0].lower() == 'copy': | ||
| if args and args[0].lower() == 'copy': | ||
|
Contributor
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
|
||
| for trigger in all_blacklisted: | ||
| filter_list += f"<code>{html.escape(trigger)}</code>\n" | ||
| else: | ||
|
|
@@ -150,9 +150,7 @@ def del_blacklist(_bot: Bot, update: Update): | |
| try: | ||
| message.delete() | ||
| except BadRequest as excp: | ||
| if excp.message == "Message to delete not found": | ||
| pass | ||
| else: | ||
| if excp.message != "Message to delete not found": | ||
|
Contributor
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
|
||
| LOGGER.exception("Error while deleting blacklist message.") | ||
| break | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,7 @@ def blackliststicker(bot: Bot, update: Update, args: List[str]): | |
|
|
||
| all_stickerlist = sql.get_chat_stickers(chat_id) | ||
|
|
||
| if len(args) > 0 and args[0].lower() == 'copy': | ||
| if args and args[0].lower() == 'copy': | ||
|
Contributor
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
|
||
| for trigger in all_stickerlist: | ||
| sticker_list += "<code>{}</code>\n".format(html.escape(trigger)) | ||
| elif len(args) == 0: | ||
|
|
@@ -257,11 +257,10 @@ def blacklist_mode(bot: Bot, update: Update, args: List[str]): | |
| chat_name = update.effective_message.chat.title | ||
|
|
||
| if args: | ||
| if args[0].lower() == 'off' or args[0].lower( | ||
| ) == 'nothing' or args[0].lower() == 'no': | ||
| if args[0].lower() in ['off', 'nothing', 'no']: | ||
| settypeblacklist = 'turn off' | ||
| sql.set_blacklist_strength(chat_id, 0, "0") | ||
| elif args[0].lower() == 'del' or args[0].lower() == 'delete': | ||
| elif args[0].lower() in ['del', 'delete']: | ||
|
Comment on lines
-260
to
+263
Contributor
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
|
||
| settypeblacklist = 'left, the message will be deleted' | ||
| sql.set_blacklist_strength(chat_id, 1, "0") | ||
| elif args[0].lower() == 'warn': | ||
|
|
@@ -446,9 +445,7 @@ def del_blackliststicker(bot: Bot, update: Update): | |
| parse_mode="markdown") | ||
| return | ||
| except BadRequest as excp: | ||
| if excp.message == "Message to delete not found": | ||
| pass | ||
| else: | ||
| if excp.message != "Message to delete not found": | ||
|
Comment on lines
-449
to
+448
Contributor
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
|
||
| LOGGER.exception("Error while deleting blacklist message.") | ||
| break | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,11 +120,7 @@ def bl_users(bot: Bot, update: Update): | |
| users.append(f"• {mention_html(user.id, user.first_name)}") | ||
|
|
||
| message = "<b>Blacklisted Users</b>\n" | ||
| if not users: | ||
| message += "Noone is being ignored as of yet." | ||
| else: | ||
| message += '\n'.join(users) | ||
|
|
||
| message += '\n'.join(users) if users else "Noone is being ignored as of yet." | ||
|
Contributor
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
|
||
| update.effective_message.reply_text(message, parse_mode=ParseMode.HTML) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,7 @@ | |
| from lynda.modules.helper_funcs.chat_status import user_admin, bot_can_delete, dev_plus, connection_status | ||
| from lynda.modules.sql import cleaner_sql as sql | ||
|
|
||
| if ALLOW_EXCL: | ||
| CMD_STARTERS = ('/', '!') | ||
| else: | ||
| CMD_STARTERS = '/' | ||
|
|
||
| CMD_STARTERS = ('/', '!') if ALLOW_EXCL else '/' | ||
|
Contributor
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. Lines
|
||
| BLUE_TEXT_CLEAN_GROUP = 15 | ||
| CommandHandlerList = ( | ||
| CommandHandler, | ||
|
|
@@ -43,24 +39,23 @@ | |
| def clean_blue_text_must_click(bot: Bot, update: Update): | ||
|
|
||
| chat = update.effective_chat | ||
| message = update.effective_message | ||
| if chat.get_member(bot.id).can_delete_messages and sql.is_enabled(chat.id): | ||
| message = update.effective_message | ||
|
|
||
| if chat.get_member(bot.id).can_delete_messages: | ||
| if sql.is_enabled(chat.id): | ||
| fst_word = message.text.strip().split(None, 1)[0] | ||
| fst_word = message.text.strip().split(None, 1)[0] | ||
|
|
||
| if len(fst_word) > 1 and any(fst_word.startswith(start) | ||
| for start in CMD_STARTERS): | ||
| if len(fst_word) > 1 and any(fst_word.startswith(start) | ||
| for start in CMD_STARTERS): | ||
|
|
||
| command = fst_word[1:].split('@') | ||
| chat = update.effective_chat | ||
| command = fst_word[1:].split('@') | ||
| chat = update.effective_chat | ||
|
|
||
| ignored = sql.is_command_ignored(chat.id, command[0]) | ||
| if ignored: | ||
| return | ||
| ignored = sql.is_command_ignored(chat.id, command[0]) | ||
| if ignored: | ||
| return | ||
|
|
||
| if command[0] not in command_list: | ||
| message.delete() | ||
| if command[0] not in command_list: | ||
| message.delete() | ||
|
Comment on lines
-46
to
+58
Contributor
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
|
||
|
|
||
|
|
||
| @run_async | ||
|
|
@@ -91,10 +86,7 @@ def set_blue_text_must_click(_bot: Bot, update: Update, args: List[str]): | |
| message.reply_text(reply) | ||
| else: | ||
| clean_status = sql.is_enabled(chat.id) | ||
| if clean_status: | ||
| clean_status = "Enabled" | ||
| else: | ||
| clean_status = "Disabled" | ||
| clean_status = "Enabled" if clean_status else "Disabled" | ||
|
Comment on lines
-94
to
+89
Contributor
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
|
||
| reply = "Bluetext cleaning for <b>{}</b> : <b>{}</b>".format( | ||
| chat.title, clean_status) | ||
| message.reply_text(reply, parse_mode=ParseMode.HTML) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,18 +215,18 @@ def reply_filter(bot: Bot, update: Update): | |
| disable_web_page_preview=True, | ||
| reply_markup=keyboard) | ||
| except BadRequest as excp: | ||
| if excp.message == "Unsupported url protocol": | ||
| message.reply_text( | ||
| "You seem to be trying to use an unsupported url protocol. Telegram " | ||
| "doesn't support buttons for some protocols, such as tg://. Please try " | ||
| "again, or ask @Aman_Ahmed for help.") | ||
| elif excp.message == "Reply message not found": | ||
| if excp.message == "Reply message not found": | ||
| bot.send_message( | ||
| chat.id, | ||
| filt.reply, | ||
| parse_mode=ParseMode.MARKDOWN, | ||
| disable_web_page_preview=True, | ||
| reply_markup=keyboard) | ||
| elif excp.message == "Unsupported url protocol": | ||
| message.reply_text( | ||
| "You seem to be trying to use an unsupported url protocol. Telegram " | ||
| "doesn't support buttons for some protocols, such as tg://. Please try " | ||
| "again, or ask @Aman_Ahmed for help.") | ||
|
Comment on lines
-218
to
+229
Contributor
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: | ||
| message.reply_text( | ||
| "This note could not be sent, as it is incorrectly formatted. Ask in " | ||
|
|
||
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
75-75refactored with the following changes:de-morgan)