示例#1
0
 def do_handle(self, request_object, request_json):
     id = uuid.uuid1()
     image = self.get_image()
     words = self.get_words()
     if image == '':
         chatbots.get(
             request_json['chatbotUserId']).send_text('正在生成中,这可能需要一些时间...')
         body = {}
         word_cloud_dict = {}
         while len(word_cloud_dict) < 200:
             response = requests.post(dark_jikipedia.browse_definitions_url,
                                      json=body,
                                      headers=dark_jikipedia.header).json()
             for data in response:
                 word_cloud_dict[data.get('term').get('title')] = data.get(
                     'view_count')
                 if len(word_cloud_dict) == 200:
                     break
             time.sleep(1)
         image = cloudMaker.make_word_cloud_to_image(word_cloud_dict)
         self.put_image(image)
         id = uuid.uuid1()
         words = self.put_words(word_cloud_dict)
     title = "小鸡骚词"
     img_url = f"http://{config.public_ip}/dark_buddy/dark_ji_word_cloud/image/get?session_id={request_json['chatbotUserId']}&uuid={id}"
     text = f"![screenshot]({img_url})\n### 小鸡骚词\n{words}"
     action_card = ActionCard(title=title,
                              text=text,
                              btns=[],
                              img_url=img_url)
     chatbots.get(
         request_json['chatbotUserId']).send_action_card(action_card)
    def display_result(self, scores):
        daily_salary = float(scores['DAILY_SALARY'])
        working_hours = float(scores['WORKING_HOURS'])
        commuting_hours = float(scores['COMMUTING_HOURS'])
        playing_hours = float(scores['PLAYING_HOURS'])

        working_area_score = WORKING_AREA_SCORE_MAP.get(scores['WORKING_AREA_SCORE'])
        study_score = STUDY_SCORE_MAP.get(scores['STUDY_SCORE'])
        sexy_area_score = SEXY_AREA_SCORE_MAP.get(scores['SEXY_AREA_SCORE'])
        guys_area_score = GUYS_AREA_SCORE_MAP.get(scores['GUYS_AREA_SCORE'])
        evil_morning_score = EVIL_MORNING_SCORE_MAP.get(scores['EVIL_MORNING_SCORE'])

        result_1 = daily_salary * working_area_score * sexy_area_score * guys_area_score * evil_morning_score
        result_2 = 35 * study_score * (working_hours + commuting_hours - 0.5 * playing_hours)
        result = result_1 / result_2
        text = '爽到爆炸'
        if result < 0.8:
            text = '很惨'
        elif result < 1.5:
            text = '一般'
        elif result < 2:
            text = '很爽'
        chatbots.get(self.chatbot_user_id).send_action_card(
            ActionCard(
                title="计算完成",
                text="### 得分:{0}\n ### 你的工作性价比:「{1}」".format(result, text),
                btns=[CardItem(
                    title="重新计算", url="**工作性价比:开启")]
            ))
示例#3
0
 def shut_down_dark_spy(self, request_json):
     redis.delete(
         self.get_dark_spy_session_name(request_json['chatbotUserId']))
     chatbots.get(request_json['chatbotUserId']).send_action_card(
         ActionCard(title="游戏结束",
                    text="### 游戏已经回归虚无......",
                    btns=[CardItem(title="再来一把", url="**游戏:谁是卧底:开启")]))
     return
示例#4
0
 def rewards(self, count, sender_id, chatbot, sender_nick):
     self.give_the_lucky_point_to(count, sender_id)
     chatbot.send_action_card(
         ActionCard(title="财富变动",
                    text='### 「{0}」{1}{2}金币!'.format(
                        sender_nick, '获得' if count > 0 else '失去',
                        abs(count)),
                    btns=[CardItem(title="查看当前金币剩余", url="**人设:显示:金币")]))
