diff --git a/spam/db/__init__.py b/spam/db/__init__.py index ccc5f42..1f83241 100644 --- a/spam/db/__init__.py +++ b/spam/db/__init__.py @@ -13,14 +13,10 @@ def __init__(self, mongo_url) -> None: self.sibyl = MongoClient(self.db_url)['Sibyl']['SIBYLMODE'] def is_vanitas(self, chat_id: int) -> bool: - x = self.vanitas.find_one({"chat_id": chat_id}) - if x: - return True - return False + return bool(x := self.vanitas.find_one({"chat_id": chat_id})) def set_vanitas(self, chat_id: int): - set_vanitas = self.is_vanitas(chat_id) - if set_vanitas: + if set_vanitas := self.is_vanitas(chat_id): return return self.vanitas.insert_one({"chat_id": chat_id}) @@ -32,14 +28,10 @@ def rm_vanitas(self, chat_id: int): def is_sibyl(self, chat_id: int) -> bool: - x = self.sibyl.find_one({"chat_id": chat_id}) - if x: - return True - return False + return bool(x := self.sibyl.find_one({"chat_id": chat_id})) def set_sibyl(self, chat_id: int): - set_sibyl = self.is_sibyl(chat_id) - if set_sibyl: + if set_sibyl := self.is_sibyl(chat_id): return return self.sibyl.insert_one({"chat_id": chat_id}) diff --git a/spam/helper/__init__.py b/spam/helper/__init__.py index 3c32347..659b109 100644 --- a/spam/helper/__init__.py +++ b/spam/helper/__init__.py @@ -7,12 +7,12 @@ def is_vanitasalert(user): res = get("https://vanitas-api.up.railway.app/user/" + str(user)).json() - return True if res['blacklisted'] else False + return bool(res['blacklisted']) def is_sibylalert(user): res = get("https://psychopass.animekaizoku.com/getInfo?token=5086015489:N0tFM9DsvPD-bjlvHx57KFqJuSS5-AmJIMsuqgidgSWd9hm7W1Zs-hdPhUAjn3U-&user-id=" + str(user)).json() - return True if res['success'] else False + return bool(res['success']) diff --git a/spam/modules/sibyl.py b/spam/modules/sibyl.py index ec95b40..75f5ef8 100644 --- a/spam/modules/sibyl.py +++ b/spam/modules/sibyl.py @@ -17,13 +17,12 @@ async def sibylalert(_, message): if is_admin(message.chat.id, message.from_user.id): return - is_sibyl = db.is_sibyl(message.chat.id) - if not is_sibyl: - db.set_sibyl(message.chat.id) - await message.reply_text("Sibyl Alert Enable") - else: + if is_sibyl := db.is_sibyl(message.chat.id): db.rm_sibyl(message.chat.id) await message.reply_text("Sibyl Alert Disable") + else: + db.set_sibyl(message.chat.id) + await message.reply_text("Sibyl Alert Enable") @bot.on_message(filters.new_chat_members) @@ -52,5 +51,3 @@ def salert(_, m: Message): callback_data=f"mute:mute:{user}") ], ])) - else: - pass diff --git a/spam/modules/spam.py b/spam/modules/spam.py index 27e0bc9..980dd8a 100644 --- a/spam/modules/spam.py +++ b/spam/modules/spam.py @@ -8,10 +8,7 @@ def is_admin(group_id: int, user_id: int): try: user_data = bot.get_chat_member(group_id, user_id) - if user_data.status == 'administrator' or user_data.status == 'creator': - return True - else: - return False + return user_data.status in ['administrator', 'creator'] except: return False diff --git a/spam/modules/vanitas.py b/spam/modules/vanitas.py index 81788bf..535d599 100644 --- a/spam/modules/vanitas.py +++ b/spam/modules/vanitas.py @@ -17,13 +17,12 @@ async def vanitasalert(_, message): if is_admin(message.chat.id, message.from_user.id): return - is_vanitas = db.is_vanitas(message.chat.id) - if not is_vanitas: - db.set_vanitas(message.chat.id) - await message.reply_text("Alert Mode Enable") - else: + if is_vanitas := db.is_vanitas(message.chat.id): db.rm_vanitas(message.chat.id) await message.reply_text("Alert Mode Disable") + else: + db.set_vanitas(message.chat.id) + await message.reply_text("Alert Mode Enable") @bot.on_message(filters.new_chat_members) @@ -52,5 +51,3 @@ def valert(_, m: Message): callback_data=f"mute:mute:{user}") ], ])) - else: - pass