-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmattermost_objects.py
137 lines (123 loc) · 3.53 KB
/
mattermost_objects.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from typing import Dict, List, NamedTuple
class MMUser(NamedTuple):
id: str
create_at: int
update_at: int
delete_at: int
username: str
first_name: str
last_name: str
nickname: str
email: str
auth_data: str
auth_service: str
roles: str
locale: str
timezone: dict
position: any
is_bot: bool = None
bot_description: str = None
email_verified: bool = None
notify_props: dict = None
last_password_update: int = None
failed_attempts: int = None
mfa_active: bool = False
terms_of_service_id: str = None
terms_of_service_create_at: int = None
props: dict = {}
last_picture_update: int = None
@staticmethod
def load(data):
try:
return MMUser(**data)
except TypeError as e:
print("[ERROR] Could not load dict into MMUser namedtuple")
print(str(e))
class MMPostProps(NamedTuple):
from_webhook: str = False
override_icon_url: str = None
override_username: str = None
webhook_display_name: str = None
channel_mentions: Dict = None
matterircd_krcggydky38kdcuubsc7fddc7w: str = None
matterircd_s4ptwhx7wfnx7qwexp1khorh7e: str = None
username: str = None
userId: str = None
old_header: str = None
new_header: str = None
old_purpose: str = None
new_purpose: str = None
old_displayname: str = None
new_displayname: str = None
remove_link_preview: str = None
removedUserId: str = None
addedUserId: str = None
removedUsername: str = None
addedUsername: str = None
message: str = None
attachments: str = None
from_bot: str = False
disable_group_highlight: str = None
class MMPost(NamedTuple):
channel_id: str
create_at: int
delete_at: int
edit_at: int
hashtags: str
id: str
is_pinned: bool
message: str
metadata: Dict
original_id: str
pending_post_id: str
root_id: str
type: str
update_at: int
user_id: str
parent_id: str = None
message_source: str = None
has_reactions: bool = None
file_ids: List[str] = None
props: MMPostProps = None
reply_count: int = None
last_reply_at: str = None
participants: any = None
def from_human(self):
return self.props is None or (
self.props.from_webhook is False and self.props.from_bot is False
)
@staticmethod
def load(data):
try:
props = None
if "props" in data:
try:
props: MMPostProps = MMPostProps(**data["props"])
except TypeError as e:
print("[ERROR] Could not load dict into MMPostProps namedtuple")
print(str(e))
del data["props"]
return MMPost(props=props, **data)
except TypeError as e:
print("[ERROR] Could not load dict into MMPost namedtuple")
print(str(e))
class MMChannelPosts(NamedTuple):
prev_post_id: str
next_post_id: str
order: List[str]
posts: Dict[str, MMPost]
has_next: any
first_inaccessible_post_time: any
reply_count: any = None
disable_group_highlight: any = None
@staticmethod
def load(data):
try:
posts: Dict[str, MMPost] = {
k: MMPost.load(v) for (k, v) in data["posts"].items()
}
del data["posts"]
return MMChannelPosts(posts=posts, **data)
except TypeError as e:
print("[ERROR] Could not load dict into MMUser namedtuple")
print(str(e))