示例#5
0
 def send_message_by_response(self, matched, request_json, response_json):
     if matched == "joke":
         for i in range(0, 3):
             joke = response_json["result"][i]
             chatbots.get(request_json['chatbotUserId']).send_text(joke["content"])
     elif matched == "toutiao":
         feed_links = []
         datas = response_json.get('result').get('data')
         for i in range(0, 4):
             data = datas[i]
             feed_link = FeedLink(title=data.get('title'), message_url=data.get('url'), pic_url=data.get('thumbnail_pic_s'))
             feed_links.append(feed_link)
         chatbots.get(request_json['chatbotUserId']).send_feed_card(feed_links)
     elif matched == "weixin":
         log.info(str(response_json))
         chatbots.get(request_json['chatbotUserId']).send_text("敬请期待...")
     elif matched == "constellation":
         name = request_json["senderNick"]
         text = ""
         for i in range(len(response_json["newslist"])):
             text+=response_json["newslist"][i]["type"]
             text+=": "
             text+=response_json["newslist"][i]["content"]
             text+="\n\n"
         chatbots.get(request_json['chatbotUserId']).send_markdown(title="%s,这就是你今天的暗黑星座运势" % name, text=text)
     elif matched == "laohuangli":
         log.info(str(response_json))
         datas = response_json.get('result')
         chatbots.get(request_json['chatbotUserId']).send_markdown(title="今日黄历", text="### 宜:" + datas["yi"] + "\n" + "### 忌:" + datas["ji"])
     elif matched == "dongtu":
         log.info(str(response_json))
         datas = response_json["data"]["result"][0]
         action_card = ActionCard(title=datas["title"],
                                  text="![screenshot](" + datas["gifurl"] + ")\n" + "#### " + datas["title"],
                                  btns=[CardItem(title="查看更多", url="**小功能:动图")],
                                  img_url=datas["gifurl"])
         chatbots.get(request_json['chatbotUserId']).send_action_card(action_card)
     elif matched == "today":
         log.info(str(response_json))
         dataCollection = response_json["result"]
         data = random.choice(dataCollection)
         chatbots.get(request_json['chatbotUserId']).send_text(
             "早啊!^_^ 历史上的今天--" + data["date"] + " " + data["title"])
     elif matched == "honey":
         log.info(str(response_json))
         chatbots.get(request_json['chatbotUserId']).send_text(response_json["newslist"][0]["content"])
     elif matched == "name":
         log.info(str(response_json))
         chatbots.get(request_json['chatbotUserId']).send_text(response_json["newslist"][0]["naming"])
     elif matched == "sweet":
         log.info(str(response_json))
         chatbots.get(request_json['chatbotUserId']).send_text(response_json["newslist"][0]["content"])
     elif matched == "shit":
         log.info(str(response_json))
         chatbots.get(request_json['chatbotUserId']).send_text(response_json["newslist"][0]["content"])
     else:
         chatbots.get(request_json['chatbotUserId']).send_text("你TM说啥呢!滚犊子")
示例#6
0
 def display_mc_quiz(self, redis_data, request_json):
     btns = []
     for i, choice in enumerate(redis_data['choices']):
         btns.append(
             CardItem(title=choice, url="**游戏:暗黑答题:答题:1:{0}".format(i)))
     chatbots.get(request_json['chatbotUserId']).send_action_card(
         ActionCard(title="暗黑答题",
                    text="### 答对加20金币,答错扣5金币\n{0}".format(
                        redis_data['title']),
                    btns=btns))
def shut_down_work_shuang_rank(chatbot_user_id):
    redis.delete(get_dark_work_shuang_rank_session_name(chatbot_user_id))
    chatbots.get(chatbot_user_id).send_action_card(
        ActionCard(
            title="计算已关闭",
            text="### 计算已关闭......",
            btns=[CardItem(
                title="重新计算", url="**工作性价比:开启")]
        ))
    return
示例#8
0
def shut_down_guess_number(chatbot_user_id):
    redis.delete(get_dark_guess_number_session_name(chatbot_user_id))
    chatbots.get(chatbot_user_id).send_action_card(
        ActionCard(
            title="游戏结束",
            text="### 数字已经忘记......",
            btns=[CardItem(
                title="再来一把", url="**游戏:猜数字:开启")]
        ))
    return
