home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import logging
- import common
- import util.callbacks as callbacks
- log = logging.getLogger('msim.conversation')
-
- class Zap(object):
-
- def name(self):
- raise NotImplementedError
-
- name = property(name)
-
- def received(self, from_who):
- raise NotImplementedError
-
-
- def sent(self, to_who):
- raise NotImplementedError
-
-
- def nice_name(self):
- raise NotImplementedError
-
-
-
- class BasicZap(Zap):
- name = None
-
- def received(self, from_who):
- return self.recv_msg % from_who
-
-
- def sent(self, to_who):
- return self.sent_msg % to_who
-
-
- def nice_name(self):
- return self.nice_name
-
-
-
- class ZapZap(BasicZap):
- name = u'zap'
- recv_msg = _(u'%s zapped you')
- sent_msg = _(u'You zapped %s')
- nice_name = _(u'Zap')
-
-
- class ZapWhack(BasicZap):
- name = u'whack'
- recv_msg = _(u'%s whacked you')
- sent_msg = _(u'You whacked %s')
- nice_name = _(u'Whack')
-
-
- class ZapTorch(BasicZap):
- name = u'torch'
- recv_msg = _(u'%s torched you')
- sent_msg = _(u'You torched %s')
- nice_name = _(u'Torch')
-
-
- class ZapSmooch(BasicZap):
- name = u'smooch'
- recv_msg = _(u'%s smooched you')
- sent_msg = _(u'You smooched %s')
- nice_name = _(u'Smooch')
-
-
- class ZapSlap(BasicZap):
- name = u'bslap'
- recv_msg = _(u'%s slapped you')
- sent_msg = _(u'You slapped %s')
- nice_name = _(u'Slap')
-
-
- class ZapGoose(BasicZap):
- name = u'goose'
- recv_msg = _(u'%s goosed you')
- sent_msg = _(u'You goosed %s')
- nice_name = _(u'Goose')
-
-
- class ZapHiFive(BasicZap):
- name = u'hi-five'
- recv_msg = _(u'%s high-fived you')
- sent_msg = _(u'You high-fived %s')
- nice_name = _(u'High-Five')
-
-
- class ZapPunk(BasicZap):
- name = u"punk'd"
- recv_msg = _(u"%s punk'd you")
- sent_msg = _(u"You punk'd %s")
- nice_name = _(u'Punk')
-
-
- class ZapRaspberry(BasicZap):
- name = u'raspberry'
- recv_msg = _(u"%s raspberry'd you")
- sent_msg = _(u"You raspberry'd %s")
- nice_name = _(u'Raspberry')
-
- AllZapTypes = [
- ZapZap,
- ZapWhack,
- ZapTorch,
- ZapSmooch,
- ZapSlap,
- ZapGoose,
- ZapHiFive,
- ZapPunk,
- ZapRaspberry]
- _zaps = dict((lambda .0: for z in .0:
- (z.name, z))((lambda .0: for Z in .0:
- Z())(AllZapTypes)))
-
- def zap_sent_text(zapname, to_who):
- z = _zaps.get(zapname)
- if z is None:
- return u''
- return z.sent(to_who)
-
-
- def zap_received_text(zapname, from_who):
- z = _zaps.get(zapname)
- if z is None:
- return u''
- return z.received(from_who)
-
-
- class MSIMConversation(common.Conversation):
- ischat = False
-
- def __init__(self, protocol, contact_id):
- common.Conversation.__init__(self, protocol)
- self.contact_id = contact_id
- self.buddy_join(self.contact)
-
-
- def __repr__(self):
- return '<%s for contact %r>' % (type(self).__name__, self.contact_id)
-
-
- def self_buddy(self):
- return self.protocol.self_buddy
-
- self_buddy = property(self_buddy)
-
- def contact(self):
- return self.protocol.get_buddy(self.contact_id)
-
- contact = property(contact)
-
- def buddy(self):
- return self.contact
-
- buddy = property(buddy)
-
- def name(self):
- return self.buddy.alias
-
- name = property(name)
-
- def send_typing_status(self, status):
- self.protocol.send_typing(who = self.buddy.id, typing = status == 'typing')
-
-
- def received_typing(self, buddy, typing):
- self.typing_status[buddy] = None if typing else None
-
-
- def _send_message(self, message, callback = None, **k):
- self.protocol.send_message(self.contact, message.format_as('msim'), callback = callback, **k)
-
- _send_message = callbacks.callsback(_send_message)
-
- def buddy_join(self, buddy):
- self.room_list.append(buddy)
- self.typing_status[buddy] = None
-
-
- def received_group_message(self, group_id, actor_id, msg_text):
- self.ischat = True
- self.group_id = group_id
- if actor_id is None:
- self.process_system_message(msg_text)
- else:
- buddy = self.protocol.get_buddy(actor_id)
- if buddy is None:
- buddy = self.buddy
-
- log.info('Group message from %r', buddy)
- self.received_message(buddy, msg_text)
-
-
- def process_system_message(self, text):
- log.info('Got chat system message: %r', text)
-
-
- def received_message(self, buddy, message):
- if isinstance(message, bytes):
- message = message.decode('utf8')
-
- common.Conversation.received_message(self, buddy, message, content_type = 'text/html')
- self.typing_status[buddy] = None
-
-
- def received_zap(self, buddy, zaptxt):
- self.system_message(zap_received_text(zaptxt, buddy.alias))
-
-
- def exit(self):
- if getattr(self, 'ischat', False):
- self.protocol.send_exitchat(self.contact_id, self.group_id)
-
- common.Conversation.exit(self)
-
-
-