Skip to content

Commit

Permalink
feat: included method to ban users in main class
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonioVentilii committed Apr 9, 2024
1 parent cdfc958 commit 6aa557d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='whatsapp_wrapper',
version='0.1.5',
version='0.1.6',
author='Antonio Ventilii',
author_email='[email protected]',
license='MIT',
Expand Down
29 changes: 22 additions & 7 deletions whatsapp_wrapper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,34 @@ def error_handler(response: Response, data: dict):
def db(self) -> WhatsAppDB:
return self._db

@property
def banned_users(self) -> list[str]:
def get_db_banned_users(self) -> list[str]:
if self.db:
db_banned_users = self.db.list_banned_user_names()
ret = self.db.list_banned_user_names()
else:
db_banned_users = []
ret = []
return ret

@property
def banned_users(self) -> list[str]:
db_banned_users = self.get_db_banned_users()
ret = self._banned_users + db_banned_users
ret = list(set(ret))
return ret

@banned_users.setter
def banned_users(self, value: list[str]):
self._banned_users = value
def ban_users(self, user_ids: list[str] | str, reason: str = "Manual ban"):
if isinstance(user_ids, str):
user_ids = [user_ids]
not_yet_banned = [x for x in user_ids if x not in self.banned_users]
if self.db:
for user_id in not_yet_banned:
data = {
"phone_number_id": user_id,
"reason": reason,
"timestamp": time.time(),
}
self.db.add_banned_user(data, user_id)
else:
self._banned_users += not_yet_banned

@property
def base_url(self):
Expand Down

0 comments on commit 6aa557d

Please sign in to comment.