示例#9
0
 def render_game(self, game_session_data, request_json):
     if game_session_data.game_status == GameStatusEnum.END:
         chatbots.get(request_json['chatbotUserId']).send_action_card(
             ActionCard(title="游戏结束",
                        text="### 游戏已经结束......",
                        btns=[CardItem(title="再来一把", url="**游戏:谁是卧底:开启")]))
     if game_session_data.game_status == GameStatusEnum.PREPARE:
         gamers = game_session_data.get_gamers()
         gamer_list = ""
         for gamer in gamers:
             gamer_list = gamer_list + gamer_icon.format(gamer.name)
         title = "暗黑卧底"
         text = '当前参与者:\t{0}\n\n{1}\n{2}'.format(gamer_list, join_icon,
                                                 start_icon)
         action_card = ActionCard(title=title, text=text, btns=[])
         chatbots.get(
             request_json['chatbotUserId']).send_action_card(action_card)
         return
     if game_session_data.game_status == GameStatusEnum.GAMING:
         gamers = game_session_data.get_gamers()
         gamer_list = ""
         for gamer in gamers:
             if gamer.status == 0:
                 gamer_list = gamer_list + vote_icon.format(
                     gamer.name,
                     game_session_data.vote_info.get(gamer.name, 0))
         gamer_list = gamer_list + vote_icon.format(
             "弃票", game_session_data.vote_info.get("弃票", 0))
         title = "暗黑卧底"
         text = '当前参与者:\t{0}\n\n{1}'.format(gamer_list, hint_icon)
         action_card = ActionCard(
             title=title,
             text=text,
             btns=[
                 CardItem(title="查看你的词",
                          url=info_icon_url.format(
                              request_json['chatbotUserId']))
             ])
         chatbots.get(
             request_json['chatbotUserId']).send_action_card(action_card)
         return
     pass
示例#10
0
 def build_all_status_property_list_action_card(self):
     all_status_property = mapper.mapper_user_status_property.select_all()
     btns = []
     if len(all_status_property) == 0:
         btn = CardItem(title='增加', url="**人设:增加")
         btns.append(btn)
         title = "你是想问?"
         text = "# 目前尚未拥有人设,请增加你的人设。"
         return ActionCard(title=title,
                           text=text,
                           btns=btns,
                           btn_orientation=1)
     for status_property in all_status_property:
         btn = CardItem(title=status_property.get('name'),
                        url="**人设:显示:{0}".format(
                            status_property.get('name')))
         btns.append(btn)
     title = "你是想问?"
     text = "# 关于你的人设, 你是想问?"
     return ActionCard(title=title, text=text, btns=btns, btn_orientation=1)
示例#11
0
 def do_handle(self, request_object, request_json):
     id = uuid.uuid1()
     image = self.get_image()
     if image == '':
         chatbots.get(request_json['chatbotUserId']).send_text('正在生成中,这可能需要一些时间...')
         image = self.get_word_cloud_image()
         self.put_image(image)
     title = "暗黑热搜"
     img_url = f"http://{config.public_ip}/dark_buddy/dark_word_cloud/image/get?session_id={request_json['chatbotUserId']}&uuid={id}"
     text = f"![screenshot]({img_url})\n# 暗黑热搜榜"
     action_card = ActionCard(title=title, text=text, btns=[])
     chatbots.get(request_json['chatbotUserId']).send_action_card(action_card)
示例#12
0
 def display_maze(self, data, message):
     redis.set(name=get_dark_maze_session_name(self.chatbot_user_id),
               value=str(data))
     title = "暗黑迷宫"
     img_url = 'http://{2}/dark_buddy/dark_maze/image/get?session_id={0}&uuid={1}'.format(
         self.chatbot_user_id, uuid.uuid1(), config.public_ip)
     text = '![screenshot]({0})\n# {1}'.format(img_url, message)
     action_card = ActionCard(title=title,
                              text=text,
                              btns=[],
                              img_url=img_url)
     chatbots.get(self.chatbot_user_id).send_action_card(action_card)
     return
