1 """Chats.
2 """
3 __docformat__ = 'restructuredtext en'
4
5
6 from utils import *
7 from user import *
8 from errors import SkypeError
9
10
12 """Represents a Skype chat.
13 """
14 _ValidateHandle = str
15
18
19 - def _Alter(self, AlterName, Args=None):
20 return self._Owner._Alter('CHAT', self.Name, AlterName, Args,
21 'ALTER CHAT %s %s' % (self.Name, AlterName))
22
23 - def _Property(self, PropName, Value=None, Cache=True):
24 return self._Owner._Property('CHAT', self.Name, PropName, Value, Cache)
25
27 """Accepts a shared group add request.
28 """
29 self._Alter('ACCEPTADD')
30
32 """Adds new members to the chat.
33
34 :Parameters:
35 Members : `User`
36 One or more users to add.
37 """
38 self._Alter('ADDMEMBERS', ', '.join([x.Handle for x in Members]))
39
41 """Bookmarks the chat in Skype client.
42 """
43 self._Alter('BOOKMARK')
44
46 """Clears recent chat messages.
47 """
48 self._Alter('CLEARRECENTMESSAGES')
49
51 """Ends the chat.
52 """
53 self._Alter('DISBAND')
54
56 """Enters chat password.
57
58 :Parameters:
59 Password : unicode
60 Password
61 """
62 self._Alter('ENTERPASSWORD', tounicode(Password))
63
65 """Joins the chat.
66 """
67 self._Alter('JOIN')
68
69 - def Kick(self, *Handles):
70 """Kicks member(s) from chat.
71
72 :Parameters:
73 Handles : str
74 Skype username(s).
75 """
76 self._Alter('KICK', ', '.join(Handles))
77
79 """Kicks and bans member(s) from chat.
80
81 :Parameters:
82 Handles : str
83 Skype username(s).
84 """
85 self._Alter('KICKBAN', ', '.join(Handles))
86
88 """Leaves the chat.
89 """
90 self._Alter('LEAVE')
91
96
98 """Sends a chat message.
99
100 :Parameters:
101 MessageText : unicode
102 Message text
103
104 :return: Message object
105 :rtype: `ChatMessage`
106 """
107 return ChatMessage(self._Owner, chop(self._Owner._DoCommand('CHATMESSAGE %s %s' % (self.Name,
108 tounicode(MessageText))), 2)[1])
109
111 """Sets the chat password.
112
113 :Parameters:
114 Password : unicode
115 Password
116 Hint : unicode
117 Password hint
118 """
119 if ' ' in Password:
120 raise ValueError('Password mut be one word')
121 self._Alter('SETPASSWORD', '%s %s' % (tounicode(Password), tounicode(Hint)))
122
124 """Unbookmarks the chat.
125 """
126 self._Alter('UNBOOKMARK')
127
130
131 ActiveMembers = property(_GetActiveMembers,
132 doc="""Active members of a chat.
133
134 :type: `UserCollection`
135 """)
136
138 from datetime import datetime
139 return datetime.fromtimestamp(self.ActivityTimestamp)
140
141 ActivityDatetime = property(_GetActivityDatetime,
142 doc="""Returns chat activity timestamp as datetime.
143
144 :type: datetime.datetime
145 """)
146
148 return float(self._Property('ACTIVITY_TIMESTAMP'))
149
150 ActivityTimestamp = property(_GetActivityTimestamp,
151 doc="""Returns chat activity timestamp.
152
153 :type: float
154
155 :see: `ActivityDatetime`
156 """)
157
159 return User(self._Owner, self._Property('ADDER'))
160
161 Adder = property(_GetAdder,
162 doc="""Returns the user that added current user to the chat.
163
164 :type: `User`
165 """)
166
169
170 AlertString = property(fset=_SetAlertString,
171 doc="""Chat alert string. Only messages containing words from this string will cause a
172 notification to pop up on the screen.
173
174 :type: unicode
175 """)
176
179
180 Applicants = property(_GetApplicants,
181 doc="""Chat applicants.
182
183 :type: `UserCollection`
184 """)
185
187 return str(self._Property('BLOB'))
188
189 Blob = property(_GetBlob,
190 doc="""Chat blob.
191
192 :type: str
193 """)
194
196 return (self._Property('BOOKMARKED') == 'TRUE')
197
198 Bookmarked = property(_GetBookmarked,
199 doc="""Tells if this chat is bookmarked.
200
201 :type: bool
202 """)
203
205 from datetime import datetime
206 return datetime.fromtimestamp(self.Timestamp)
207
208 Datetime = property(_GetDatetime,
209 doc="""Chat timestamp as datetime.
210
211 :type: datetime.datetime
212 """)
213
215 return self._Property('DESCRIPTION')
216
218 self._Property('DESCRIPTION', tounicode(Value))
219
220 Description = property(_GetDescription, _SetDescription,
221 doc="""Chat description.
222
223 :type: unicode
224 """)
225
227 return str(self._Property('DIALOG_PARTNER'))
228
229 DialogPartner = property(_GetDialogPartner,
230 doc="""Skypename of the chat dialog partner.
231
232 :type: str
233 """)
234
236 return self._Property('FRIENDLYNAME')
237
238 FriendlyName = property(_GetFriendlyName,
239 doc="""Friendly name of the chat.
240
241 :type: unicode
242 """)
243
245 return self._Property('GUIDELINES')
246
248 self._Alter('SETGUIDELINES', tounicode(Value))
249
250 GuideLines = property(_GetGuideLines, _SetGuideLines,
251 doc="""Chat guidelines.
252
253 :type: unicode
254 """)
255
258
259 MemberObjects = property(_GetMemberObjects,
260 doc="""Chat members as member objects.
261
262 :type: `ChatMemberCollection`
263 """)
264
267
268 Members = property(_GetMembers,
269 doc="""Chat members.
270
271 :type: `UserCollection`
272 """)
273
276
277 Messages = property(_GetMessages,
278 doc="""All chat messages.
279
280 :type: `ChatMessageCollection`
281 """)
282
284 return str(self._Property('MYROLE'))
285
286 MyRole = property(_GetMyRole,
287 doc="""My chat role in a public chat.
288
289 :type: `enums`.chatMemberRole*
290 """)
291
293 return str(self._Property('MYSTATUS'))
294
295 MyStatus = property(_GetMyStatus,
296 doc="""My status in a public chat.
297
298 :type: `enums`.chatStatus*
299 """)
300
303
304 Name = property(_GetName,
305 doc="""Chat name as used by Skype to identify this chat.
306
307 :type: str
308 """)
309
311 return int(self._Property('OPTIONS'))
312
314 self._Alter('SETOPTIONS', Value)
315
316 Options = property(_GetOptions, _SetOptions,
317 doc="""Chat options. A mask.
318
319 :type: `enums`.chatOption*
320 """)
321
323 return self._Property('PASSWORDHINT')
324
325 PasswordHint = property(_GetPasswordHint,
326 doc="""Chat password hint.
327
328 :type: unicode
329 """)
330
331 - def _GetPosters(self):
332 return UserCollection(self._Owner, split(self._Property('POSTERS')))
333
334 Posters = property(_GetPosters,
335 doc="""Users who have posted messages to this chat.
336
337 :type: `UserCollection`
338 """)
339
342
343 RecentMessages = property(_GetRecentMessages,
344 doc="""Most recent chat messages.
345
346 :type: `ChatMessageCollection`
347 """)
348
350 return str(self._Property('STATUS'))
351
352 Status = property(_GetStatus,
353 doc="""Status.
354
355 :type: `enums`.chs*
356 """)
357
359 return float(self._Property('TIMESTAMP'))
360
361 Timestamp = property(_GetTimestamp,
362 doc="""Chat timestamp.
363
364 :type: float
365
366 :see: `Datetime`
367 """)
368
369
370
372 return self._Property('TOPIC')
373
375 self._Alter('SETTOPIC', tounicode(Value))
376
377 Topic = property(_GetTopic, _SetTopic,
378 doc="""Chat topic.
379
380 :type: unicode
381 """)
382
384 return self._Property('TOPICXML')
385
387 self._Alter('SETTOPICXML', tounicode(Value))
388
389 TopicXML = property(_GetTopicXML, _SetTopicXML,
390 doc="""Chat topic in XML format.
391
392 :type: unicode
393 """)
394
396 return str(self._Property('TYPE'))
397
398 Type = property(_GetType,
399 doc="""Chat type.
400
401 :type: `enums`.chatType*
402 """)
403
404
407
408
410 """Represents a single chat message.
411 """
412 _ValidateHandle = int
413
416
417 - def _Property(self, PropName, Value=None, Cache=True):
418 return self._Owner._Property('CHATMESSAGE', self.Id, PropName, Value, Cache)
419
421 """Marks a missed chat message as seen.
422 """
423 self._Owner._DoCommand('SET CHATMESSAGE %d SEEN' % self.Id, 'CHATMESSAGE %d STATUS READ' % self.Id)
424
425 - def _GetBody(self):
426 return self._Property('BODY')
427
428 - def _SetBody(self, Value):
429 self._Property('BODY', tounicode(Value))
430
431 Body = property(_GetBody, _SetBody,
432 doc="""Chat message body.
433
434 :type: unicode
435 """)
436
439
440 Chat = property(_GetChat,
441 doc="""Chat this message was posted on.
442
443 :type: `Chat`
444 """)
445
447 return str(self._Property('CHATNAME'))
448
449 ChatName = property(_GetChatName,
450 doc="""Name of the chat this message was posted on.
451
452 :type: str
453 """)
454
456 from datetime import datetime
457 return datetime.fromtimestamp(self.Timestamp)
458
459 Datetime = property(_GetDatetime,
460 doc="""Chat message timestamp as datetime.
461
462 :type: datetime.datetime
463 """)
464
466 return str(self._Property('EDITED_BY'))
467
468 EditedBy = property(_GetEditedBy,
469 doc="""Skypename of the user who edited this message.
470
471 :type: str
472 """)
473
475 from datetime import datetime
476 return datetime.fromtimestamp(self.EditedTimestamp)
477
478 EditedDatetime = property(_GetEditedDatetime,
479 doc="""Message editing timestamp as datetime.
480
481 :type: datetime.datetime
482 """)
483
485 return float(self._Property('EDITED_TIMESTAMP'))
486
487 EditedTimestamp = property(_GetEditedTimestamp,
488 doc="""Message editing timestamp.
489
490 :type: float
491 """)
492
494 return self._Property('FROM_DISPNAME')
495
496 FromDisplayName = property(_GetFromDisplayName,
497 doc="""DisplayName of the message sender.
498
499 :type: unicode
500 """)
501
503 return str(self._Property('FROM_HANDLE'))
504
505 FromHandle = property(_GetFromHandle,
506 doc="""Skypename of the message sender.
507
508 :type: str
509 """)
510
513
514 Id = property(_GetId,
515 doc="""Chat message Id.
516
517 :type: int
518 """)
519
521 return (self._Property('IS_EDITABLE') == 'TRUE')
522
523 IsEditable = property(_GetIsEditable,
524 doc="""Tells if message body is editable.
525
526 :type: bool
527 """)
528
530 return str(self._Property('LEAVEREASON'))
531
532 LeaveReason = property(_GetLeaveReason,
533 doc="""LeaveReason.
534
535 :type: `enums`.lea*
536 """)
537
539 from warnings import warn
540 warn('ChatMessage.Seen = x: Use ChatMessage.MarkAsSeen() instead.', DeprecationWarning, stacklevel=2)
541 if Value:
542 self.MarkAsSeen()
543 else:
544 raise SkypeError(0, 'Seen can only be set to True')
545
546 Seen = property(fset=_SetSeen,
547 doc="""Marks a missed chat message as seen. Accepts only True value.
548
549 :type: bool
550
551 :deprecated: Extremely unpythonic, use `MarkAsSeen` instead.
552 """)
553
556
557 Sender = property(_GetSender,
558 doc="""Sender of the chat message.
559
560 :type: `User`
561 """)
562
564 return str(self._Property('STATUS'))
565
566 Status = property(_GetStatus,
567 doc="""Status of the chat message.
568
569 :type: `enums`.cms*
570 """)
571
573 return float(self._Property('TIMESTAMP'))
574
575 Timestamp = property(_GetTimestamp,
576 doc="""Chat message timestamp.
577
578 :type: float
579
580 :see: `Datetime`
581 """)
582
584 return str(self._Property('TYPE'))
585
586 Type = property(_GetType,
587 doc="""Type of chat message.
588
589 :type: `enums`.cme*
590 """)
591
594
595 Users = property(_GetUsers,
596 doc="""Users added to the chat.
597
598 :type: `UserCollection`
599 """)
600
601
604
605
607 """Represents a member of a public chat.
608 """
609 _ValidateHandle = int
610
613
614 - def _Alter(self, AlterName, Args=None):
615 return self._Owner._Alter('CHATMEMBER', self.Id, AlterName, Args,
616 'ALTER CHATMEMBER %s %s' % (self.Id, AlterName))
617
618 - def _Property(self, PropName, Value=None, Cache=True):
619 return self._Owner._Property('CHATMEMBER', self.Id, PropName, Value, Cache)
620
622 """Checks if the new role can be applied to the member.
623
624 :Parameters:
625 Role : `enums`.chatMemberRole*
626 New chat member role.
627
628 :return: True if the new role can be applied, False otherwise.
629 :rtype: bool
630 """
631 t = self._Owner._Alter('CHATMEMBER', self.Id, 'CANSETROLETO', Role,
632 'ALTER CHATMEMBER CANSETROLETO')
633 return (chop(t, 1)[-1] == 'TRUE')
634
636 return Chat(self._Owner, self._Property('CHATNAME'))
637
638 Chat = property(_GetChat,
639 doc="""Chat this member belongs to.
640
641 :type: `Chat`
642 """)
643
645 return str(self._Property('IDENTITY'))
646
647 Handle = property(_GetHandle,
648 doc="""Member Skypename.
649
650 :type: str
651 """)
652
655
656 Id = property(_GetId,
657 doc="""Chat member Id.
658
659 :type: int
660 """)
661
663 return (self._Property('IS_ACTIVE') == 'TRUE')
664
665 IsActive = property(_GetIsActive,
666 doc="""Member activity status.
667
668 :type: bool
669 """)
670
672 return str(self._Property('ROLE'))
673
675 self._Alter('SETROLETO', Value)
676
677 Role = property(_GetRole, _SetRole,
678 doc="""Chat Member role.
679
680 :type: `enums`.chatMemberRole*
681 """)
682
683
686