1 '''Chats.
2 '''
3
4 from utils import *
5 from user import *
6 from enums import *
7 from errors import *
8
9
11 '''Represents a Skype chat.
12 '''
13
16
17 - def _Alter(self, AlterName, Args=None):
18 return self._Skype._Alter('CHAT', self._Name, AlterName, Args, 'ALTER CHAT %s' % AlterName)
19
20 - def _Init(self, Name, Skype):
21 self._Skype = Skype
22 self._Name = Name
23
24 - def _Property(self, PropName, Value=None, Cache=True):
25 return self._Skype._Property('CHAT', self._Name, PropName, Value, Cache)
26
28 '''Accepts a shared group add request.
29 '''
30 self._Alter('ACCEPTADD')
31
33 '''Adds new members to the chat.
34
35 @param Members: One or more users to add.
36 @type Members: L{IUser}
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 @param Password: Password
59 @type Password: unicode
60 '''
61 self._Alter('ENTERPASSWORD', Password)
62
64 '''Joins the chat.
65 '''
66 self._Alter('JOIN')
67
68 - def Kick(self, Handle):
69 '''Kicks a member from chat.
70
71 @param Handle: Handle
72 @type Handle: unicode
73 '''
74 self._Alter('KICK', Handle)
75
77 '''Kicks and bans a member from chat.
78
79 @param Handle: Handle
80 @type Handle: unicode
81 '''
82 self._Alter('KICKBAN', Handle)
83
85 '''Leaves the chat.
86 '''
87 self._Alter('LEAVE')
88
90 '''Opens the chat window.
91 '''
92 self._Skype.Client.OpenDialog('CHAT', self._Name)
93
95 '''Sends a chat message.
96
97 @param MessageText: Message text
98 @type MessageText: unicode
99 @return: Message object
100 @rtype: L{IChatMessage}
101 '''
102 return IChatMessage(chop(self._Skype._DoCommand('CHATMESSAGE %s %s' % (self._Name, MessageText)), 2)[1], self._Skype)
103
105 '''Sets the chat password.
106
107 @param Password: Password
108 @type Password: unicode
109 @param Hint: Password hint
110 @type Hint: unicode
111 '''
112 if ' ' in Password:
113 raise ValueError('Password mut be one word')
114 self._Alter('SETPASSWORD', '%s %s' % (Password, Hint))
115
117 '''Unbookmarks the chat.
118 '''
119 self._Alter('UNBOOKMARK')
120
122 return tuple(IUser(x, self._Skype) for x in esplit(self._Property('ACTIVEMEMBERS', Cache=False)))
123
124 ActiveMembers = property(_GetActiveMembers,
125 doc='''Active members of a chat.
126
127 @type: tuple of L{IUser}
128 ''')
129
131 from datetime import datetime
132 return datetime.fromtimestamp(self.ActivityTimestamp)
133
134 ActivityDatetime = property(_GetActivityDatetime,
135 doc='''Returns chat activity timestamp as datetime.
136
137 @type: datetime.datetime
138 ''')
139
141 return float(self._Property('ACTIVITY_TIMESTAMP'))
142
143 ActivityTimestamp = property(_GetActivityTimestamp,
144 doc='''Returns chat activity timestamp.
145
146 @type: float
147 @see: L{ActivityDatetime}
148 ''')
149
151 return IUser(self._Property('ADDER'), self._Skype)
152
153 Adder = property(_GetAdder,
154 doc='''Returns the user that added current user to the chat.
155
156 @type: L{IUser}
157 ''')
158
160 self._Alter('SETALERTSTRING', quote('=%s' % value))
161
162 AlertString = property(fset=_SetAlertString,
163 doc='''Chat alert string. Only messages containing words from this string will cause a
164 notification to pop up on the screen.
165
166 @type: unicode
167 ''')
168
170 return tuple(IUser(x, self._Skype) for x in esplit(self._Property('APPLICANTS')))
171
172 Applicants = property(_GetApplicants,
173 doc='''Chat applicants.
174
175 @type: tuple of L{IUser}
176 ''')
177
179 return self._Property('BLOB')
180
181 Blob = property(_GetBlob,
182 doc='''Chat blob.
183
184 @type: unicode
185 ''')
186
188 return self._Property('BOOKMARKED') == 'TRUE'
189
190 Bookmarked = property(_GetBookmarked,
191 doc='''Tells if this chat is bookmarked.
192
193 @type: bool
194 ''')
195
197 from datetime import datetime
198 return datetime.fromtimestamp(self.Timestamp)
199
200 Datetime = property(_GetDatetime,
201 doc='''Chat timestamp as datetime.
202
203 @type: datetime.datetime
204 ''')
205
207 return self._Property('DESCRIPTION')
208
210 self._Property('DESCRIPTION', value)
211
212 Description = property(_GetDescription, _SetDescription,
213 doc='''Chat description.
214
215 @type: unicode
216 ''')
217
219 return self._Property('DIALOG_PARTNER')
220
221 DialogPartner = property(_GetDialogPartner,
222 doc='''Skypename of the chat dialog partner.
223
224 @type: unicode
225 ''')
226
228 return self._Property('FRIENDLYNAME')
229
230 FriendlyName = property(_GetFriendlyName,
231 doc='''Friendly name of the chat.
232
233 @type: unicode
234 ''')
235
237 return self._Property('GUIDELINES')
238
240 self._Alter('SETGUIDELINES', value)
241
242 GuideLines = property(_GetGuideLines, _SetGuideLines,
243 doc='''Chat guidelines.
244
245 @type: unicode
246 ''')
247
249 return tuple(IChatMember(x, self._Skype) for x in esplit(self._Property('MEMBEROBJECTS'), ', '))
250
251 MemberObjects = property(_GetMemberObjects,
252 doc='''Chat members as member objects.
253
254 @type: tuple of L{IChatMember}
255 ''')
256
258 return tuple(IUser(x, self._Skype) for x in esplit(self._Property('MEMBERS')))
259
260 Members = property(_GetMembers,
261 doc='''Chat members.
262
263 @type: tuple of L{IUser}
264 ''')
265
268
269 Messages = property(_GetMessages,
270 doc='''All chat messages.
271
272 @type: tuple of L{IChatMessage}
273 ''')
274
276 return self._Property('MYROLE')
277
278 MyRole = property(_GetMyRole,
279 doc='''My chat role in a public chat.
280
281 @type: L{Chat member role<enums.chatMemberRoleUnknown>}
282 ''')
283
285 return self._Property('MYSTATUS')
286
287 MyStatus = property(_GetMyStatus,
288 doc='''My status in a public chat.
289
290 @type: L{My chat status<enums.chatStatusUnknown>}
291 ''')
292
295
296 Name = property(_GetName,
297 doc='''Chat name as used by Skype to identify this chat.
298
299 @type: unicode
300 ''')
301
303 return int(self._Property('OPTIONS'))
304
306 self._Alter('SETOPTIONS', value)
307
308 Options = property(_GetOptions, _SetOptions,
309 doc='''Chat options. A mask.
310
311 @type: L{Chat options<enums.chatOptionJoiningEnabled>}
312 ''')
313
315 return self._Property('PASSWORDHINT')
316
317 PasswordHint = property(_GetPasswordHint,
318 doc='''Chat password hint.
319
320 @type: unicode
321 ''')
322
323 - def _GetPosters(self):
324 return tuple(IUser(x, self._Skype) for x in esplit(self._Property('POSTERS')))
325
326 Posters = property(_GetPosters,
327 doc='''Users who have posted messages to this chat.
328
329 @type: tuple of L{IUser}
330 ''')
331
333 return tuple(IChatMessage(x, self._Skype) for x in esplit(self._Property('RECENTCHATMESSAGES', Cache=False), ', '))
334
335 RecentMessages = property(_GetRecentMessages,
336 doc='''Most recent chat messages.
337
338 @type: tuple of L{IChatMessage}
339 ''')
340
342 return self._Property('STATUS')
343
344 Status = property(_GetStatus,
345 doc='''Status.
346
347 @type: L{Chat status<enums.chsUnknown>}
348 ''')
349
351 return float(self._Property('TIMESTAMP'))
352
353 Timestamp = property(_GetTimestamp,
354 doc='''Chat timestamp.
355
356 @type: float
357 @see: L{Datetime}
358 ''')
359
361 try:
362 topicxml = self._Property('TOPICXML')
363 if topicxml:
364 return topicxml
365 except ISkypeError:
366 pass
367 return self._Property('TOPIC')
368
370 try:
371 self._Alter('SETTOPICXML', value)
372 except ISkypeError:
373 self._Alter('SETTOPIC', value)
374
375 Topic = property(_GetTopic, _SetTopic,
376 doc='''Chat topic.
377
378 @type: unicode
379 ''')
380
382 return self._Property('TOPICXML')
383
385 self._Property('TOPICXML', value)
386
387 TopicXML = property(_GetTopicXML, _SetTopicXML,
388 doc='''Chat topic in XML format.
389
390 @type: unicode
391 ''')
392
394 return self._Property('TYPE')
395
396 Type = property(_GetType,
397 doc='''Chat type.
398
399 @type: L{Chat type<enums.chatTypeUnknown>}
400 ''')
401
402
404 '''Represents a single chat message.
405 '''
406
409
410 - def _Init(self, Id, Skype):
411 self._Skype = Skype
412 self._Id = int(Id)
413
414 - def _Property(self, PropName, Value=None, Cache=True):
415 return self._Skype._Property('CHATMESSAGE', self._Id, PropName, Value, Cache)
416
418 '''Marks a missed chat message as seen.
419 '''
420 self._Skype._DoCommand('SET CHATMESSAGE %d SEEN' % self._Id, 'CHATMESSAGE %d STATUS READ' % self._Id)
421
422 - def _GetBody(self):
423 return self._Property('BODY')
424
425 - def _SetBody(self, value):
426 self._Property('BODY', value)
427
428 Body = property(_GetBody, _SetBody,
429 doc='''Chat message body.
430
431 @type: unicode
432 ''')
433
436
437 Chat = property(_GetChat,
438 doc='''Chat this message was posted on.
439
440 @type: L{IChat}
441 ''')
442
444 return self._Property('CHATNAME')
445
446 ChatName = property(_GetChatName,
447 doc='''Name of the chat this message was posted on.
448
449 @type: unicode
450 ''')
451
453 from datetime import datetime
454 return datetime.fromtimestamp(self.Timestamp)
455
456 Datetime = property(_GetDatetime,
457 doc='''Chat message timestamp as datetime.
458
459 @type: datetime.datetime
460 ''')
461
463 return self._Property('EDITED_BY')
464
465 EditedBy = property(_GetEditedBy,
466 doc='''Skypename of the user who edited this message.
467
468 @type: unicode
469 ''')
470
472 from datetime import datetime
473 return datetime.fromtimestamp(self.EditedTimestamp)
474
475 EditedDatetime = property(_GetEditedDatetime,
476 doc='''Message editing timestamp as datetime.
477
478 @type: datetime.datetime
479 ''')
480
482 return float(self._Property('EDITED_TIMESTAMP'))
483
484 EditedTimestamp = property(_GetEditedTimestamp,
485 doc='''Message editing timestamp.
486
487 @type: float
488 ''')
489
491 return self._Property('FROM_DISPNAME')
492
493 FromDisplayName = property(_GetFromDisplayName,
494 doc='''DisplayName of the message sender.
495
496 @type: unicode
497 ''')
498
500 return self._Property('FROM_HANDLE')
501
502 FromHandle = property(_GetFromHandle,
503 doc='''Skypename of the message sender.
504
505 @type: unicode
506 ''')
507
510
511 Id = property(_GetId,
512 doc='''Chat message Id.
513
514 @type: int
515 ''')
516
518 return self._Property('IS_EDITABLE') == 'TRUE'
519
520 IsEditable = property(_GetIsEditable,
521 doc='''Tells if message body is editable.
522
523 @type: bool
524 ''')
525
527 return self._Property('LEAVEREASON')
528
529 LeaveReason = property(_GetLeaveReason,
530 doc='''LeaveReason.
531
532 @type: L{Chat leave reason<enums.leaUnknown>}
533 ''')
534
536 from warnings import warn
537 warn('IChatMessage.Seen = x: Use IChatMessage.MarkAsSeen() instead.', DeprecationWarning, stacklevel=2)
538 if value:
539 self.MarkAsSeen()
540 else:
541 raise ISkypeError(0, 'Seen can only be set to True')
542
543 Seen = property(fset=_SetSeen,
544 doc='''Marks a missed chat message as seen.
545
546 @type: bool
547 @deprecated: Unpythonic, use L{MarkAsSeen} instead.
548 ''')
549
552
553 Sender = property(_GetSender,
554 doc='''Sender of the chat message.
555
556 @type: L{IUser}
557 ''')
558
560 return self._Property('STATUS')
561
562 Status = property(_GetStatus,
563 doc='''Status of the chat messsage.
564
565 @type: L{Chat message status<enums.cmsUnknown>}
566 ''')
567
569 return float(self._Property('TIMESTAMP'))
570
571 Timestamp = property(_GetTimestamp,
572 doc='''Chat message timestamp.
573
574 @type: float
575 @see: L{Datetime}
576 ''')
577
579 return self._Property('TYPE')
580
581 Type = property(_GetType,
582 doc='''Type of chat message.
583
584 @type: L{Chat message type<enums.cmeUnknown>}
585 ''')
586
588 return tuple(IUser(self._Skype, x) for x in esplit(self._Property('USERS')))
589
590 Users = property(_GetUsers,
591 doc='''Users added to the chat.
592
593 @type: tuple of L{IUser}
594 ''')
595
596
598 '''Represents a member of a public chat.
599 '''
600
603
604 - def _Alter(self, AlterName, Args=None):
605 return self._Skype._Alter('CHATMEMBER', self._Id, AlterName, Args, 'ALTER CHATMEMBER %s' % AlterName)
606
607 - def _Init(self, Id, Skype):
608 self._Skype = Skype
609 self._Id = int(Id)
610
611 - def _Property(self, PropName, Value=None, Cache=True):
612 return self._Skype._Property('CHATMEMBER', self._Id, PropName, Value, Cache)
613
615 '''Checks if the new role can be applied to the member.
616
617 @param Role: New chat member role.
618 @type Role: L{Chat member role<enums.chatMemberRoleUnknown>}
619 @return: True if the new role can be applied, False otherwise.
620 @rtype: bool
621 '''
622 return self._Alter('CANSETROLETO', Role) == 'TRUE'
623
625 return IChat(self._Property('CHATNAME'), self._Skype)
626
627 Chat = property(_GetChat,
628 doc='''Chat this member belongs to.
629
630 @type: L{IChat}
631 ''')
632
634 return self._Property('IDENTITY')
635
636 Handle = property(_GetHandle,
637 doc='''Member Skypename.
638
639 @type: unicode
640 ''')
641
644
645 Id = property(_GetId,
646 doc='''Chat member Id.
647
648 @type: int
649 ''')
650
652 return self._Property('IS_ACTIVE') == 'TRUE'
653
654 IsActive = property(_GetIsActive,
655 doc='''Member activity status.
656
657 @type: bool
658 ''')
659
661 return self._Property('ROLE')
662
664 self._Alter('SETROLETO', value)
665
666 Role = property(_GetRole, _SetRole,
667 doc='''Chat Member role.
668
669 @type: L{Chat member role<enums.chatMemberRoleUnknown>}
670 ''')
671