home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / msim / MSIMConversation.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  8.8 KB  |  223 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import logging
  5. import common
  6. import util.callbacks as callbacks
  7. log = logging.getLogger('msim.conversation')
  8.  
  9. class Zap(object):
  10.     
  11.     def name(self):
  12.         raise NotImplementedError
  13.  
  14.     name = property(name)
  15.     
  16.     def received(self, from_who):
  17.         raise NotImplementedError
  18.  
  19.     
  20.     def sent(self, to_who):
  21.         raise NotImplementedError
  22.  
  23.     
  24.     def nice_name(self):
  25.         raise NotImplementedError
  26.  
  27.  
  28.  
  29. class BasicZap(Zap):
  30.     name = None
  31.     
  32.     def received(self, from_who):
  33.         return self.recv_msg % from_who
  34.  
  35.     
  36.     def sent(self, to_who):
  37.         return self.sent_msg % to_who
  38.  
  39.     
  40.     def nice_name(self):
  41.         return self.nice_name
  42.  
  43.  
  44.  
  45. class ZapZap(BasicZap):
  46.     name = u'zap'
  47.     recv_msg = _(u'%s zapped you')
  48.     sent_msg = _(u'You zapped %s')
  49.     nice_name = _(u'Zap')
  50.  
  51.  
  52. class ZapWhack(BasicZap):
  53.     name = u'whack'
  54.     recv_msg = _(u'%s whacked you')
  55.     sent_msg = _(u'You whacked %s')
  56.     nice_name = _(u'Whack')
  57.  
  58.  
  59. class ZapTorch(BasicZap):
  60.     name = u'torch'
  61.     recv_msg = _(u'%s torched you')
  62.     sent_msg = _(u'You torched %s')
  63.     nice_name = _(u'Torch')
  64.  
  65.  
  66. class ZapSmooch(BasicZap):
  67.     name = u'smooch'
  68.     recv_msg = _(u'%s smooched you')
  69.     sent_msg = _(u'You smooched %s')
  70.     nice_name = _(u'Smooch')
  71.  
  72.  
  73. class ZapSlap(BasicZap):
  74.     name = u'bslap'
  75.     recv_msg = _(u'%s slapped you')
  76.     sent_msg = _(u'You slapped %s')
  77.     nice_name = _(u'Slap')
  78.  
  79.  
  80. class ZapGoose(BasicZap):
  81.     name = u'goose'
  82.     recv_msg = _(u'%s goosed you')
  83.     sent_msg = _(u'You goosed %s')
  84.     nice_name = _(u'Goose')
  85.  
  86.  
  87. class ZapHiFive(BasicZap):
  88.     name = u'hi-five'
  89.     recv_msg = _(u'%s high-fived you')
  90.     sent_msg = _(u'You high-fived %s')
  91.     nice_name = _(u'High-Five')
  92.  
  93.  
  94. class ZapPunk(BasicZap):
  95.     name = u"punk'd"
  96.     recv_msg = _(u"%s punk'd you")
  97.     sent_msg = _(u"You punk'd %s")
  98.     nice_name = _(u'Punk')
  99.  
  100.  
  101. class ZapRaspberry(BasicZap):
  102.     name = u'raspberry'
  103.     recv_msg = _(u"%s raspberry'd you")
  104.     sent_msg = _(u"You raspberry'd %s")
  105.     nice_name = _(u'Raspberry')
  106.  
  107. AllZapTypes = [
  108.     ZapZap,
  109.     ZapWhack,
  110.     ZapTorch,
  111.     ZapSmooch,
  112.     ZapSlap,
  113.     ZapGoose,
  114.     ZapHiFive,
  115.     ZapPunk,
  116.     ZapRaspberry]
  117. _zaps = dict((lambda .0: for z in .0:
  118. (z.name, z))((lambda .0: for Z in .0:
  119. Z())(AllZapTypes)))
  120.  
  121. def zap_sent_text(zapname, to_who):
  122.     z = _zaps.get(zapname)
  123.     if z is None:
  124.         return u''
  125.     return z.sent(to_who)
  126.  
  127.  
  128. def zap_received_text(zapname, from_who):
  129.     z = _zaps.get(zapname)
  130.     if z is None:
  131.         return u''
  132.     return z.received(from_who)
  133.  
  134.  
  135. class MSIMConversation(common.Conversation):
  136.     ischat = False
  137.     
  138.     def __init__(self, protocol, contact_id):
  139.         common.Conversation.__init__(self, protocol)
  140.         self.contact_id = contact_id
  141.         self.buddy_join(self.contact)
  142.  
  143.     
  144.     def __repr__(self):
  145.         return '<%s for contact %r>' % (type(self).__name__, self.contact_id)
  146.  
  147.     
  148.     def self_buddy(self):
  149.         return self.protocol.self_buddy
  150.  
  151.     self_buddy = property(self_buddy)
  152.     
  153.     def contact(self):
  154.         return self.protocol.get_buddy(self.contact_id)
  155.  
  156.     contact = property(contact)
  157.     
  158.     def buddy(self):
  159.         return self.contact
  160.  
  161.     buddy = property(buddy)
  162.     
  163.     def name(self):
  164.         return self.buddy.alias
  165.  
  166.     name = property(name)
  167.     
  168.     def send_typing_status(self, status):
  169.         self.protocol.send_typing(who = self.buddy.id, typing = status == 'typing')
  170.  
  171.     
  172.     def received_typing(self, buddy, typing):
  173.         self.typing_status[buddy] = None if typing else None
  174.  
  175.     
  176.     def _send_message(self, message, callback = None, **k):
  177.         self.protocol.send_message(self.contact, message.format_as('msim'), callback = callback, **k)
  178.  
  179.     _send_message = callbacks.callsback(_send_message)
  180.     
  181.     def buddy_join(self, buddy):
  182.         self.room_list.append(buddy)
  183.         self.typing_status[buddy] = None
  184.  
  185.     
  186.     def received_group_message(self, group_id, actor_id, msg_text):
  187.         self.ischat = True
  188.         self.group_id = group_id
  189.         if actor_id is None:
  190.             self.process_system_message(msg_text)
  191.         else:
  192.             buddy = self.protocol.get_buddy(actor_id)
  193.             if buddy is None:
  194.                 buddy = self.buddy
  195.             
  196.             log.info('Group message from %r', buddy)
  197.             self.received_message(buddy, msg_text)
  198.  
  199.     
  200.     def process_system_message(self, text):
  201.         log.info('Got chat system message: %r', text)
  202.  
  203.     
  204.     def received_message(self, buddy, message):
  205.         if isinstance(message, bytes):
  206.             message = message.decode('utf8')
  207.         
  208.         common.Conversation.received_message(self, buddy, message, content_type = 'text/html')
  209.         self.typing_status[buddy] = None
  210.  
  211.     
  212.     def received_zap(self, buddy, zaptxt):
  213.         self.system_message(zap_received_text(zaptxt, buddy.alias))
  214.  
  215.     
  216.     def exit(self):
  217.         if getattr(self, 'ischat', False):
  218.             self.protocol.send_exitchat(self.contact_id, self.group_id)
  219.         
  220.         common.Conversation.exit(self)
  221.  
  222.  
  223.