2
2
3
3
4
4
class Message (object ):
5
- def __init__ (self , ** kwargs ):
6
- param_defaults = {
7
- 'message_id' : None ,
8
- 'user' : None ,
9
- 'date' : None ,
10
- 'chat' : None ,
11
- 'forward_from' : None ,
12
- 'forward_date' : None ,
13
- 'reply_to_message' : None ,
14
- 'text' : None ,
15
- 'audio' : None ,
16
- 'document' : None ,
17
- 'photo' : None ,
18
- 'sticker' : None ,
19
- 'video' : None ,
20
- 'contact' : None ,
21
- 'location' : None ,
22
- 'new_chat_participant' : None ,
23
- 'left_chat_participant' : None ,
24
- 'new_chat_title' : None ,
25
- 'new_chat_photo' : None ,
26
- 'delete_chat_photo' : None ,
27
- 'group_chat_created' : None
28
- }
29
-
30
- for (param , default ) in param_defaults .iteritems ():
31
- setattr (self , param , kwargs .get (param , default ))
5
+ def __init__ (self ,
6
+ message_id ,
7
+ from_user ,
8
+ date ,
9
+ chat ,
10
+ forward_from = None ,
11
+ forward_date = None ,
12
+ reply_to_message = None ,
13
+ text = None ,
14
+ audio = None ,
15
+ document = None ,
16
+ photo = None ,
17
+ sticker = None ,
18
+ video = None ,
19
+ contact = None ,
20
+ location = None ,
21
+ new_chat_participant = None ,
22
+ left_chat_participant = None ,
23
+ new_chat_title = None ,
24
+ new_chat_photo = None ,
25
+ delete_chat_photo = None ,
26
+ group_chat_created = None ):
27
+ self .message_id = message_id
28
+ self .from_user = from_user
29
+ self .date = date
30
+ self .chat = chat
31
+ self .forward_from = forward_from
32
+ self .forward_date = forward_date
33
+ self .reply_to_message = reply_to_message
34
+ self .text = text
35
+ self .audio = audio
36
+ self .document = document
37
+ self .photo = photo
38
+ self .sticker = sticker
39
+ self .video = video
40
+ self .contact = contact
41
+ self .location = location
42
+ self .new_chat_participant = new_chat_participant
43
+ self .left_chat_participant = left_chat_participant
44
+ self .new_chat_title = new_chat_title
45
+ self .new_chat_photo = new_chat_photo
46
+ self .delete_chat_photo = delete_chat_photo
47
+ self .group_chat_created = group_chat_created
32
48
33
49
@property
34
50
def chat_id (self ):
35
51
return self .chat .id
36
52
37
53
@staticmethod
38
54
def de_json (data ):
39
- if 'from' in data : # from on api
55
+ if 'from' in data : # from is a reserved word, use user_from instead.
40
56
from telegram import User
41
- user = User .de_json (data ['from' ])
57
+ from_user = User .de_json (data ['from' ])
42
58
else :
43
- user = None
59
+ from_user = None
44
60
45
61
if 'chat' in data :
46
62
if 'username' in data ['chat' ]:
@@ -59,9 +75,7 @@ def de_json(data):
59
75
forward_from = None
60
76
61
77
if 'reply_to_message' in data :
62
- reply_to_message = Message .de_json (
63
- data ['reply_to_message' ]
64
- )
78
+ reply_to_message = Message .de_json (data ['reply_to_message' ])
65
79
else :
66
80
reply_to_message = None
67
81
@@ -109,22 +123,18 @@ def de_json(data):
109
123
110
124
if 'new_chat_participant' in data :
111
125
from telegram import User
112
- new_chat_participant = User .de_json (
113
- data ['new_chat_participant' ]
114
- )
126
+ new_chat_participant = User .de_json (data ['new_chat_participant' ])
115
127
else :
116
128
new_chat_participant = None
117
129
118
130
if 'left_chat_participant' in data :
119
131
from telegram import User
120
- left_chat_participant = User .de_json (
121
- data ['left_chat_participant' ]
122
- )
132
+ left_chat_participant = User .de_json (data ['left_chat_participant' ])
123
133
else :
124
134
left_chat_participant = None
125
135
126
136
return Message (message_id = data .get ('message_id' , None ),
127
- user = user ,
137
+ from_user = from_user ,
128
138
date = data .get ('date' , None ),
129
139
chat = chat ,
130
140
forward_from = forward_from ,
0 commit comments