From a144162f46013c92e6740fa175348002a8d588c5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 18 Aug 2021 08:54:39 +0000 Subject: [PATCH] Refactor unnecessary `else` / `elif` when `if` block has a `return` statement --- Stella/StellaGban.py | 75 ++++---- Stella/database/antiflood_mongo.py | 16 +- Stella/database/blocklists_mongo.py | 23 ++- Stella/database/chats_settings_mongo.py | 3 +- Stella/database/connection_mongo.py | 23 ++- Stella/database/disable_mongo.py | 6 +- Stella/database/federation_mongo.py | 67 ++++--- Stella/database/filters_mongo.py | 13 +- Stella/database/locks_mongo.py | 9 +- Stella/database/log_channels_mongo.py | 11 +- Stella/database/notes_mongo.py | 37 ++-- Stella/database/pin_mongo.py | 6 +- Stella/database/report_mongo.py | 3 +- Stella/database/rules_mongo.py | 9 +- Stella/database/users_mongo.py | 9 +- Stella/database/warnings_mongo.py | 16 +- Stella/database/welcome_mongo.py | 168 ++++++++---------- Stella/helper/chat_status.py | 133 +++++++------- Stella/helper/disable.py | 3 +- Stella/helper/get_data.py | 21 ++- Stella/helper/get_user.py | 33 ++-- Stella/helper/time_checker.py | 13 +- Stella/plugins/antiflood/setflood.py | 4 +- Stella/plugins/blocklists/checker.py | 6 +- Stella/plugins/connection/connection.py | 15 +- .../plugins/greeting/captcha/text_captcha.py | 24 ++- Stella/plugins/notes/clear_note.py | 24 +-- Stella/plugins/owner/export.py | 7 +- Stella/plugins/pin/antichannelpin_checker.py | 3 +- Stella/plugins/pin/cleanlinked_checker.py | 3 +- Stella/plugins/purge/purge_between.py | 114 ++++++------ Stella/plugins/start/startHandler.py | 13 +- Stella/plugins/warnings/warn_checker.py | 20 +-- 33 files changed, 429 insertions(+), 501 deletions(-) diff --git a/Stella/StellaGban.py b/Stella/StellaGban.py index 4ef239e..bd4ff1f 100644 --- a/Stella/StellaGban.py +++ b/Stella/StellaGban.py @@ -65,19 +65,18 @@ def ungban_protocol(self, user_id): ) ReturnedJson = ReturnedData.json() - if ReturnedData.status_code == requests.codes.ok: - status = ReturnedJson['status'] - operation = ReturnedJson['operation'] - - return ( - status, - operation - ) - else: - return ( - 'Server is currently down!', - False - ) + if ReturnedData.status_code == requests.codes.ok: + status = ReturnedJson['status'] + operation = ReturnedJson['operation'] + + return ( + status, + operation + ) + return ( + 'Server is currently down!', + False + ) def banned_list(self) -> list: URL = f'{self.host}/admin/users/' @@ -112,19 +111,18 @@ def generate_api(self, user_id, first_name, username): ) ReturnedJson = ReturnedData.json() - if ReturnedData.status_code == requests.codes.ok: - api_key = ReturnedJson['api_key'] - operation = ReturnedJson['operation'] - - return ( - operation, - api_key - ) - else: - return ( - 'Server is currently down!', - False - ) + if ReturnedData.status_code == requests.codes.ok: + api_key = ReturnedJson['api_key'] + operation = ReturnedJson['operation'] + + return ( + operation, + api_key + ) + return ( + 'Server is currently down!', + False + ) def promote_api(self, user_id): URL = f'{self.host}/admin/promote/' @@ -139,16 +137,15 @@ def promote_api(self, user_id): ) ReturnedJson = ReturnedData.json() - if ReturnedData.status_code == requests.codes.ok: - status = ReturnedJson['status'] - operation = ReturnedJson['operation'] - - return ( - status, - operation - ) - else: - return ( - 'Server is currently down!', - False - ) + if ReturnedData.status_code == requests.codes.ok: + status = ReturnedJson['status'] + operation = ReturnedJson['operation'] + + return ( + status, + operation + ) + return ( + 'Server is currently down!', + False + ) diff --git a/Stella/database/antiflood_mongo.py b/Stella/database/antiflood_mongo.py index 6b4b875..8d2cd96 100644 --- a/Stella/database/antiflood_mongo.py +++ b/Stella/database/antiflood_mongo.py @@ -88,8 +88,7 @@ def get_flood(chat_id: int) -> bool: ) if antiflood_data is not None: return antiflood_data['flood'] - else: - return False + return False def set_antiflood_mode(chat_id, flood_mode, until_time=None): antiflood_data = antiflood.find_one( @@ -140,10 +139,9 @@ def get_antiflood_mode(chat_id): FloodMode, Flood_until_time ) - else: - FloodMode = 1 - Flood_until_time = None - return ( - FloodMode, - Flood_until_time - ) \ No newline at end of file + FloodMode = 1 + Flood_until_time = None + return ( + FloodMode, + Flood_until_time + ) diff --git a/Stella/database/blocklists_mongo.py b/Stella/database/blocklists_mongo.py index ead4bda..52a135a 100644 --- a/Stella/database/blocklists_mongo.py +++ b/Stella/database/blocklists_mongo.py @@ -197,8 +197,7 @@ def getblocklistMessageDelete(chat_id) -> bool: ) if blocklist_data is not None: return blocklist_data['blocklistdelete'] - else: - return True + return True def setblocklistmode(chat_id, blocklist_mode, blocklist_time=None): blocklist_data = blocklists.find_one( @@ -250,23 +249,21 @@ def getblocklistmode(chat_id): blocklist_mode = blocklist_data['blocklist_mode']['blocklist_mode'] blocklist_time = blocklist_data['blocklist_mode']['blocklist_time'] blocklist_default_reason = blocklist_data['blocklist_default_reason'] - + return ( blocklist_mode, blocklist_time, blocklist_default_reason ) + blocklist_mode = 1 + blocklist_time = None + blocklist_default_reason = None - else: - blocklist_mode = 1 - blocklist_time = None - blocklist_default_reason = None - - return ( - blocklist_mode, - blocklist_time, - blocklist_default_reason - ) + return ( + blocklist_mode, + blocklist_time, + blocklist_default_reason + ) def setblocklistreason_db(chat_id, reason): blocklist_data = blocklists.find_one( diff --git a/Stella/database/chats_settings_mongo.py b/Stella/database/chats_settings_mongo.py index 53d943d..c4ca08a 100644 --- a/Stella/database/chats_settings_mongo.py +++ b/Stella/database/chats_settings_mongo.py @@ -62,7 +62,6 @@ def get_anon_setting(chat_id) -> bool: if chat_data is not None: if 'anon_admin' in chat_data: return chat_data['anon_admin'] - else: - return False + return False else: return False \ No newline at end of file diff --git a/Stella/database/connection_mongo.py b/Stella/database/connection_mongo.py index 4054db3..422a095 100644 --- a/Stella/database/connection_mongo.py +++ b/Stella/database/connection_mongo.py @@ -62,11 +62,10 @@ def GetConnectedChat(user_id): 'user_id': user_id } ) - if connectionData is not None: - chat_id = connectionData['connected_chat'] - return chat_id - else: - return None + if connectionData is not None: + chat_id = connectionData['connected_chat'] + return chat_id + return None def isChatConnected(user_id) -> bool: connectionData = connection.find_one( @@ -74,10 +73,9 @@ def isChatConnected(user_id) -> bool: 'user_id': user_id } ) - if connectionData is not None: - return connectionData['connection'] - else: - return False + if connectionData is not None: + return connectionData['connection'] + return False def disconnectChat(user_id): connection.update_one( @@ -144,8 +142,7 @@ def get_allow_connection(chat_id)-> bool: } ) if chat_data is not None: - if 'allow_collection' in chat_data: - return chat_data['allow_collection'] - else: - return False + if 'allow_collection' in chat_data: + return chat_data['allow_collection'] + return False return False \ No newline at end of file diff --git a/Stella/database/disable_mongo.py b/Stella/database/disable_mongo.py index 98590d4..1d8eac0 100644 --- a/Stella/database/disable_mongo.py +++ b/Stella/database/disable_mongo.py @@ -80,8 +80,7 @@ def get_disabled(chat_id) -> list: if disable_data is not None: return disable_data['disabled_items'] - else: - return [] + return [] def disabledel_db(chat_id, disabledel): disable_data = disable.find_one( @@ -120,5 +119,4 @@ def get_disabledel(chat_id) -> bool: ) if disable_data is not None: return disable_data['disabledel'] - else: - return False \ No newline at end of file + return False diff --git a/Stella/database/federation_mongo.py b/Stella/database/federation_mongo.py index f92a24a..531031c 100644 --- a/Stella/database/federation_mongo.py +++ b/Stella/database/federation_mongo.py @@ -47,11 +47,10 @@ def is_fed_exist(fed_id=None, owner_id=None) -> bool: 'owner_id': owner_id } ) - - if GetFed is not None: - return True - else: - return False + + if GetFed is not None: + return True + return False else: GetFed = federation.find_one( @@ -59,10 +58,9 @@ def is_fed_exist(fed_id=None, owner_id=None) -> bool: 'fed_id': fed_id } ) - if GetFed is not None: - return True - else: - return False + if GetFed is not None: + return True + return False def join_fed_db(chat_id, chat_title, fed_id): federation.update_one( @@ -128,10 +126,9 @@ def is_user_fban(fed_id, user_id) -> bool: for users in GetFed['banned_users']: banned_user = users['user_id'] user_ids_list.append(banned_user) - if user_id in user_ids_list: - return True - else: - return False + if user_id in user_ids_list: + return True + return False else: return False else: @@ -162,11 +159,10 @@ def get_fed_from_chat(chat_id): } } ): - if 'fed_id' in fedData: - fed_id = fedData['fed_id'] - return fed_id - else: - return None + if 'fed_id' in fedData: + fed_id = fedData['fed_id'] + return fed_id + return None def get_fed_from_ownerid(owner_id): fedData = federation.find_one( @@ -174,11 +170,10 @@ def get_fed_from_ownerid(owner_id): 'owner_id': owner_id } ) - if not fedData == None: - fed_id = fedData['fed_id'] - return fed_id - else: - return None + if not fedData == None: + fed_id = fedData['fed_id'] + return fed_id + return None def get_fed_reason(fed_id, user_id): fedData = federation.find_one( @@ -200,13 +195,12 @@ def get_connected_chats(fed_id) -> list: } ) connected_chats = [] - if 'chats' in fedData: - for chats in fedData['chats']: - chat_id = chats['chat_id'] - connected_chats.append(chat_id) - return connected_chats - else: - return None + if 'chats' in fedData: + for chats in fedData['chats']: + chat_id = chats['chat_id'] + connected_chats.append(chat_id) + return connected_chats + return None def get_fed_name(fed_id=None, owner_id=None): if fed_id == None: @@ -236,13 +230,12 @@ def is_fed_creator(fed_id, owner_id) -> bool: 'fed_id': fed_id } ) - - if ( - owner_id == GetFed['owner_id'] - ): - return True - else: - return False + + if ( + owner_id == GetFed['owner_id'] + ): + return True + return False def fed_rename_db(owner_id, fed_name): federation.update_one( diff --git a/Stella/database/filters_mongo.py b/Stella/database/filters_mongo.py index c3a49b0..e591b78 100644 --- a/Stella/database/filters_mongo.py +++ b/Stella/database/filters_mongo.py @@ -132,10 +132,9 @@ def get_filters_list(chat_id: int): 'chat_id': chat_id } ) - if filter_data is not None: - FILTERS_NAME = list() - for filter_name in filter_data['filters']: - FILTERS_NAME.append(filter_name['filter_name']) - return FILTERS_NAME - else: - return [] \ No newline at end of file + if filter_data is not None: + FILTERS_NAME = list() + for filter_name in filter_data['filters']: + FILTERS_NAME.append(filter_name['filter_name']) + return FILTERS_NAME + return [] diff --git a/Stella/database/locks_mongo.py b/Stella/database/locks_mongo.py index 20ee527..6c4ac2a 100644 --- a/Stella/database/locks_mongo.py +++ b/Stella/database/locks_mongo.py @@ -59,8 +59,7 @@ def get_locks(chat_id) -> list: if locks_data is not None: return locks_data['locked'] - else: - return [] + return [] def unlock_db(chat_id, locked_item): locks_data = locks.find_one( @@ -89,8 +88,7 @@ def lockwarns_db(chat_id) -> bool: if locks_data is not None: return locks_data['lockwarns'] - else: - return True + return True def set_lockwarn_db(chat_id, warn_args): locks_data = locks.find_one( @@ -197,5 +195,4 @@ def get_allowlist(chat_id) -> list: ) if locks_data is not None: return locks_data['allow_list'] - else: - return [] \ No newline at end of file + return [] diff --git a/Stella/database/log_channels_mongo.py b/Stella/database/log_channels_mongo.py index 4f6d0f7..83145dd 100644 --- a/Stella/database/log_channels_mongo.py +++ b/Stella/database/log_channels_mongo.py @@ -88,9 +88,8 @@ def get_set_channel(chat_id): 'chat_id': chat_id } ) - - if get_data is not None: - channel_title = get_data['channel_title'] - return channel_title - else: - return None \ No newline at end of file + + if get_data is not None: + channel_title = get_data['channel_title'] + return channel_title + return None diff --git a/Stella/database/notes_mongo.py b/Stella/database/notes_mongo.py index 84876d6..acce5af 100644 --- a/Stella/database/notes_mongo.py +++ b/Stella/database/notes_mongo.py @@ -152,10 +152,9 @@ def isNoteExist(chat_id, note_name) -> bool: for Getnotes in gnotes: n_name = Getnotes['note_name'] notes_list.append(n_name) - if note_name in notes_list: - return True - else: - return False + if note_name in notes_list: + return True + return False return False def NoteList(chat_id) -> list: @@ -166,17 +165,16 @@ def NoteList(chat_id) -> list: } ) if not GetNoteData == None: - if 'notes' in GetNoteData: - Getnotes = GetNoteData['notes'] - for note in Getnotes: - NoteText = note['text'] - NoteNames = note['note_name'] - if '{admin}' in NoteText: - NoteNames = NoteNames + ' ' + '__{admin}__' - NotesNamesList.append(NoteNames) - return NotesNamesList - else: - return NotesNamesList + if 'notes' in GetNoteData: + Getnotes = GetNoteData['notes'] + for note in Getnotes: + NoteText = note['text'] + NoteNames = note['note_name'] + if '{admin}' in NoteText: + NoteNames = NoteNames + ' ' + '__{admin}__' + NotesNamesList.append(NoteNames) + return NotesNamesList + return NotesNamesList else: return NotesNamesList @@ -215,11 +213,10 @@ def is_pnote_on(chat_id) -> bool: } ) if not GetNoteData == None: - if 'private_note' in GetNoteData: - private_note = GetNoteData['private_note'] - return private_note - else: - return False + if 'private_note' in GetNoteData: + private_note = GetNoteData['private_note'] + return private_note + return False else: return False diff --git a/Stella/database/pin_mongo.py b/Stella/database/pin_mongo.py index cd21b21..2a55f10 100644 --- a/Stella/database/pin_mongo.py +++ b/Stella/database/pin_mongo.py @@ -41,8 +41,7 @@ def get_cleanlinked(chat_id: int) -> bool: if pin_data is not None: return pin_data['cleanlinked'] - else: - return False + return False def antichannelpin_db(chat_id: int, antichannelpin: bool) -> None: pin_data = pin.find_one( @@ -81,5 +80,4 @@ def get_antichannelpin(chat_id: int) -> bool: ) if pin_data is not None: return pin_data['antichannelpin'] - else: - return False + return False diff --git a/Stella/database/report_mongo.py b/Stella/database/report_mongo.py index 5c1c432..9cbde99 100644 --- a/Stella/database/report_mongo.py +++ b/Stella/database/report_mongo.py @@ -38,5 +38,4 @@ def get_report(chat_id: int) -> bool: ) if report_data is not None: return report_data['reports'] - else: - return True \ No newline at end of file + return True diff --git a/Stella/database/rules_mongo.py b/Stella/database/rules_mongo.py index b0054c6..a15bbb6 100644 --- a/Stella/database/rules_mongo.py +++ b/Stella/database/rules_mongo.py @@ -43,8 +43,7 @@ def get_rules(chat_id: int): if rule_data is not None: rules_text = rule_data['rules'] return rules_text - else: - return None + return None def set_private_rule(chat_id, private_note): rule_data = rules.find_one( @@ -85,8 +84,7 @@ def get_private_note(chat_id) -> bool: if rule_data is not None: return rule_data['private_note'] - else: - return True + return True def set_rule_button(chat_id, rule_button): rule_data = rules.find_one( @@ -126,6 +124,5 @@ def get_rules_button(chat_id): ) if rule_data is not None: return rule_data['button_text'] - else: - return 'Rules' + return 'Rules' diff --git a/Stella/database/users_mongo.py b/Stella/database/users_mongo.py index 0dce823..d5144c3 100644 --- a/Stella/database/users_mongo.py +++ b/Stella/database/users_mongo.py @@ -138,8 +138,7 @@ def GetChatName(chat_id): 'chat_id': chat_id } ) - if ChatData is not None: - chat_title = ChatData['chat_title'] - return chat_title - else: - return None \ No newline at end of file + if ChatData is not None: + chat_title = ChatData['chat_title'] + return chat_title + return None diff --git a/Stella/database/warnings_mongo.py b/Stella/database/warnings_mongo.py index b074c7b..05536c7 100644 --- a/Stella/database/warnings_mongo.py +++ b/Stella/database/warnings_mongo.py @@ -102,8 +102,7 @@ def warn_limit(chat_id): if warn_data is not None: _warn_limit = warn_data['warn_limit'] return _warn_limit - else: - return 3 + return 3 def count_user_warn(chat_id, user_id): warn_data = warnings.find_one( @@ -185,14 +184,13 @@ def get_warn_mode(chat_id): warn_mode, warn_mode_time ) - else: - warn_mode = 1 - warn_mode_time = None + warn_mode = 1 + warn_mode_time = None - return ( - warn_mode, - warn_mode_time - ) + return ( + warn_mode, + warn_mode_time + ) def get_all_warn_reason(chat_id, user_id) -> list: warn_data = warnings.find_one( diff --git a/Stella/database/welcome_mongo.py b/Stella/database/welcome_mongo.py index 6c369c4..575121e 100644 --- a/Stella/database/welcome_mongo.py +++ b/Stella/database/welcome_mongo.py @@ -112,10 +112,9 @@ def GetWelcomemessageOnOff(chat_id) -> bool: ) if not GetWelcomeData == None: - if 'welcome' in GetWelcomeData: - return GetWelcomeData['welcome'] - else: - return True + if 'welcome' in GetWelcomeData: + return GetWelcomeData['welcome'] + return True else: return True @@ -125,16 +124,15 @@ def isWelcome(chat_id) -> bool: 'chat_id': chat_id } ) - if ( - GetWelcomeData == None - or not ( - 'welcome_message' in GetWelcomeData - and 'text' in GetWelcomeData['welcome_message'] - ) - ): - return False - else: - return True + if ( + GetWelcomeData == None + or not ( + 'welcome_message' in GetWelcomeData + and 'text' in GetWelcomeData['welcome_message'] + ) + ): + return False + return True def SetGoodBye(chat_id, Content, Text, DataType): @@ -242,10 +240,9 @@ def GetGoodbyemessageOnOff(chat_id) -> bool: ) if not GetWelcomeData == None: - if 'goodbye' in GetWelcomeData: - return GetWelcomeData['goodbye'] - else: - return True + if 'goodbye' in GetWelcomeData: + return GetWelcomeData['goodbye'] + return True else: return True @@ -256,16 +253,15 @@ def isGoodbye(chat_id) -> bool: 'chat_id': chat_id } ) - if ( - GetWelcomeData == None - or not ( - 'goodbye_message' in GetWelcomeData - and 'text' in GetWelcomeData['goodbye_message'] - ) - ): - return False - else: - return True + if ( + GetWelcomeData == None + or not ( + 'goodbye_message' in GetWelcomeData + and 'text' in GetWelcomeData['goodbye_message'] + ) + ): + return False + return True def SetCleanService(chat_id, clean_service): @@ -308,10 +304,9 @@ def GetCleanService(chat_id) -> bool: ) if not GetWelcomeData == None: - if 'clean_service' in GetWelcomeData: - return GetWelcomeData['clean_service'] - else: - return False + if 'clean_service' in GetWelcomeData: + return GetWelcomeData['clean_service'] + return False else: return False @@ -373,10 +368,9 @@ def GetCleanWelcome(chat_id) -> bool: } ) if not GetWelcomeData == None: - if 'clean_welcome' in GetWelcomeData: - return GetWelcomeData['clean_welcome'] - else: - return True + if 'clean_welcome' in GetWelcomeData: + return GetWelcomeData['clean_welcome'] + return True else: return True @@ -387,11 +381,10 @@ def GetCleanWelcomeMessage(chat_id): } ) if not GetWelcomeData == None: - if 'clean_welcome_message' in GetWelcomeData: - clean_message = GetWelcomeData['clean_welcome_message'] - return clean_message - else: - return None + if 'clean_welcome_message' in GetWelcomeData: + clean_message = GetWelcomeData['clean_welcome_message'] + return clean_message + return None return None def SetCaptcha(chat_id, captcha): @@ -445,13 +438,12 @@ def isGetCaptcha(chat_id) -> bool: 'chat_id': chat_id } ) - - if not GetCaptchaData == None: - if 'captcha' in GetCaptchaData: - return GetCaptchaData['captcha']['_captcha'] - return False - else: - return False + + if not GetCaptchaData == None: + if 'captcha' in GetCaptchaData: + return GetCaptchaData['captcha']['_captcha'] + return False + return False def GetCaptchaSettings(chat_id): GetCaptchaData = welcome.find_one( @@ -463,28 +455,27 @@ def GetCaptchaSettings(chat_id): captcha_text_de = "Click here to prove you're human" if not GetCaptchaData == None: - if 'captcha' in GetCaptchaData: - captcha_mode = GetCaptchaData['captcha']['captcha_mode'] - captcha_text = GetCaptchaData['captcha']['captcha_text'] - captcha_kick_time = GetCaptchaData['captcha']['captcha_kick_time'] - - if captcha_text is None: - captcha_text = captcha_text_de - - if captcha_mode is None: - captcha_mode = 'button' - - return ( - captcha_mode, - captcha_text, - captcha_kick_time - ) - else: - return ( - 'button', - captcha_text_de, - None - ) + if 'captcha' in GetCaptchaData: + captcha_mode = GetCaptchaData['captcha']['captcha_mode'] + captcha_text = GetCaptchaData['captcha']['captcha_text'] + captcha_kick_time = GetCaptchaData['captcha']['captcha_kick_time'] + + if captcha_text is None: + captcha_text = captcha_text_de + + if captcha_mode is None: + captcha_mode = 'button' + + return ( + captcha_mode, + captcha_text, + captcha_kick_time + ) + return ( + 'button', + captcha_text_de, + None + ) else: return ( 'button', @@ -753,10 +744,9 @@ def isUserVerified(chat_id, user_id) -> bool: 'chat_id': chat_id } ) - if user_id in GetData['captcha']['verified_users']: - return True - else: - return False + if user_id in GetData['captcha']['verified_users']: + return True + return False def setReCaptcha(chat_id: int, reCaptcha: bool): getWelcomeData = welcome.find_one( @@ -793,14 +783,13 @@ def isReCaptcha(chat_id: int) -> bool: 'chat_id': chat_id } ) - - if ( - getWelcomeData is not None - and 'reCaptcha' in getWelcomeData - ): - return getWelcomeData['reCaptcha'] - else: - return False + + if ( + getWelcomeData is not None + and 'reCaptcha' in getWelcomeData + ): + return getWelcomeData['reCaptcha'] + return False def setRuleCaptcha(chat_id: int, rule_captcha: bool): getWelcomeData = welcome.find_one( @@ -837,11 +826,10 @@ def isRuleCaptcha(chat_id: int) -> bool: 'chat_id': chat_id } ) - - if ( - getWelcomeData is not None - and 'rule_captcha' in getWelcomeData - ): - return getWelcomeData['rule_captcha'] - else: - return False \ No newline at end of file + + if ( + getWelcomeData is not None + and 'rule_captcha' in getWelcomeData + ): + return getWelcomeData['rule_captcha'] + return False diff --git a/Stella/helper/chat_status.py b/Stella/helper/chat_status.py index c0bfc11..765126e 100644 --- a/Stella/helper/chat_status.py +++ b/Stella/helper/chat_status.py @@ -72,15 +72,14 @@ async def isBotAdmin(message: Message, chat_id=None, silent=False) -> bool: chat_id=chat_id, user_id=BOT_ID ) - - if GetData.status not in ADMIN_STRINGS: - if not silent: - await message.reply( - "I'm not admin here to do that." - ) - return False - else: - return True + + if GetData.status not in ADMIN_STRINGS: + if not silent: + await message.reply( + "I'm not admin here to do that." + ) + return False + return True async def isUserAdmin(message: Message, pm_mode: bool = False, user_id: int = None, chat_id: int = None, silent: bool = False) -> bool: """ This function returns users chat status in the chat. @@ -108,17 +107,16 @@ async def isUserAdmin(message: Message, pm_mode: bool = False, user_id: int = No chat_id=chat_id, user_id=user_id ) - - if ( - GetData.status in ADMIN_STRINGS - ): - return True - else: - if not silent: - await message.reply( - "Only admins can execute this command!" - ) - return False + + if ( + GetData.status in ADMIN_STRINGS + ): + return True + if not silent: + await message.reply( + "Only admins can execute this command!" + ) + return False async def anon_admin_checker(chat_id: int, user_id: int) -> bool: """ This function returns user_id chat status @@ -130,10 +128,9 @@ async def anon_admin_checker(chat_id: int, user_id: int) -> bool: chat_id=chat_id, user_id=user_id ) - if GetData.status not in ADMIN_STRINGS: - return False - else: - return True + if GetData.status not in ADMIN_STRINGS: + return False + return True async def can_restrict_member(message: Message, user_id: int, chat_id: int = None) -> bool: @@ -152,14 +149,13 @@ async def can_restrict_member(message: Message, user_id: int, chat_id: int = Non ) except: return True - - if ( - GetData.status in ADMIN_STRINGS - or user_id in SUDO_USERS - ): - return False - else: - return True + + if ( + GetData.status in ADMIN_STRINGS + or user_id in SUDO_USERS + ): + return False + return True async def isUserCreator(message: Message, chat_id: int = None, user_id: int = None) -> bool: """ This function returns the creator status of the given chat. @@ -193,11 +189,10 @@ async def isUserCreator(message: Message, chat_id: int = None, user_id: int = No chat_id=chat_id, user_id=user_id ) - - if GetData.status == 'creator': - return True - else: - return False + + if GetData.status == 'creator': + return True + return False async def isBotCan(message: Message, chat_id: int = None, permissions: str = 'can_change_info', silent: bool = False) -> bool: """This function returns permissions of the bot in the given chat. @@ -218,14 +213,13 @@ async def isBotCan(message: Message, chat_id: int = None, permissions: str = 'ca chat_id=chat_id, user_id=BOT_ID ) - if GetData[permissions]: - return True - else: - if silent == False: - await message.reply( - BOT_PERMISSIONS_STRINGS[permissions] - ) - return False + if GetData[permissions]: + return True + if silent == False: + await message.reply( + BOT_PERMISSIONS_STRINGS[permissions] + ) + return False async def isUserCan(message, user_id: int = None, chat_id: int = None, permissions: str = None, silent: bool = False) -> bool: """This function returns permissions of the user in the chat. @@ -237,11 +231,10 @@ async def isUserCan(message, user_id: int = None, chat_id: int = None, permissio if message.sender_chat: user_id = message.sender_chat.id chat_id = message.chat.id - - if user_id == chat_id: - return True - else: - return False + + if user_id == chat_id: + return True + return False user_id = message.from_user.id @@ -258,17 +251,16 @@ async def isUserCan(message, user_id: int = None, chat_id: int = None, permissio chat_id=chat_id, user_id=user_id ) - if ( - GetData[permissions] - or user_id in SUDO_USERS - ): - return True - else: - if silent == False: - await message.reply( - USERS_PERMISSIONS_STRINGS[permissions] - ) - return False + if ( + GetData[permissions] + or user_id in SUDO_USERS + ): + return True + if silent == False: + await message.reply( + USERS_PERMISSIONS_STRINGS[permissions] + ) + return False async def CheckAllAdminsStuffs(message: Message, permissions: Union[str, List[str]] = 'can_change_info', silent=False) -> bool: """This function checks both bot & user permissions and chat status is the chat. @@ -284,11 +276,10 @@ async def CheckAllAdminsStuffs(message: Message, permissions: Union[str, List[st if message.sender_chat: user_id = message.sender_chat.id chat_id = message.chat.id - - if user_id == chat_id: - return True - else: - return False + + if user_id == chat_id: + return True + return False user_id = message.from_user.id if GetConnectedChat(user_id) is not None: @@ -338,12 +329,10 @@ async def CheckAdmins(message: Message, silent: bool = False) -> bool: if message.sender_chat: user_id = message.sender_chat.id chat_id = message.chat.id - - if user_id == chat_id: - return True - else: - return False - + + if user_id == chat_id: + return True + return False user_id = message.from_user.id if GetConnectedChat(user_id) is not None: chat_id = GetConnectedChat(user_id) diff --git a/Stella/helper/disable.py b/Stella/helper/disable.py index 7eff110..5d03e41 100644 --- a/Stella/helper/disable.py +++ b/Stella/helper/disable.py @@ -36,8 +36,7 @@ async def wrapper(client, message): return await message.delete() return - else: - return + return else: await func(client, message) else: diff --git a/Stella/helper/get_data.py b/Stella/helper/get_data.py index 1841b4c..c9da386 100644 --- a/Stella/helper/get_data.py +++ b/Stella/helper/get_data.py @@ -31,17 +31,16 @@ async def GetChat(chat_id: int): Returns: [type]: chat's title """ - if GetChatName(chat_id) is not None: - chat_title = GetChatName(chat_id) - return chat_title - else: - await StellaCli.send_message( - chat_id=chat_id, - text=( - "I couldn't find the `{chat_title}` in my database. Please execute /forcecachechat here to make me be able to store your chat's data!" - ) - ) - return + if GetChatName(chat_id) is not None: + chat_title = GetChatName(chat_id) + return chat_title + await StellaCli.send_message( + chat_id=chat_id, + text=( + "I couldn't find the `{chat_title}` in my database. Please execute /forcecachechat here to make me be able to store your chat's data!" + ) + ) + return def get_text_reason(message: Message) -> str: """This function returns text, and the reason of the user's arguments diff --git a/Stella/helper/get_user.py b/Stella/helper/get_user.py index b694a45..02f8d13 100644 --- a/Stella/helper/get_user.py +++ b/Stella/helper/get_user.py @@ -27,23 +27,22 @@ async def get_user_id(message): len(message.command) >= 2 ): args = message.command[1] - if ( - args.startswith('@') - or ( - args.isdigit() - and ( - len(args) >= 5 - or len(args) <=15 - ) - ) - ): - user_info = await StellaCli.get_users( - user_ids=args - ) - return user_info - else: - user_info = message.reply_to_message.from_user - return user_info + if ( + args.startswith('@') + or ( + args.isdigit() + and ( + len(args) >= 5 + or len(args) <=15 + ) + ) + ): + user_info = await StellaCli.get_users( + user_ids=args + ) + return user_info + user_info = message.reply_to_message.from_user + return user_info else: user_info = message.reply_to_message.from_user return user_info diff --git a/Stella/helper/time_checker.py b/Stella/helper/time_checker.py index ac4ac83..6ee4132 100644 --- a/Stella/helper/time_checker.py +++ b/Stella/helper/time_checker.py @@ -66,14 +66,14 @@ async def check_time(message, args) -> bool: ) return False - elif len(args) > 1: + if len(args) > 1: if not args[-2].isdigit(): await message.reply( f"failed to get specified time: '{args[-2]}' is not a valid number" ) return False - elif args[-1] in ['w', 'd', 'h', 'm']: + if args[-1] in ['w', 'd', 'h', 'm']: check_time_limit = convert_time(int(args[:-1]), args[-1]) if check_time_limit >= 31622400: # 31622400 ( seconds ) is 366 days await message.reply( @@ -81,11 +81,10 @@ async def check_time(message, args) -> bool: ) return False return True - else: - await message.reply( - f"failed to get specified time: '{args[-1]}' is not a valid time char; expected one of w/d/h/m (weeks, days, hours, minutes)" - ) - return False + await message.reply( + f"failed to get specified time: '{args[-1]}' is not a valid time char; expected one of w/d/h/m (weeks, days, hours, minutes)" + ) + return False def time_string_helper(time_args): time_limit = int(time_args[:-1]) diff --git a/Stella/plugins/antiflood/setflood.py b/Stella/plugins/antiflood/setflood.py index 88bb5e1..81e93fe 100644 --- a/Stella/plugins/antiflood/setflood.py +++ b/Stella/plugins/antiflood/setflood.py @@ -61,8 +61,8 @@ async def setflood(client, message): "I've disable antiflood." ) return - - elif ( + + if ( arg.isdigit() ): if int(arg) > 75: diff --git a/Stella/plugins/blocklists/checker.py b/Stella/plugins/blocklists/checker.py index 977f41a..5380813 100644 --- a/Stella/plugins/blocklists/checker.py +++ b/Stella/plugins/blocklists/checker.py @@ -44,8 +44,8 @@ async def blocklist_action(message, blocklist_word): if getblocklistMessageDelete(chat_id): await message.delete() return - - elif blocklist_mode == 2: + + if blocklist_mode == 2: await StellaCli.kick_chat_member( chat_id, user_id @@ -97,7 +97,7 @@ async def blocklist_action(message, blocklist_word): # Unbanning proceess and wait 5 sec to give server to kick user first await asyncio.sleep(5) await StellaCli.unban_chat_member(chat_id, user_id) - + elif blocklist_mode == 5: await warn(message, reason, warn_user=message) diff --git a/Stella/plugins/connection/connection.py b/Stella/plugins/connection/connection.py index 25dfffb..c28cfc8 100644 --- a/Stella/plugins/connection/connection.py +++ b/Stella/plugins/connection/connection.py @@ -57,14 +57,13 @@ async def connection(message): if isChatConnected: if connected_chat is not None: if get_allow_connection(connected_chat): - if not await isUserBanned(connected_chat, user_id): - return connected_chat - else: - await message.reply( - f"You are banned user of {chat_title}", - quote=True - ) - return None + if not await isUserBanned(connected_chat, user_id): + return connected_chat + await message.reply( + f"You are banned user of {chat_title}", + quote=True + ) + return None else: return None else: diff --git a/Stella/plugins/greeting/captcha/text_captcha.py b/Stella/plugins/greeting/captcha/text_captcha.py index e567c1f..45dab1b 100644 --- a/Stella/plugins/greeting/captcha/text_captcha.py +++ b/Stella/plugins/greeting/captcha/text_captcha.py @@ -148,19 +148,17 @@ async def textCaptchaRedirect(message): os.remove(CaptchaLoc) else: - # Admins captcha message - if await isUserAdmin(message, pm_mode=True, chat_id=new_chat_id, user_id=new_user_id, silent=True): - await message.reply( - "You are admin, You don't have to complete CAPTCHA.", - quote=True - ) - return - - else: - await message.reply( - "This wasn't for you.", - quote=True - ) + # Admins captcha message + if await isUserAdmin(message, pm_mode=True, chat_id=new_chat_id, user_id=new_user_id, silent=True): + await message.reply( + "You are admin, You don't have to complete CAPTCHA.", + quote=True + ) + return + await message.reply( + "This wasn't for you.", + quote=True + ) @StellaCli.on_callback_query(filters.create(lambda _,__, query: 'textc_' in query.data)) diff --git a/Stella/plugins/notes/clear_note.py b/Stella/plugins/notes/clear_note.py index b9400c8..506f640 100644 --- a/Stella/plugins/notes/clear_note.py +++ b/Stella/plugins/notes/clear_note.py @@ -113,18 +113,18 @@ async def ClearAllCallback(client: StellaCli, callback_query: CallbackQuery): user_id = callback_query.from_user.id if owner_id == user_id: - if query_data == 'clear': - chat_id = int(callback_query.data.split('_')[3]) - ClearAllNotes(chat_id) - await callback_query.edit_message_text( - "Deleted all chat notes." - ) - return - - elif query_data == 'cancel': - await callback_query.edit_message_text( - "Cancelled." - ) + if query_data == 'clear': + chat_id = int(callback_query.data.split('_')[3]) + ClearAllNotes(chat_id) + await callback_query.edit_message_text( + "Deleted all chat notes." + ) + return + + if query_data == 'cancel': + await callback_query.edit_message_text( + "Cancelled." + ) else: await callback_query.answer( "Only admins can execute this command!" diff --git a/Stella/plugins/owner/export.py b/Stella/plugins/owner/export.py index cf92830..bec494a 100644 --- a/Stella/plugins/owner/export.py +++ b/Stella/plugins/owner/export.py @@ -80,7 +80,6 @@ def collect_collections(): class DateTimeEncoder(json.JSONEncoder): def default(self, z): - if isinstance(z, datetime.datetime): - return (str(z)) - else: - return super().default(z) + if isinstance(z, datetime.datetime): + return (str(z)) + return super().default(z) diff --git a/Stella/plugins/pin/antichannelpin_checker.py b/Stella/plugins/pin/antichannelpin_checker.py index 42ca970..daff191 100644 --- a/Stella/plugins/pin/antichannelpin_checker.py +++ b/Stella/plugins/pin/antichannelpin_checker.py @@ -53,5 +53,4 @@ async def GetLinkedChannel(chat_id: int) -> str: ) if chat_data.linked_chat: return chat_data.linked_chat.id - else: - return None + return None diff --git a/Stella/plugins/pin/cleanlinked_checker.py b/Stella/plugins/pin/cleanlinked_checker.py index 4d2dec1..5f8f46b 100644 --- a/Stella/plugins/pin/cleanlinked_checker.py +++ b/Stella/plugins/pin/cleanlinked_checker.py @@ -48,5 +48,4 @@ async def GetLinkedChannel(chat_id: int) -> str: ) if chat_data.linked_chat: return chat_data.linked_chat.id - else: - return None + return None diff --git a/Stella/plugins/purge/purge_between.py b/Stella/plugins/purge/purge_between.py index e4edc29..9d94b58 100644 --- a/Stella/plugins/purge/purge_between.py +++ b/Stella/plugins/purge/purge_between.py @@ -40,60 +40,60 @@ async def PurgeBetween(client, message): return reply_to_message = message.reply_to_message.message_id - if command == 'purgefrom': - purge_from_message = await message.reply( - "Message marked for deletion. Reply to another message with /purgeto to delete all messages in between." - ) - purge_from_messageID = purge_from_message.message_id - PurgeDictDataUpdater( - chat_id, purge_from=reply_to_message, - first_messageID=message_id, - purge_from_messageID=purge_from_messageID - ) - return - - elif command == 'purgeto': - - if not message.reply_to_message: - await message.reply( - 'Reply to a message to let me know what to delete.' - ) - return - - if chat_id in PurgeData.keys(): - PurgeDictDataUpdater(chat_id, purge_to=(reply_to_message + 1)) - - purge_from = PurgeData[chat_id]['purge_from'] - first_messageID = PurgeData[chat_id]['first_messageID'] - purge_from_messageID = PurgeData[chat_id]['purge_from_messageID'] - purge_to = PurgeData[chat_id]['purge_to'] - - ExtraMessageIDs = [ - message_id, - first_messageID, - purge_from_messageID - ] - - for MessageID in range(purge_from, purge_to): - MessagesIDs.append(MessageID) - - for MessageID in ExtraMessageIDs: - MessagesIDs.append(MessageID) - - try: - await StellaCli.delete_messages( - chat_id=chat_id, - message_ids=MessagesIDs - ) - PurgeData.clear() - except: - await message.reply( - "I can't delete messages here! Make sure I'm admin and can delete other user's messages." - ) - await message.reply( - "Purge completed!" - ) - else: - await message.reply( - "You can only use this command after having used the /purgefrom command." - ) + if command == 'purgefrom': + purge_from_message = await message.reply( + "Message marked for deletion. Reply to another message with /purgeto to delete all messages in between." + ) + purge_from_messageID = purge_from_message.message_id + PurgeDictDataUpdater( + chat_id, purge_from=reply_to_message, + first_messageID=message_id, + purge_from_messageID=purge_from_messageID + ) + return + + if command == 'purgeto': + + if not message.reply_to_message: + await message.reply( + 'Reply to a message to let me know what to delete.' + ) + return + + if chat_id in PurgeData.keys(): + PurgeDictDataUpdater(chat_id, purge_to=(reply_to_message + 1)) + + purge_from = PurgeData[chat_id]['purge_from'] + first_messageID = PurgeData[chat_id]['first_messageID'] + purge_from_messageID = PurgeData[chat_id]['purge_from_messageID'] + purge_to = PurgeData[chat_id]['purge_to'] + + ExtraMessageIDs = [ + message_id, + first_messageID, + purge_from_messageID + ] + + for MessageID in range(purge_from, purge_to): + MessagesIDs.append(MessageID) + + for MessageID in ExtraMessageIDs: + MessagesIDs.append(MessageID) + + try: + await StellaCli.delete_messages( + chat_id=chat_id, + message_ids=MessagesIDs + ) + PurgeData.clear() + except: + await message.reply( + "I can't delete messages here! Make sure I'm admin and can delete other user's messages." + ) + await message.reply( + "Purge completed!" + ) + else: + await message.reply( + "You can only use this command after having used the /purgefrom command." + ) diff --git a/Stella/plugins/start/startHandler.py b/Stella/plugins/start/startHandler.py index 0627a22..b3a1202 100644 --- a/Stella/plugins/start/startHandler.py +++ b/Stella/plugins/start/startHandler.py @@ -84,10 +84,9 @@ async def start(client, message): def startCheckQuery(message, StartQuery=None) -> bool: - if ( - StartQuery in message.command[1].split('_')[0] - and message.command[1].split('_')[0] == StartQuery - ): - return True - else: - return False + if ( + StartQuery in message.command[1].split('_')[0] + and message.command[1].split('_')[0] == StartQuery + ): + return True + return False diff --git a/Stella/plugins/warnings/warn_checker.py b/Stella/plugins/warnings/warn_checker.py index 9f1ab16..ec76d17 100644 --- a/Stella/plugins/warnings/warn_checker.py +++ b/Stella/plugins/warnings/warn_checker.py @@ -33,13 +33,13 @@ async def warn_checker(message, user_id, silent=False): if countuser_warn >= warnlimit: warn_mode, warn_mode_time = get_warn_mode(chat_id) - + if warn_mode == 1: await StellaCli.kick_chat_member( chat_id, user_id ) - + if not silent: user_info = await StellaCli.get_users( user_ids=user_id @@ -54,14 +54,14 @@ async def warn_checker(message, user_id, silent=False): ) reset_user_warns(chat_id, user_id) return True - - elif warn_mode == 2: + + if warn_mode == 2: await StellaCli.kick_chat_member( chat_id, user_id, int(time.time()) + 60 # wait 60 seconds in case of server goes down at unbanning time ) - + if not silent: user_info = await StellaCli.get_users( user_ids=user_id @@ -81,8 +81,8 @@ async def warn_checker(message, user_id, silent=False): await StellaCli.unban_chat_member(chat_id, user_id) return True - - elif warn_mode == 3: + + if warn_mode == 3: await StellaCli.restrict_chat_member( chat_id, user_id, @@ -106,14 +106,14 @@ async def warn_checker(message, user_id, silent=False): reset_user_warns(chat_id, user_id) return True - elif warn_mode == 4: + if warn_mode == 4: until_time = int(time.time() + int(warn_mode_time)) await StellaCli.restrict_chat_member( chat_id, user_id, until_date=until_time ) - + if not silent: user_info = await StellaCli.get_users( user_ids=user_id @@ -129,7 +129,7 @@ async def warn_checker(message, user_id, silent=False): reset_user_warns(chat_id, user_id) return True - elif warn_mode == 5: + if warn_mode == 5: until_time = int(time.time() + int(warn_mode_time)) await StellaCli.restrict_chat_member( chat_id,