From d8aaa0ba17215386a9174b6ae39bc4b2e7527c50 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:44:12 +0000 Subject: [PATCH 1/2] Use identity check for comparison to a singleton --- Stella/database/connection_mongo.py | 2 +- Stella/database/federation_mongo.py | 8 ++-- Stella/database/notes_mongo.py | 8 ++-- Stella/database/users_mongo.py | 4 +- Stella/database/welcome_mongo.py | 42 +++++++++---------- Stella/helper/chat_status.py | 4 +- Stella/helper/note_helper/note_fillings.py | 4 +- .../helper/welcome_helper/welcome_fillings.py | 4 +- Stella/plugins/connection/connect.py | 2 +- Stella/plugins/federation/checker.py | 2 +- .../federation/federation_owner/fedpromote.py | 2 +- .../federation/federation_owner/rename_fed.py | 2 +- .../plugins/greeting/captcha/captcha_modes.py | 2 +- Stella/plugins/greeting/new_member.py | 12 +++--- Stella/plugins/greeting/welcome.py | 6 +-- Stella/plugins/locks/locks_checker.py | 2 +- Stella/plugins/notes/get_note.py | 2 +- Stella/plugins/owner/import.py | 2 +- Stella/plugins/purge/purge_helper.py | 4 +- Stella/plugins/warnings/warn.py | 4 +- 20 files changed, 59 insertions(+), 59 deletions(-) diff --git a/Stella/database/connection_mongo.py b/Stella/database/connection_mongo.py index 4054db3..e1c7bae 100644 --- a/Stella/database/connection_mongo.py +++ b/Stella/database/connection_mongo.py @@ -109,7 +109,7 @@ def allow_collection(chat_id, chat_title, allow_collection): 'chat_id': chat_id } ) - if chat_data == None: + if chat_data is None: ChatsNums = chats.count_documents({}) ChatsIDs = ChatsNums + 1 diff --git a/Stella/database/federation_mongo.py b/Stella/database/federation_mongo.py index f92a24a..567ae98 100644 --- a/Stella/database/federation_mongo.py +++ b/Stella/database/federation_mongo.py @@ -27,7 +27,7 @@ def new_fed_db(new_fed, fed_id, created_time, owner_id): } ) - if GetFed == None: + if GetFed is None: FedNums = federation.count_documents({}) FedIDs = FedNums + 1 federation.insert_one( @@ -41,7 +41,7 @@ def new_fed_db(new_fed, fed_id, created_time, owner_id): ) def is_fed_exist(fed_id=None, owner_id=None) -> bool: - if fed_id == None: + if fed_id is None: GetFed = federation.find_one( { 'owner_id': owner_id @@ -174,7 +174,7 @@ def get_fed_from_ownerid(owner_id): 'owner_id': owner_id } ) - if not fedData == None: + if not fedData is None: fed_id = fedData['fed_id'] return fed_id else: @@ -209,7 +209,7 @@ def get_connected_chats(fed_id) -> list: return None def get_fed_name(fed_id=None, owner_id=None): - if fed_id == None: + if fed_id is None: GetFed = federation.find_one( { 'owner_id': owner_id diff --git a/Stella/database/notes_mongo.py b/Stella/database/notes_mongo.py index 84876d6..c5a4a01 100644 --- a/Stella/database/notes_mongo.py +++ b/Stella/database/notes_mongo.py @@ -29,7 +29,7 @@ def SaveNote(chat_id, note_name, content, text, data_type): totalNote = notes.count_documents({}) NotesIDs = totalNote + 1 - if GetNotes == None: + if GetNotes is None: NoteData = { '_id': NotesIDs, 'chat_id': chat_id, @@ -121,7 +121,7 @@ def GetNote(chat_id, note_name): } ) - if not GetNoteData == None: + if not GetNoteData is None: Getnotes = GetNoteData['notes'] for note in Getnotes: GetNote = note['note_name'] @@ -165,7 +165,7 @@ def NoteList(chat_id) -> list: 'chat_id': chat_id } ) - if not GetNoteData == None: + if not GetNoteData is None: if 'notes' in GetNoteData: Getnotes = GetNoteData['notes'] for note in Getnotes: @@ -214,7 +214,7 @@ def is_pnote_on(chat_id) -> bool: 'chat_id': chat_id } ) - if not GetNoteData == None: + if not GetNoteData is None: if 'private_note' in GetNoteData: private_note = GetNoteData['private_note'] return private_note diff --git a/Stella/database/users_mongo.py b/Stella/database/users_mongo.py index 0dce823..696ed1b 100644 --- a/Stella/database/users_mongo.py +++ b/Stella/database/users_mongo.py @@ -14,7 +14,7 @@ def add_user(user_id, username=None, chat_id=None, chat_title=None, Forwared=Fal } ) - if UserData == None: + if UserData is None: UsersNums = users.count_documents({}) UsersIDs = UsersNums + 1 @@ -95,7 +95,7 @@ def add_chat(chat_id, chat_title): } ) - if ChatData == None: + if ChatData is None: ChatsNums = chats.count_documents({}) ChatsIDs = ChatsNums + 1 diff --git a/Stella/database/welcome_mongo.py b/Stella/database/welcome_mongo.py index 6c369c4..681f622 100644 --- a/Stella/database/welcome_mongo.py +++ b/Stella/database/welcome_mongo.py @@ -17,7 +17,7 @@ def SetWelcome(chat_id, Content, Text, DataType): WelcomeDataCount = welcome.count_documents({}) WelcomeIDs = WelcomeDataCount + 1 - if WelcomeData == None: + if WelcomeData is None: WelcomeSetData = { '_id': WelcomeIDs, 'welcome': True, @@ -54,7 +54,7 @@ def UnSetWelcome(chat_id): 'chat_id': chat_id } ) - if not WelcomeData == None: + if not WelcomeData is None: if 'text' in WelcomeData['welcome_message']: welcome.update_one( { @@ -78,7 +78,7 @@ def GetWelcome(chat_id): ) if not ( - GetWelcomeData == None + GetWelcomeData is None ): if 'text' in GetWelcomeData['welcome_message']: Content = GetWelcomeData['welcome_message']['content'] @@ -111,7 +111,7 @@ def GetWelcomemessageOnOff(chat_id) -> bool: } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'welcome' in GetWelcomeData: return GetWelcomeData['welcome'] else: @@ -126,7 +126,7 @@ def isWelcome(chat_id) -> bool: } ) if ( - GetWelcomeData == None + GetWelcomeData is None or not ( 'welcome_message' in GetWelcomeData and 'text' in GetWelcomeData['welcome_message'] @@ -147,7 +147,7 @@ def SetGoodBye(chat_id, Content, Text, DataType): WelcomeDataCount = welcome.count_documents({}) WelcomeIDs = WelcomeDataCount + 1 - if WelcomeData == None: + if WelcomeData is None: WelcomeSetData = { '_id': WelcomeIDs, 'welcome': True, @@ -184,7 +184,7 @@ def UnSetGoodbye(chat_id): 'chat_id': chat_id } ) - if not WelcomeData == None: + if not WelcomeData is None: if 'text' in WelcomeData['goodbye_message']: welcome.update_one( { @@ -208,7 +208,7 @@ def GetGoobye(chat_id): ) if not ( - GetWelcomeData == None + GetWelcomeData is None ): if 'text' in GetWelcomeData['goodbye_message']: Content = GetWelcomeData['goodbye_message']['content'] @@ -241,7 +241,7 @@ def GetGoodbyemessageOnOff(chat_id) -> bool: } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'goodbye' in GetWelcomeData: return GetWelcomeData['goodbye'] else: @@ -257,7 +257,7 @@ def isGoodbye(chat_id) -> bool: } ) if ( - GetWelcomeData == None + GetWelcomeData is None or not ( 'goodbye_message' in GetWelcomeData and 'text' in GetWelcomeData['goodbye_message'] @@ -279,7 +279,7 @@ def SetCleanService(chat_id, clean_service): WelcomeIDs = WelcomeDataCount + 1 if not ( - WelcomeData == None + WelcomeData is None ): welcome.update_one( { @@ -307,7 +307,7 @@ def GetCleanService(chat_id) -> bool: } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'clean_service' in GetWelcomeData: return GetWelcomeData['clean_service'] else: @@ -325,7 +325,7 @@ def SetCleanWelcome(chat_id, clean_welcome): } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: welcome.update_one( { 'chat_id': chat_id @@ -353,7 +353,7 @@ def SetCleanWelcomeMessage(chat_id, message_id): 'chat_id': chat_id } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'clean_welcome_message' in GetWelcomeData: welcome.update_one( { @@ -372,7 +372,7 @@ def GetCleanWelcome(chat_id) -> bool: 'chat_id': chat_id } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'clean_welcome' in GetWelcomeData: return GetWelcomeData['clean_welcome'] else: @@ -386,7 +386,7 @@ def GetCleanWelcomeMessage(chat_id): 'chat_id': chat_id } ) - if not GetWelcomeData == None: + if not GetWelcomeData is None: if 'clean_welcome_message' in GetWelcomeData: clean_message = GetWelcomeData['clean_welcome_message'] return clean_message @@ -403,7 +403,7 @@ def SetCaptcha(chat_id, captcha): 'chat_id': chat_id } ) - if not GetCaptchaData == None: + if not GetCaptchaData is None: welcome.update_one( { 'chat_id': chat_id @@ -446,7 +446,7 @@ def isGetCaptcha(chat_id) -> bool: } ) - if not GetCaptchaData == None: + if not GetCaptchaData is None: if 'captcha' in GetCaptchaData: return GetCaptchaData['captcha']['_captcha'] return False @@ -462,7 +462,7 @@ def GetCaptchaSettings(chat_id): captcha_text_de = "Click here to prove you're human" - if not GetCaptchaData == None: + if not GetCaptchaData is None: if 'captcha' in GetCaptchaData: captcha_mode = GetCaptchaData['captcha']['captcha_mode'] captcha_text = GetCaptchaData['captcha']['captcha_text'] @@ -501,7 +501,7 @@ def SetCaptchaText(chat_id, captcha_text): 'chat_id': chat_id } ) - if not GetCaptchaData == None: + if not GetCaptchaData is None: if 'captcha' in GetCaptchaData: welcome.update_one( { @@ -559,7 +559,7 @@ def SetCaptchaMode(chat_id, captcha_mode): } ) - if not GetCaptchaData == None: + if not GetCaptchaData is None: if 'captcha' in GetCaptchaData: welcome.update_one( { diff --git a/Stella/helper/chat_status.py b/Stella/helper/chat_status.py index c0bfc11..9d28d38 100644 --- a/Stella/helper/chat_status.py +++ b/Stella/helper/chat_status.py @@ -221,7 +221,7 @@ async def isBotCan(message: Message, chat_id: int = None, permissions: str = 'ca if GetData[permissions]: return True else: - if silent == False: + if silent is False: await message.reply( BOT_PERMISSIONS_STRINGS[permissions] ) @@ -264,7 +264,7 @@ async def isUserCan(message, user_id: int = None, chat_id: int = None, permissio ): return True else: - if silent == False: + if silent is False: await message.reply( USERS_PERMISSIONS_STRINGS[permissions] ) diff --git a/Stella/helper/note_helper/note_fillings.py b/Stella/helper/note_helper/note_fillings.py index 4a2b8e4..364b427 100644 --- a/Stella/helper/note_helper/note_fillings.py +++ b/Stella/helper/note_helper/note_fillings.py @@ -17,11 +17,11 @@ def NoteFillings(message, message_text): - if not message == None: + if not message is None: user_id = message.from_user.id first_name = message.from_user.first_name last_name = message.from_user.last_name - if last_name == None: + if last_name is None: last_name = '' full_name = f'{first_name} {last_name}' username = message.from_user.username diff --git a/Stella/helper/welcome_helper/welcome_fillings.py b/Stella/helper/welcome_helper/welcome_fillings.py index 55f5605..cd1eb93 100644 --- a/Stella/helper/welcome_helper/welcome_fillings.py +++ b/Stella/helper/welcome_helper/welcome_fillings.py @@ -19,11 +19,11 @@ import html def Welcomefillings(message, message_text, NewUserJson): - if not NewUserJson == None: + if not NewUserJson is None: user_id = NewUserJson.id first_name = NewUserJson.first_name last_name = NewUserJson.last_name - if last_name == None: + if last_name is None: last_name = '' full_name = f'{first_name} {last_name}' username = NewUserJson.username diff --git a/Stella/plugins/connection/connect.py b/Stella/plugins/connection/connect.py index c84b191..7a66f56 100644 --- a/Stella/plugins/connection/connect.py +++ b/Stella/plugins/connection/connect.py @@ -48,7 +48,7 @@ async def Connect(client, message): return chat_title = await GetChat(int(chat_id)) - if chat_title == None: + if chat_title is None: await message.reply( "failed to connect to chat!\nError: `chat not found`", quote=True diff --git a/Stella/plugins/federation/checker.py b/Stella/plugins/federation/checker.py index 7cbedb6..aa842d9 100644 --- a/Stella/plugins/federation/checker.py +++ b/Stella/plugins/federation/checker.py @@ -34,7 +34,7 @@ async def fed_checker(client, message): user_id = message.from_user.id fed_id = get_fed_from_chat(chat_id) - if not fed_id == None: + if not fed_id is None: if is_user_fban(fed_id, user_id): fed_reason = get_fed_reason(fed_id, user_id) text = ( diff --git a/Stella/plugins/federation/federation_owner/fedpromote.py b/Stella/plugins/federation/federation_owner/fedpromote.py index 2200c6e..3371b5e 100644 --- a/Stella/plugins/federation/federation_owner/fedpromote.py +++ b/Stella/plugins/federation/federation_owner/fedpromote.py @@ -48,7 +48,7 @@ async def FedPromote(client, message): return if ( - fed_id == None + fed_id is None ): await message.reply( "Only federation creators can promote people, and you don't even seem to have a federation to promote to!" diff --git a/Stella/plugins/federation/federation_owner/rename_fed.py b/Stella/plugins/federation/federation_owner/rename_fed.py index a4be56a..952f971 100644 --- a/Stella/plugins/federation/federation_owner/rename_fed.py +++ b/Stella/plugins/federation/federation_owner/rename_fed.py @@ -53,7 +53,7 @@ async def Rename_fed(client, message): return fed_id = get_fed_from_ownerid(owner_id) - if fed_id == None: + if fed_id is None: await message.reply( "It doesn't look like you have a federation yet!" ) diff --git a/Stella/plugins/greeting/captcha/captcha_modes.py b/Stella/plugins/greeting/captcha/captcha_modes.py index a4a60b8..461c1dd 100644 --- a/Stella/plugins/greeting/captcha/captcha_modes.py +++ b/Stella/plugins/greeting/captcha/captcha_modes.py @@ -79,7 +79,7 @@ async def CaptchaMode(client, message): else: captcha_mode, captcha_text, captcha_kick_time = GetCaptchaSettings(chat_id) - if captcha_mode == None: + if captcha_mode is None: captcha_mode = 'button' await message.reply( diff --git a/Stella/plugins/greeting/new_member.py b/Stella/plugins/greeting/new_member.py index 577feb0..1a9303c 100644 --- a/Stella/plugins/greeting/new_member.py +++ b/Stella/plugins/greeting/new_member.py @@ -58,7 +58,7 @@ async def NewMemeber(client, message): if GetCleanWelcome(chat_id): CleanWelcomeMessageID = GetCleanWelcomeMessage(chat_id) - if not CleanWelcomeMessageID == None: + if not CleanWelcomeMessageID is None: await StellaCli.delete_messages( chat_id=chat_id, message_ids=CleanWelcomeMessageID @@ -153,7 +153,7 @@ async def NewMemeber(client, message): # Captcha modes button/text/math captcha_mode, captcha_text, captcha_kick_time = GetCaptchaSettings(chat_id) if ( - captcha_mode == None + captcha_mode is None or captcha_mode == 'button' ): CaptchaButton = await button_captcha.CaptchaButton(chat_id, user_id) @@ -174,12 +174,12 @@ async def NewMemeber(client, message): Content, Text, DataType = GetWelcome(chat_id) Text, buttons = button_markdown_parser(Text) - if CaptchaButton == None: + if CaptchaButton is None: reply_markup = None # If welcome message has button greater than 0 if len(buttons) > 0: - if not CaptchaButton == None: + if not CaptchaButton is None: reply_markup = InlineKeyboardMarkup(buttons + CaptchaButton) # Already Verified users if not isReCaptcha(chat_id): @@ -193,7 +193,7 @@ async def NewMemeber(client, message): reply_markup = InlineKeyboardMarkup(buttons) else: reply_markup = None - if not CaptchaButton == None: + if not CaptchaButton is None: reply_markup = InlineKeyboardMarkup(CaptchaButton) # Already Verified users if not isReCaptcha(chat_id): @@ -215,7 +215,7 @@ async def NewMemeber(client, message): # If welcome has No any messages set Text = Welcomefillings(message, DEFAUT_WELCOME, NewUserJson) - if CaptchaButton == None: + if CaptchaButton is None: reply_markup = None else: reply_markup = InlineKeyboardMarkup(CaptchaButton) diff --git a/Stella/plugins/greeting/welcome.py b/Stella/plugins/greeting/welcome.py index 0ea476a..f6ffb2b 100644 --- a/Stella/plugins/greeting/welcome.py +++ b/Stella/plugins/greeting/welcome.py @@ -82,13 +82,13 @@ async def welcomeformat(message, chat_id, noformat=True): if isGetCaptcha(chat_id): captcha_mode, captcha_text, captcha_kick_time = GetCaptchaSettings(chat_id) - if captcha_mode == None: + if captcha_mode is None: captcha_mode = 'button' - if captcha_text == None: + if captcha_text is None: captcha_text = "Click here to prove you're human" - if captcha_kick_time == None: + if captcha_kick_time is None: captcha_kick_time = "disabled" captcha = ( diff --git a/Stella/plugins/locks/locks_checker.py b/Stella/plugins/locks/locks_checker.py index 1ab90d4..e51d7d0 100644 --- a/Stella/plugins/locks/locks_checker.py +++ b/Stella/plugins/locks/locks_checker.py @@ -161,7 +161,7 @@ async def locks_checker(client, message): ): from_channel_user = message.forward_from_chat.username from_channel_id = message.forward_from_chat.id - if from_channel_user == None: + if from_channel_user is None: CHECKER_IN_LIST = ( from_channel_id in ALLOW_LIST ) diff --git a/Stella/plugins/notes/get_note.py b/Stella/plugins/notes/get_note.py index ceb62b6..6edea2e 100644 --- a/Stella/plugins/notes/get_note.py +++ b/Stella/plugins/notes/get_note.py @@ -66,7 +66,7 @@ async def send_note(message: Message, note_name: str): privateNote, allow = await privateNote_and_admin_checker(message, text) if allow: - if privateNote == None: + if privateNote is None: if is_pnote_on(chat_id): await PrivateNoteButton(message, chat_id, note_name) else: diff --git a/Stella/plugins/owner/import.py b/Stella/plugins/owner/import.py index a8c0adb..7cb4a8a 100644 --- a/Stella/plugins/owner/import.py +++ b/Stella/plugins/owner/import.py @@ -71,7 +71,7 @@ async def StellaImport(client, message): for collection in COLLECTIONS_NAMES: for exportData in data['exports_data']: get_col = exportData.get(collection) - if not get_col == None: + if not get_col is None: for doc in get_col: collection_lists.append(doc) StellaDB[collection].insert_many(collection_lists) diff --git a/Stella/plugins/purge/purge_helper.py b/Stella/plugins/purge/purge_helper.py index fba2452..656471b 100644 --- a/Stella/plugins/purge/purge_helper.py +++ b/Stella/plugins/purge/purge_helper.py @@ -18,7 +18,7 @@ def PurgeDictDataUpdater(chat_id, purge_from=None, purge_to=None, first_messageID=None, purge_from_messageID=None): PurgeData = PurgeDictData.PurgeDict - if purge_to == None: + if purge_to is None: PurgeData.update( { chat_id: { @@ -28,7 +28,7 @@ def PurgeDictDataUpdater(chat_id, purge_from=None, purge_to=None, first_messageI } } ) - elif purge_from == None: + elif purge_from is None: PurgeData[chat_id].update( { "purge_to": purge_to diff --git a/Stella/plugins/warnings/warn.py b/Stella/plugins/warnings/warn.py index 22d3e9f..72562b3 100644 --- a/Stella/plugins/warnings/warn.py +++ b/Stella/plugins/warnings/warn.py @@ -51,8 +51,8 @@ async def warn(message, reason, silent=False, warn_user=None): warnchecker = await warn_checker(message, user_id, silent) if ( - warnchecker == True - or warnchecker == None + warnchecker is True + or warnchecker is None ): return False From 09a51aa7990c1d54552f26e83f2785303e5da83e 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:46:42 +0000 Subject: [PATCH 2/2] Autofix issues in 1 file Resolved issues in Stella/plugins/locks/locks_checker.py via DeepSource Autofix --- Stella/plugins/locks/locks_checker.py | 41 ++++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Stella/plugins/locks/locks_checker.py b/Stella/plugins/locks/locks_checker.py index e51d7d0..5fd3a61 100644 --- a/Stella/plugins/locks/locks_checker.py +++ b/Stella/plugins/locks/locks_checker.py @@ -185,9 +185,8 @@ async def locks_checker(client, message): ): await lock_action(message, action=15) - if 16 in LOCKS_LIST: - if message.game: - await lock_action(message, action=16) + if 16 in LOCKS_LIST and message.game: + await lock_action(message, action=16) if 17 in LOCKS_LIST: if message.animation: @@ -210,26 +209,28 @@ async def locks_checker(client, message): else: await lock_action(message, action=18) - if 19 in LOCKS_LIST: - if ( + if ( + 19 in LOCKS_LIST + and ( + message.text + or message.caption + ) + ): + text = ( message.text or message.caption + ) + extractor = URLExtract() + URL_LIST = extractor.find_urls(text) + if ( + len(URL_LIST) == 0 ): - text = ( - message.text - or message.caption - ) - extractor = URLExtract() - URL_LIST = extractor.find_urls(text) - if ( - len(URL_LIST) == 0 - ): - return - - TG_INVITELINK = 't.me/joinchat/' - for link in URL_LIST: - if TG_INVITELINK in link: - await lock_action(message, action=19) + return + + TG_INVITELINK = 't.me/joinchat/' + for link in URL_LIST: + if TG_INVITELINK in link: + await lock_action(message, action=19) if 20 in LOCKS_LIST: if message.location: