File size: 1,700 Bytes
ea508b7
 
 
 
 
 
51e1c40
ea508b7
 
 
 
 
 
 
51e1c40
ea508b7
 
 
 
 
 
 
 
 
51e1c40
 
ea508b7
 
 
 
51e1c40
89ad488
ea508b7
 
 
51e1c40
ea508b7
 
51e1c40
ea508b7
 
 
 
 
89ad488
ea508b7
51e1c40
89ad488
ea508b7
51e1c40
ea508b7
 
51e1c40
89ad488
ea508b7
 
 
 
51e1c40
89ad488
ea508b7
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from threading import RLock

from Powers.database import MongoDB

INSERTION_LOCK = RLock()


class SUPPORTS(MongoDB):
    """
    class to store support users in database
    Dev > sudo > whitelist
    """

    db_name = "supports"

    def __init__(self) -> None:
        super().__init__(self.db_name)

    def insert_support_user(self, user_id, support_type):
        curr = self.is_support_user(user_id)
        if not curr:
            with INSERTION_LOCK:
                self.insert_one(
                    {
                        "user_id": user_id,
                        "support_type": support_type
                    }
                )
            return

    def update_support_user_type(self, user, new_type):
        if curr := self.is_support_user(user):
            with INSERTION_LOCK:
                self.update(
                    {
                        "user_id": user
                    },
                    {
                        "support_type": new_type
                    }
                )
        return

    def is_support_user(self, user_id):
        return bool(curr := self.find_one({"user_id": user_id}))

    def delete_support_user(self, user):
        if curr := self.is_support_user(user):
            with INSERTION_LOCK:
                self.delete_one({"user_id": user})
        return

    def get_particular_support(self, support_type):
        if curr := self.find_all({"support_type": support_type}):
            return [i['user_id'] for i in curr]
        else:
            return []

    def get_support_type(self, user):
        if curr := self.find_one({"user_id": user}):
            return curr["support_type"]
        return False