Ejemplo n.º 1
0
 def handle_sticker_message(self, receive):
     """
     Sticker message handler.
     :param receive:
     :return:
     """
     mid = receive['from_mid']
     self.logger.info('New sticker message.[From] %s' % mid)
     content = receive['content']
     lang = self.check_fromuser_language(mid)
     stkgid = content.attrs['stkpkgid']
     if not self.dao.is_edison_enable():
         self.send_take_photo_disable(mid)
         return
     if stkgid != '2':
         result = modules.random_get_result(self.dao.get_nlp_response(model.NLPActions.Edison_not_match, lang))
     else:
         photo_count = self.dao.get_num_of_photo(mid)
         if photo_count >= utils.PHOTO_LIMIT:
             # over limit
             resp = modules.random_get_result(
                 self.dao.get_command_responses('/edisonoverlimit', self.check_fromuser_language(mid),
                                                self.check_fromuser_humour(mid)))
             command_resp = model.CommandResponse.de_json(resp)
             self.bot_api.send_text(to_mid=mid, text=command_resp.response_msg)
             return
         self.edison_queue.put(mid)
         self.dao.increase_num_of_photo(mid)
         result = modules.random_get_result(self.dao.get_nlp_response(model.NLPActions.Edison_request, lang))
     self.bot_api.reply_text(receive, result)
Ejemplo n.º 2
0
 def test_get_command_response(self):
     cmd1 = model.Command('zh_TW', 'help', [model.CommandResponse(['No', 'No2'], 'hi'),
                                            model.CommandResponse(['No3', 'No4'], 'Hello')])
     cmd2 = model.Command('zh_TW', 'hello', [model.CommandResponse(['Yes', 'Yes2'], 'Hello'),
                                             model.CommandResponse(['Yes3', 'Yes4'], 'Wrold')])
     get_dao().add_commands([cmd1, cmd2])
     result = modules.random_get_result(get_dao().get_command_responses('help', 'zh_TW'))
     cr = model.CommandResponse.de_json(result)
     assert 'hi' == cr.response_msg or 'Hello' == cr.response_msg
Ejemplo n.º 3
0
 def send_take_photo_count(self, mid):
     for i in range(0, self.take_photo_sec):
         self.bot_api.send_text(to_mid=mid, text=str(self.take_photo_sec - i))
         time.sleep(1)
     resp = modules.random_get_result(
         self.dao.get_command_responses('/edisontakephoto', self.check_fromuser_language(mid),
                                        self.check_fromuser_humour(mid)))
     command_resp = model.CommandResponse.de_json(resp)
     self.bot_api.send_text(to_mid=mid, text=command_resp.response_msg)
Ejemplo n.º 4
0
 def handle_sticker_message(self, receive):
     """
     Sticker message handler.
     :param receive:
     :return:
     """
     mid = receive['from_mid']
     self.logger.info('New sticker message.[From] %s' % mid)
     self.edison_queue.put(mid)
     lang = self.check_fromuser_language(mid)
     result = modules.random_get_result(self.dao.get_nlp_response(model.NLPActions.Edison_request, lang))
     self.bot_api.reply_text(receive, result)
Ejemplo n.º 5
0
 def test_get_command_response(self):
     cmd1 = model.Command('zh_TW', 'help', [
         model.CommandResponse(['No', 'No2'], 'hi'),
         model.CommandResponse(['No3', 'No4'], 'Hello')
     ])
     cmd2 = model.Command('zh_TW', 'hello', [
         model.CommandResponse(['Yes', 'Yes2'], 'Hello'),
         model.CommandResponse(['Yes3', 'Yes4'], 'Wrold')
     ])
     get_dao().add_commands([cmd1, cmd2])
     result = modules.random_get_result(get_dao().get_command_responses(
         'help', 'zh_TW'))
     cr = model.CommandResponse.de_json(result)
     assert 'hi' == cr.response_msg or 'Hello' == cr.response_msg
Ejemplo n.º 6
0
 def get_edison_request(self):
     """
     Get mid from take photo request queue.
     :return: None or mid
     """
     self.logger.info('Edison try get mid from queue.')
     result = self.edison_queue.get(timeout=10)
     if result:
         mid = result.decode('utf-8')
         self.logger.info('Edison get mid %s .' % mid)
         photo_count = self.dao.get_num_of_photo(mid)
         self.logger.info('User %s already take %d photo.' % (mid, photo_count))
         if photo_count >= utils.PHOTO_LIMIT:
             # over limit
             resp = modules.random_get_result(
                 self.dao.get_command_responses('/edisonoverlimit', self.check_fromuser_language(mid),
                                                self.check_fromuser_humour(mid)))
             command_resp = model.CommandResponse.de_json(resp)
             self.bot_api.send_text(to_mid=mid, text=command_resp.response_msg)
             return None
         self.task_pool.submit(self.send_take_photo_count, mid)
         return {'mid': mid, 'count': photo_count + 1}
     return None
Ejemplo n.º 7
0
 def send_take_photo_disable(self, mid):
     resp = modules.random_get_result(
         self.dao.get_command_responses('/edisondisable', self.check_fromuser_language(mid),
                                        self.check_fromuser_humour(mid)))
     command_resp = model.CommandResponse.de_json(resp)
     self.bot_api.send_text(to_mid=mid, text=command_resp.response_msg)