def detailed_mode(self, times, ten_times=False): operators = self.start_gacha(times) result = '阿米娅给博士扔来了%d张简历,博士细细地检阅着...\n\n【%s】\n\n' % (times, self.pick_up_name) operators_data = database.operator.get_all_operator( [item['name'] for item in operators]) operator_avatars = { item['operator_name']: item['operator_avatar'] for item in operators_data } icons = [] for index, item in enumerate(operators): star = '☆' if item['rarity'] < 5 else '★' result += '%s%s%s\n\n' % (' ' * 15, insert_empty(item['name'], 6, True), star * item['rarity']) if item['name'] in operator_avatars: avatar_path = '%s/%s.png' % (avatar_resource, operator_avatars[item['name']]) if os.path.exists(avatar_path): icons.append({ 'path': avatar_path, 'size': (34, 34), 'pos': (10, 60 + 34 * index) }) result += '\n%s' % self.check_break_even() reply = [TextImage(result, icons)] if ten_times: operators_info = { item['operator_name']: { 'photo': item['operator_avatar'], 'rarity': item['operator_rarity'], 'class': class_index[item['operator_class']].lower() } for item in operators_data } result_list = [] for item in operators: name = item['name'] op_dt = None if name in operators_info: op_dt = operators_info[name] elif name in self.temp_operator: op_dt = self.temp_operator[name] result_list.append(op_dt) res_img = '%s/%s' % (gacha_result, create_gacha_result(result_list)) reply.insert(0, Image(res_img)) return reply
def face_image(data): message = data['text'].strip() only_at = message == '' and data['is_at'] path = None if re.search('好耶', message): path = face_dir + 'haoye.jpg' elif (only_at or eliminate_name(message)) and images: path = face_dir + random.choice(images) if path: return Reply(Image(path), at=False)
def requests_content(self, only_id=False, index=0): session = requests.session() cards = self.get_cards_list() if index >= len(cards): return Reply('博士,只能获取到列表内的微博哦') target_blog = cards[index] blog = target_blog['mblog'] detail_url = target_blog['scheme'] item_id = target_blog['itemid'] if only_id: return item_id # 获取完整正文 url = 'https://m.weibo.cn/statuses/extend?id=%s' % blog['id'] result = session.get(url, headers=self.headers).json() html_text = result['data']['longTextContent'] html_text = re.sub('<br />', '\n', html_text) html_text = remove_xml_tag(html_text) html_text = html_text.strip('\n') # 获取静态图片列表 pics_list = [] pics = blog['pics'] if 'pics' in blog else [] for pic in pics: pic_url = pic['large']['url'] name = pic_url.split('/')[-1] suffix = name.split('.')[-1] if suffix.lower() == 'gif': continue temp = 'resource/message/Blog' path = '%s/%s' % (temp, name) if os.path.exists(path) is False: if os.path.exists(temp) is False: os.mkdir(temp) stream = requests.get(pic_url, headers=self.headers, stream=True) if stream.status_code == 200: open(path, 'wb').write(stream.content) pics_list.append(Image(path)) return [ Reply(html_text), Reply(detail_url, 0, at=False, auto_image=False), Reply(pics_list, 0, at=False) ]
def find_skin(skin_name): skin = database.operator.find_operator_skin(skin_name) if skin: opt = database.operator.get_operator_by_id(skin['operator_id']) text = '博士,为您找到干员%s的皮肤档案:\n\n【%s - %s】\n\n' % ( opt['operator_name'], skin['skin_group'], skin['skin_name']) text += skin['skin_source'] + '\n\n' text += skin['skin_usage'] + '\n' text += skin['skin_content'] + '\n\n' text += ' -- ' + skin['skin_desc'] reply = [Reply(text)] pic = 'resource/images/picture/%s.png' % skin['skin_image'] if os.path.exists(pic): reply.append(Reply(Image(pic), at=False)) else: reply.append(Reply('暂时无法获取到立绘图片~', at=False)) return reply