コード例 #1
0
ファイル: activitysession.py プロジェクト: Daksh/joke-machine
  def broadcast_joke_cb(self, jokebook_id, joke_pickle, sender_nick, sender):
    '''handle a BroadCast Joke by creating a new joke in the local store'''
    if sender == self.my_bus_name:
      # Ignore my own signal
      return

    logging.debug('In broadcast_joke_cb. sender: %r' % sender)
    
    # 1. unpickle joke
    joke_pickle = str(joke_pickle)
    if len(joke_pickle) == 0:
      logging.debug('JokeMachineSession.broadcast_joke_cb() -> empty joke_pickle - doing nothing')
      return
    joke = Joke.loads(joke_pickle)
    if joke is None:
      logging.error('JokeMachineSession.broadcast_joke_cb -> could not unpickle joke')
      return
    
    # 2. get the jokebook it belongs to
    jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
    if jokebook is None:
      logging.error('Joke was broadcast to non-existent jokebook id %d', jokebook_id)
      return
    
    # 3. add it to jokes in the appropriate jokebook
    logging.debug('%s broadcast a joke to my jokebook# %d with text: %s and answer %s', joke.joker, jokebook_id, joke.text, joke.answer)    
    jokebook.jokes.append(joke)

    
    # 4. TODO - show some kind of alert - ask on #sugar
    message = str(sender_nick) + _(' accepted a joke submitted to ') + \
              str(jokebook.title) + _(' by ') + str(joke.joker)
    Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
コード例 #2
0
ファイル: activitysession.py プロジェクト: Daksh/joke-machine
 def submit_cb(self, jokebook_id, joke_pickle, sender=None):
   '''Receive someones submission
   jokebook_id -- the jokebook to submit joke to
   joke_pickle -- a pickled joke'''
   if sender == self.my_bus_name: # don't respond to own submit signal
     return
   logging.debug('In submit_cv. sender: %r' % sender)
   
   # 1. unpickle joke
   joke_pickle = str(joke_pickle)
   if len(joke_pickle) == 0:
     logging.debug('JokeMachineSession.submit_cb() -> empty joke_pickle - doing nothing')
     return
   joke = Joke.loads(joke_pickle)
   if joke is None:
     logging.error('JokeMachineSession.submit_cb -> could not unpickle joke')
     return
   
   # 2. get the jokebook it belongs to
   jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
   if jokebook is None:
     logging.error('Joke was submitted to non-existent jokebook id %d', jokebook_id)
     return
   
   # 3. add it to submissions in the appropriate jokebook
   logging.debug('%s submitted a joke to my jokebook# %d with text: %s and answer %s', joke.joker, jokebook_id, joke.text, joke.answer)
   jokebook.submissions.append(joke)
 
   # 4. alert the owner 
   message = str(joke.joker) + _(' submitted a joke to ') + str(jokebook.title)
   Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
コード例 #3
0
    def broadcast_joke_cb(self, jokebook_id, joke_pickle, sender_nick, sender):
        '''handle a BroadCast Joke by creating a new joke in the local store'''
        if sender == self.my_bus_name:
            # Ignore my own signal
            return

        logging.debug('In broadcast_joke_cb. sender: %r' % sender)

        # 1. unpickle joke
        joke_pickle = str(joke_pickle)
        if len(joke_pickle) == 0:
            logging.debug(
                'JokeMachineSession.broadcast_joke_cb() -> empty joke_pickle - doing nothing'
            )
            return
        joke = Joke.loads(joke_pickle)
        if joke is None:
            logging.error(
                'JokeMachineSession.broadcast_joke_cb -> could not unpickle joke'
            )
            return

        # 2. get the jokebook it belongs to
        jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
        if jokebook is None:
            logging.error('Joke was broadcast to non-existent jokebook id %d',
                          jokebook_id)
            return

        # 3. add it to jokes in the appropriate jokebook
        logging.debug(
            '%s broadcast a joke to my jokebook# %d with text: %s and answer %s',
            joke.joker, jokebook_id, joke.text, joke.answer)
        jokebook.jokes.append(joke)

        # 4. TODO - show some kind of alert - ask on #sugar
        message = str(sender_nick) + _(' accepted a joke submitted to ') + \
                  str(jokebook.title) + _(' by ') + str(joke.joker)
        Globals.JokeMachineActivity.alert(_('Joke Machine'), message)
コード例 #4
0
    def submit_cb(self, jokebook_id, joke_pickle, sender=None):
        '''Receive someones submission
    jokebook_id -- the jokebook to submit joke to
    joke_pickle -- a pickled joke'''
        if sender == self.my_bus_name:  # don't respond to own submit signal
            return
        logging.debug('In submit_cv. sender: %r' % sender)

        # 1. unpickle joke
        joke_pickle = str(joke_pickle)
        if len(joke_pickle) == 0:
            logging.debug(
                'JokeMachineSession.submit_cb() -> empty joke_pickle - doing nothing'
            )
            return
        joke = Joke.loads(joke_pickle)
        if joke is None:
            logging.error(
                'JokeMachineSession.submit_cb -> could not unpickle joke')
            return

        # 2. get the jokebook it belongs to
        jokebook = Globals.JokeMachineState.jokebook(jokebook_id)
        if jokebook is None:
            logging.error('Joke was submitted to non-existent jokebook id %d',
                          jokebook_id)
            return

        # 3. add it to submissions in the appropriate jokebook
        logging.debug(
            '%s submitted a joke to my jokebook# %d with text: %s and answer %s',
            joke.joker, jokebook_id, joke.text, joke.answer)
        jokebook.submissions.append(joke)

        # 4. alert the owner
        message = str(joke.joker) + _(' submitted a joke to ') + str(
            jokebook.title)
        Globals.JokeMachineActivity.alert(_('Joke Machine'), message)