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