示例#13
0
 def action_card_content(self, search_definition_data):
     title = search_definition_data['term']['title']
     content = search_definition_data['plaintext']
     image_url = search_definition_data.get('images')
     if len(image_url) == 0:
         text = '### {0}\n{1}\n'.format(title, content)
     else:
         text = '![screenshot]({0})\n### {1}\n{2}\n'.format(
             image_url[0]['scaled']['path'], title, content.strip())
     return ActionCard(
         title=title,
         text=text,
         btns=[CardItem(title="查看更多", url="**骚词:推荐")],
         img_url=image_url[0]['scaled']['path'] if image_url else None)
示例#14
0
 def treat_dark_quiz(self, answer, type, request_json):
     redis_data_str = redis.get(
         self.get_session_name_by_type(request_json['chatbotUserId'],
                                       int(type)))
     if redis_data_str is None:
         return
     redis_data = eval(redis_data_str)
     if redis_data['answer'] == int(answer):
         chatbots.get(request_json['chatbotUserId']).send_action_card(
             ActionCard(title="暗黑答题",
                        text="### 回答正确!6六6!",
                        btns=[
                            CardItem(title="再来一题是非题",
                                     url="**游戏:暗黑答题:是非题(10金币)"),
                            CardItem(title="再来一题单选题",
                                     url="**游戏:暗黑答题:单选题(20金币)")
                        ]))
         if type == '0':
             user_login.rewards_to_sender_id(10, request_json)
         if type == '1':
             user_login.rewards_to_sender_id(20, request_json)
     else:
         chatbots.get(request_json['chatbotUserId']).send_action_card(
             ActionCard(title="暗黑答题",
                        text="### GG!回答错误!正确答案是「{0}」,相关信息:{1}".format(
                            redis_data['answer_str'],
                            redis_data['analytic']),
                        btns=[
                            CardItem(title="再来一题是非题",
                                     url="**游戏:暗黑答题:是非题(10金币)"),
                            CardItem(title="再来一题单选题",
                                     url="**游戏:暗黑答题:单选题(20金币)")
                        ]))
         user_login.rewards_to_sender_id(-5, request_json)
     redis.delete(
         self.get_session_name_by_type(request_json['chatbotUserId'],
                                       int(type)))
示例#15
0
 def do_handle(self, request_object, request_json):
     body = {}
     response = requests.post(self.browse_definitions_url,
                              json=body,
                              headers=self.header).json()
     # log.info(json.dumps(response, indent=4))
     content = "### 骚词推荐\n"
     for data in response:
         if data.get('scaled_image') != '':
             title = data.get('term').get('title')
             content += "[{0}](dtmd://dingtalkclient/sendMessage?content={1})/".format(
                 title, quote(title))
     action_card = ActionCard(title="骚词推荐",
                              text=content[:-1],
                              btns=[CardItem(title="查看更多", url="**骚词:推荐")])
     chatbots.get(
         request_json['chatbotUserId']).send_action_card(action_card)
     return True
示例#16
0
 def do_handle(self, request_object, request_json):
     sender_id = request_json['senderId']
     sender_nick = request_json['senderNick']
     redis.setex(name=self.get_sign_in_lock_name(sender_id),
                 time=60,
                 value=sender_nick)
     btns = []
     btn = CardItem(
         title='点击注册',
         url='http://{2}/dark_buddy/web/bindid/{0}?uuid={1}'.format(
             sender_id, uuid.uuid1(), public_ip))
     btns.append(btn)
     title = "欢迎注册"
     text = "# {0}你好, 请点击下方按钮注册。".format(sender_nick)
     action_card = ActionCard(title=title,
                              text=text,
                              btns=btns,
                              btn_orientation=1)
     chatbots.get(
         request_json['chatbotUserId']).send_action_card(action_card)
