File size: 1,134 Bytes
fc19cc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51e1c40
fc19cc9
 
 
 
 
51e1c40
fc19cc9
 
51e1c40
fc19cc9
 
 
51e1c40
 
89ad488
fc19cc9
51e1c40
89ad488
51e1c40
89ad488
fc19cc9
51e1c40
89ad488
51e1c40
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from threading import RLock

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})
        return curr["type"] if curr else False

    def update_join_type(self, chat, mode):
        if curr := self.find_one({"chat_id": chat}):
            self.update({"chat_id": chat}, {"type": mode})
        return

    def remove_autojoin(self, chat):
        if curr := self.find_one({"chat_id": chat}):
            self.delete_one({"chat_id": chat})
        return