Spaces:
Paused
Paused
Download Powers/database/autojoin_db.py from Dragdev/telegrambot: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/Dragdev/telegrambot/resolve/85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/database/autojoin_db.py
- Command line
-
hf download hf://spaces/Dragdev/telegrambot@85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/database/autojoin_db.py
-
curl -L -o autojoin_db.py https://huggingface.co/spaces/Dragdev/telegrambot/resolve/85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/database/autojoin_db.py
1.27 kB
| from threading import RLock | |
| from time import time | |
| from Powers import LOGGER | |
| from Powers.database import MongoDB | |
| INSERTION_LOCK = RLock() | |
| class AUTOJOIN(MongoDB): | |
| """class to store auto join requests""" | |
| db_name = "autojoin" | |
| def __init__(self) -> None: | |
| super().__init__(self.db_name) | |
| def load_autojoin(self, chat,mode="auto"): | |
| """ | |
| type = auto or notify | |
| auto to auto accept join requests | |
| notify to notify the admins about the join requests | |
| """ | |
| curr = self.find_one({"chat_id":chat,}) | |
| if not curr: | |
| with INSERTION_LOCK: | |
| self.insert_one({"chat_id":chat,"type":mode}) | |
| return True | |
| return False | |
| def get_autojoin(self,chat): | |
| curr = self.find_one({"chat_id":chat}) | |
| if not curr: | |
| return False | |
| else: | |
| return curr["type"] | |
| def update_join_type(self,chat,mode): | |
| curr = self.find_one({"chat_id":chat}) | |
| if curr: | |
| self.update({"chat_id":chat},{"type":mode}) | |
| return | |
| else: | |
| return | |
| def remove_autojoin(self,chat): | |
| curr = self.find_one({"chat_id":chat}) | |
| if curr: | |
| self.delete_one({"chat_id":chat}) | |
| return |