示例#17
0
 def auto_complete(self, text, request_json):
     body = {"phrase": text}
     response = requests.post(self.auto_complete_url,
                              json=body,
                              headers=self.header)
     # log.info(json.dumps(response.json(), indent=4))
     auto_complete_result = response.json()['data']
     if len(auto_complete_result) > 0:
         btns = []
         for word in auto_complete_result:
             if text == word['word']:
                 return False
             title = word['word']
             btn = CardItem(title=title, url=quote(title))
             btns.append(btn)
         title = "你是想问?"
         text = "### 你是想问?"
         action_card = ActionCard(title=title, text=text, btns=btns)
         chatbots.get(
             request_json['chatbotUserId']).send_action_card(action_card)
         return True
     return False
示例#18
0
    def main_process(self):
        self.draw.ai_draw(True)
        self.draw.ai_draw(False)
        self.draw.player_draw(True)
        self.draw.player_draw(False)

        self.render_cards()

        bet_money = self.listener.ask_for_bet()
        if bet_money == 'giveup':
            self.chatbot.send_action_card(
                ActionCard(
                    title="暗黑二十一点",
                    text="### 你输了!呵呵...",
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑二十一点:来一把")]))
            return
        bet_money = int(bet_money)
        current_money = user_login.get_luck_point_by_sender_id(
            self.player_id)['value']
        if bet_money >= current_money:
            self.chatbot.send_text(
                '你梭哈了,当前的所有金币:「{0}」全部用于下注!'.format(current_money))
            bet_money = current_money
        self.push_money(bet_money)

        while Ai.predict_point(self.draw.player_cards)['status'] == 'none':
            call_command = self.listener.ask_for_call()
            if call_command == 'call':
                self.draw.player_draw(False)
                self.render_cards()
            if call_command == 'done':
                break

        self.chatbot.send_text("轮到AI的回合...")
        eventlet.sleep(1)

        while Ai.predict_point(self.draw.ai_cards)['status'] == 'none':
            call_command = Ai.calculate_decision(self.draw)
            if call_command == 'call':
                self.chatbot.send_text("AI觉得应该再来一张...")
                eventlet.sleep(1)
                self.draw.ai_draw(False)
                self.render_cards()
            if call_command == 'done':
                self.chatbot.send_text("AI觉得牌够了")
                eventlet.sleep(1)
                break

        judgement = Ai.judge(self.draw)
        self.render_cards(True)
        if judgement > 0:
            self.chatbot.send_action_card(
                ActionCard(
                    title="暗黑二十一点",
                    text="### 你赢了!「{0}」金币都是你的!".format(bet_money * 2),
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑二十一点:来一把")]))
            user_login.rewards(bet_money * 2, self.player_id, self.chatbot,
                               '玩家')
        elif judgement < 0:
            self.chatbot.send_action_card(
                ActionCard(
                    title="暗黑二十一点",
                    text="### 你输了!呵呵...",
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑二十一点:来一把")]))
        else:
            self.chatbot.send_action_card(
                ActionCard(
                    title="暗黑二十一点",
                    text="### 平局!「{0}」金币还给你...".format(bet_money),
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑二十一点:来一把")]))
            user_login.rewards(bet_money, self.player_id, self.chatbot, '玩家')
示例#19
0
 def do_handle(self, request_object, request_json):
     action_card = ActionCard(title='祖安',
                              text='# ' + self.getZuAn(),
                              btns=[CardItem(title="你再骂?!", url="**祖安")])
     chatbots.get(
         request_json['chatbotUserId']).send_action_card(action_card)
示例#20
0
 def win(self, player_id, total_money):
     self.chatbot.send_action_card(
         ActionCard(title="暗黑梭哈",
                    text="### 你赢了!「{0}」金币都是你的!".format(total_money),
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑梭哈:来一把")]))
     user_login.rewards(total_money, player_id, self.chatbot, '玩家')
示例#21
0
 def lose(self, player_id):
     self.chatbot.send_action_card(
         ActionCard(title="暗黑梭哈",
                    text="### 你输了!呵呵...",
                    btns=[CardItem(title="再来一把", url="**游戏:暗黑梭哈:来一把")]))