@@ -134,110 +134,60 @@ def de_json(data):
134134 if not data :
135135 return None
136136
137- message = dict ()
138-
139- # Required
140- message ['message_id' ] = data ['message_id' ]
141- message ['from_user' ] = User .de_json (data ['from' ])
142- message ['date' ] = datetime .fromtimestamp (data ['date' ])
143- # Optionals
137+ data ['from_user' ] = User .de_json (data ['from' ])
138+ data ['date' ] = datetime .fromtimestamp (data ['date' ])
144139 if 'first_name' in data .get ('chat' , '' ):
145- message ['chat' ] = User .de_json (data .get ('chat' ))
140+ data ['chat' ] = User .de_json (data .get ('chat' ))
146141 elif 'title' in data .get ('chat' , '' ):
147- message ['chat' ] = GroupChat .de_json (data .get ('chat' ))
148- message ['forward_from' ] = \
142+ data ['chat' ] = GroupChat .de_json (data .get ('chat' ))
143+ data ['forward_from' ] = \
149144 User .de_json (data .get ('forward_from' ))
150- message ['forward_date' ] = \
145+ data ['forward_date' ] = \
151146 Message ._fromtimestamp (data .get ('forward_date' ))
152- message ['reply_to_message' ] = \
147+ data ['reply_to_message' ] = \
153148 Message .de_json (data .get ('reply_to_message' ))
154- message ['text' ] = \
155- data .get ('text' )
156- message ['audio' ] = \
149+ data ['audio' ] = \
157150 Audio .de_json (data .get ('audio' ))
158- message ['document' ] = \
151+ data ['document' ] = \
159152 Document .de_json (data .get ('document' ))
160- message ['photo' ] = \
161- [ PhotoSize .de_json ( x ) for x in data .get ('photo' , [])]
162- message ['sticker' ] = \
153+ data ['photo' ] = \
154+ PhotoSize .de_list ( data .get ('photo' ))
155+ data ['sticker' ] = \
163156 Sticker .de_json (data .get ('sticker' ))
164- message ['video' ] = \
157+ data ['video' ] = \
165158 Video .de_json (data .get ('video' ))
166- message ['voice' ] = \
159+ data ['voice' ] = \
167160 Voice .de_json (data .get ('voice' ))
168- message ['caption' ] = \
169- data .get ('caption' )
170- message ['contact' ] = \
161+ data ['contact' ] = \
171162 Contact .de_json (data .get ('contact' ))
172- message ['location' ] = \
163+ data ['location' ] = \
173164 Location .de_json (data .get ('location' ))
174- message ['new_chat_participant' ] = \
165+ data ['new_chat_participant' ] = \
175166 User .de_json (data .get ('new_chat_participant' ))
176- message ['left_chat_participant' ] = \
167+ data ['left_chat_participant' ] = \
177168 User .de_json (data .get ('left_chat_participant' ))
178- message ['new_chat_title' ] = \
179- data .get ('new_chat_title' )
180- message ['new_chat_photo' ] = \
181- [PhotoSize .de_json (x ) for x in data .get ('new_chat_photo' , [])]
182- message ['delete_chat_photo' ] = \
183- data .get ('delete_chat_photo' )
184- message ['group_chat_created' ] = \
185- data .get ('group_chat_created' )
169+ data ['new_chat_photo' ] = \
170+ PhotoSize .de_list (data .get ('new_chat_photo' ))
186171
187- return Message (** message )
172+ return Message (** data )
188173
189174 def to_dict (self ):
190175 """
191176 Returns:
192177 dict:
193178 """
194- data = dict ()
179+ data = super ( Message , self ). to_dict ()
195180
196181 # Required
197- data ['message_id' ] = self .message_id
198- data ['from' ] = self .from_user .to_dict ()
182+ data ['from' ] = data .pop ('from_user' )
199183 data ['date' ] = self ._totimestamp (self .date )
200- data ['chat' ] = self .chat .to_dict ()
201184 # Optionals
202- if self .forward_from :
203- data ['forward_from' ] = self .forward_from .to_dict ()
204185 if self .forward_date :
205186 data ['forward_date' ] = self ._totimestamp (self .forward_date )
206- if self .reply_to_message :
207- data ['reply_to_message' ] = self .reply_to_message .to_dict ()
208- if self .text :
209- data ['text' ] = self .text
210- if self .audio :
211- data ['audio' ] = self .audio .to_dict ()
212- if self .document :
213- data ['document' ] = self .document .to_dict ()
214187 if self .photo :
215188 data ['photo' ] = [p .to_dict () for p in self .photo ]
216- if self .sticker :
217- data ['sticker' ] = self .sticker .to_dict ()
218- if self .video :
219- data ['video' ] = self .video .to_dict ()
220- if self .voice :
221- data ['voice' ] = self .voice .to_dict ()
222- if self .caption :
223- data ['caption' ] = self .caption
224- if self .contact :
225- data ['contact' ] = self .contact .to_dict ()
226- if self .location :
227- data ['location' ] = self .location .to_dict ()
228- if self .new_chat_participant :
229- data ['new_chat_participant' ] = self .new_chat_participant .to_dict ()
230- if self .left_chat_participant :
231- data ['left_chat_participant' ] = \
232- self .left_chat_participant .to_dict ()
233- if self .new_chat_title :
234- data ['new_chat_title' ] = self .new_chat_title
235189 if self .new_chat_photo :
236190 data ['new_chat_photo' ] = [p .to_dict () for p in self .new_chat_photo ]
237- if self .delete_chat_photo :
238- data ['delete_chat_photo' ] = self .delete_chat_photo
239- if self .group_chat_created :
240- data ['group_chat_created' ] = self .group_chat_created
241191
242192 return data
243193
0 commit comments