22
33
44class 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
3248
3349 @property
3450 def chat_id (self ):
3551 return self .chat .id
3652
3753 @staticmethod
3854 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.
4056 from telegram import User
41- user = User .de_json (data ['from' ])
57+ from_user = User .de_json (data ['from' ])
4258 else :
43- user = None
59+ from_user = None
4460
4561 if 'chat' in data :
4662 if 'username' in data ['chat' ]:
@@ -59,9 +75,7 @@ def de_json(data):
5975 forward_from = None
6076
6177 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' ])
6579 else :
6680 reply_to_message = None
6781
@@ -109,22 +123,18 @@ def de_json(data):
109123
110124 if 'new_chat_participant' in data :
111125 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' ])
115127 else :
116128 new_chat_participant = None
117129
118130 if 'left_chat_participant' in data :
119131 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' ])
123133 else :
124134 left_chat_participant = None
125135
126136 return Message (message_id = data .get ('message_id' , None ),
127- user = user ,
137+ from_user = from_user ,
128138 date = data .get ('date' , None ),
129139 chat = chat ,
130140 forward_from = forward_from ,
0 commit comments