def group_admin(data): permission = data['permission'] group_id = data['group_id'] user_id = data['user_id'] message = data['text'] if permission in ['OWNER', 'ADMINISTRATOR'] or user_id == admin_id: if word_in_sentence(message, ['休息', '下班']): res = database.group.get_status(group_id) if not res or res['active'] == 1: database.group.set_status(group_id, 0, int(time.time())) return Reply('阿米娅打卡下班啦,博士需要阿米娅的时候再让阿米娅工作吧。^_^') if word_in_sentence(message, ['工作', '上班']): res = database.group.get_status(group_id) if res and res['active'] == 0: seconds = int(time.time()) - int(res['sleep_time']) total = calc_time_total(seconds) text = '打卡上班啦~阿米娅%s休息了%s……' % ('才' if seconds < 600 else '一共', total) if seconds < 600: text += '\n博士真是太过分了!哼~ >.<' else: text += '\n充足的休息才能更好的工作,博士,不要忘记休息哦 ^_^' database.group.set_status(group_id, 1, 0) return Reply(text) else: return Reply('阿米娅没有偷懒哦博士,请您也不要偷懒~')
def group_admin(data): permission = data['permission'] group_id = data['group_id'] user_id = data['user_id'] message = data['text_digits'] if permission in ['OWNER', 'ADMINISTRATOR'] or user_id == admin_id: if word_in_sentence(message, ['休息', '下班']): res = database.group.get_status(group_id) if not res or res['active'] == 1: database.group.set_status(group_id, 0, int(time.time())) return Reply('阿米娅打卡下班啦,博士需要阿米娅的时候再让阿米娅工作吧。^_^') if word_in_sentence(message, ['工作', '上班']): res = database.group.get_status(group_id) if res and res['active'] == 0: seconds = int(time.time()) - int(res['sleep_time']) total = calc_time_total(seconds) text = '打卡上班啦~阿米娅%s休息了%s……' % ('才' if seconds < 600 else '一共', total) if seconds < 600: text += '\n博士真是太过分了!哼~ >.<' else: text += '\n充足的休息才能更好的工作,博士,不要忘记休息哦 ^_^' database.group.set_status(group_id, 1, 0) return Reply(text) else: return Reply('阿米娅没有偷懒哦博士,请您也不要偷懒~') if '功能' in message: status = 0 if word_in_sentence(message, ['关闭', '禁用']): status = 1 if word_in_sentence(message, ['打开', '开启']): status = 2 if status: for item in Function.index_reg: r = re.search(re.compile(item), message) if r: index = int(r.group(1)) if 0 < index <= len(Function.function_list): index -= 1 func = Function.function_list[index] if func['id']: group = Function.function_groups[func['id']] database.function.set_disable_function( group_id, func['id'], status == 1) text = '已在本群%s以下功能:\n\n' % ('关闭' if status == 1 else '打开') text += '\n'.join([(' -- ' + n) for n in group]) return Reply(text, auto_image=False) else: return Reply('【%s】功能不可操作' % func['title'])
def action(self, data): user_id = data['user_id'] message = data['text_digits'] message_ori = data['text'] gacha = GaCha(user_id) for item in re_list: r = re.search(re.compile(item), message) if r: times = int(find_once(r'\d+', find_once(item, message))) if times <= 0: return Reply('博士在捉弄阿米娅吗 >.<') if times > 300: return Reply( '博士不要着急,罗德岛的资源要好好规划使用哦,先试试 300 次以内的寻访吧 (#^.^#)') user = database.user.get_user(user_id) coupon = user['coupon'] if user else 0 if times > coupon: return Reply('博士,您的寻访凭证(%d张)不够哦~' % coupon) if times <= 10: res = gacha.detailed_mode(times, ten_times=times == 10) else: res = gacha.continuous_mode(times) return Reply(res) if '保底' in message: return Reply(gacha.check_break_even()) if word_in_sentence(message, ['多少', '几']): user = database.user.get_user(user_id) coupon = user['coupon'] if user else 0 text = '博士的寻访凭证还剩余 %d 张~' % coupon if coupon: text += '\n博士,快去获得您想要的干员吧 ☆_☆' return Reply(TextImage(text)) if word_in_sentence(message_ori, ['切换', '更换']): r = re.search(r'(\d+)', message_ori) if r: idx = int(r.group(1)) - 1 if 0 <= idx < len(self.all_pools): message_ori = self.all_pools[idx]['pool_name'] return self.change_pool(user_id, message_ori) if word_in_sentence(message, ['查看', '卡池', '列表']): return self.pool_list() if word_in_sentence(message, ['抽', '寻访']): return Reply('博士是想抽卡吗?和阿米娅说「阿米娅抽卡 N 次」或「阿米娅 N 连抽」就可以了')
def emotion(data): message = data['text'] user_id = data['user_id'] mood = get_mood(user_id) if check_sentence_by_re(message, keyword['badWords'], amiya_name[0]): if mood - 5 <= 0: return Reply('(阿米娅没有应答...似乎已经生气了...)', -5, at=False) anger = int((1 - (mood - 5) / 15) * 100) return Reply( '博士为什么要说这种话,阿米娅要生气了![face67]({anger}%)'.format(anger=anger), -5) if check_sentence_by_re(message, keyword['goodWords'], amiya_name[0]): if mood < 0: if mood + 5 < 0: text = '哼!不要以为这样阿米娅就会轻易原谅博士...[face103]' else: text = '阿米娅这次就原谅博士吧,博士要好好对阿米娅哦[face21]' return Reply(text, 5) else: if word_in_sentence(message, ['我错了', '对不起', '抱歉']): if mood >= 15: return Reply('博士为什么要这么说呢,嗯……博士是不是偷偷做了对不起阿米娅的事[face181]', 5) else: return Reply('好吧,阿米娅就当博士刚刚是在开玩笑吧,博士要好好对阿米娅哦[face21]', 5) return Reply(random.choice(random.choice(talk_words)), 5, auto_image=False) if mood < 0: return Reply('哼~阿米娅生气了!不理博士![face38]', 1)
def action(self, data): for index, item in enumerate(self.functions): if word_in_sentence(data['text'], item.keyword): result = item.action(data) if result: database.function.add_function_use_num(item.function_id) return result
def eliminate_name(message): if word_in_sentence(message, amiya_name[0]): for name in amiya_name[0]: message = message.replace(name, '') message = re.sub(r'\W', '', message).strip() if message == '': return True return False
def action(self, data): if word_in_sentence(data['text_digits'], ['关闭清单', '关闭列表']): text = self.disable_func(data) else: text = self.func_list(data) if isinstance(text, Reply): return text return Reply(TextImage(text))
def action(self, data): disable = database.function.get_disable_function(data['group_id']) for index, item in enumerate(self.functions): # 过滤禁用的功能 if item.function_id in disable: continue if word_in_sentence(data['text'], item.keyword): result = item.action(data) if result: database.function.add_function_use_num(item.function_id) return result
def greeting(data): message = data['text'] nickname = data['nickname'] for item in ['不能休息', '不能停', '不要休息', '不要停', '很多事情']: if item in message: pass for item in ['早上好', '早安', '中午好', '午安', '下午好', '晚上好']: if item in message: hour = talk_time() text = '' if hour: text += 'Dr.%s,%s好~' % (nickname, hour) else: text += 'Dr.%s,这么晚还不睡吗?要注意休息哦~' % nickname status = sign_in(data) if status['status']: text += '\n' + status['text'] feeling = reward if status['status'] else 2 coupon = reward if status['status'] else 0 sign = 1 if status['status'] else 0 return Reply(text, feeling, sign=sign, coupon=coupon) if '签到' in message and word_in_sentence(message, amiya_name[0]): status = sign_in(data, 1) if status: feeling = reward if status['status'] else 2 coupon = reward if status['status'] else 0 sign = 1 if status['status'] else 0 return Reply(status['text'], feeling, sign=sign, coupon=coupon) if '晚安' in message: return Reply('Dr.%s,晚安~' % nickname) for name in amiya_name[1]: if message.find(name) == 0: return Reply('哼!Dr.%s不许叫人家%s,不然人家要生气了!' % (nickname, name), -3)
def action(self, data): message = data['text_digits'] message_ori = remove_punctuation(data['text']) words = jieba.lcut_for_search( (message.lower() + message_ori.lower()).replace(' ', '')) name = '' level = 0 skill = '' voice_key = '' skill_index = 0 stories_key = '' for item in words: # 获取档案关键词 if item in self.stories_title: stories_key = item continue # 获取语音关键词 if item in voices: voice_key = item continue # 获取干员名 if item in material_costs.operator_map: name = material_costs.operator_map[item] continue if item in material_costs.operator_list: name = item continue # 获取专精或精英等级 if item in material_costs.level_list: level = material_costs.level_list[item] continue # 获取技能序号 if item in material_costs.skill_index_list: skill_index = material_costs.skill_index_list[item] continue # 获取技能名 if item in material_costs.skill_map: skill = material_costs.skill_map[item] continue if name == '' and skill == '': return Reply('博士,想查询哪位干员的资料呢?') if level != 0: if level < 0: # todo 精英化资料 level = abs(level) result = material_costs.check_evolve_costs(name, level) else: if level >= 8 and '材料' in message: # todo 专精资料 level -= 7 result = material_costs.check_mastery_costs( name, skill, level, skill_index=skill_index) else: # todo 技能数据 result = operator.get_skill_data(name, skill, level, skill_index=skill_index) return Reply(result) if name: # todo 档案资料 if stories_key: story = database.operator.find_operator_stories( name, stories_key) if story: text = '博士,这是干员%s的《%s》档案\n\n' % (name, stories_key) return Reply(text + story['story_text']) else: return Reply('博士,没有找到干员%s的《%s》档案' % (name, stories_key)) # todo 语音资料 if voice_key: return self.find_voice(name, voice_key) if word_in_sentence(message, ['精英', '专精']): return Reply('博士,要告诉阿米娅精英或专精等级哦') if word_in_sentence(message, ['语音']): return Reply('博士,要告诉阿米娅语音的详细标题哦') if skill or skill_index: return Reply('博士,要查询干员技能资料的话,请加上【技能等级】或者加上【技能等级和“材料”关键字】哦') return Reply(operator.get_detail_info(name))
def action(self, data): message = data['text_digits'] message_ori = remove_punctuation(data['text']) words = jieba.lcut( message.lower().replace(' ', '') ) words += jieba.lcut( message_ori.lower().replace(' ', '') ) words = sorted(words, reverse=True, key=lambda i: len(i)) info = { 'name': '', 'level': 0, 'skill': '', 'voice_key': '', 'skill_index': 0, 'stories_key': '' } info_source = { 'name': [material_costs.operator_map, material_costs.operator_list], 'level': [material_costs.level_list], 'skill': [material_costs.skill_map], 'skill_index': [material_costs.skill_index_list], 'voice_key': [voices], 'stories_key': [self.stories_title] } info_key = list(info.keys()) for item in words: try: # 遍历 info_key 在资源 info_source 里逐个寻找关键词 for name in copy.deepcopy(info_key): for source in info_source[name]: # info_source 有两种类型(列表或字典) if item in source: if type(source) is dict: info[name] = source[item] if type(source) is list: info[name] = item # 找到关键词后删除这个 key,后续不再匹配这个 key 的内容 info_key.remove(name) raise LoopBreak(name=name, value=info[name]) except LoopBreak as value: # print(value) continue if info['name'] == '' and info['skill'] == '': return Reply('博士,想查询哪位干员的资料呢?') if info['level'] != 0: if info['level'] < 0: # todo 精英化资料 info['level'] = abs(info['level']) result = material_costs.check_evolve_costs(info['name'], info['level']) else: if info['level'] >= 8 and '材料' in message: # todo 专精资料 info['level'] -= 7 result = material_costs.check_mastery_costs(info['name'], info['skill'], info['level'], skill_index=info['skill_index']) else: # todo 技能数据 result = operator.get_skill_data(info['name'], info['skill'], info['level'], skill_index=info['skill_index']) return Reply(result) if info['name']: # todo 档案资料 if info['stories_key']: story = database.operator.find_operator_stories(info['name'], info['stories_key']) if story: text = '博士,这是干员%s的《%s》档案\n\n' % (info['name'], info['stories_key']) return Reply(text + story['story_text']) else: return Reply('博士,没有找到干员%s的《%s》档案' % (info['name'], info['stories_key'])) # todo 语音资料 if info['voice_key']: return self.find_voice(info['name'], info['voice_key']) if word_in_sentence(message, ['精英', '专精']): return Reply('博士,要告诉阿米娅精英或专精等级哦') if word_in_sentence(message, ['语音']): return Reply('博士,要告诉阿米娅语音的详细标题哦') if info['skill'] or info['skill_index']: return Reply('博士,要查询干员技能资料的话,请加上【技能等级】或者加上【技能等级和“材料”关键字】哦') return Reply(operator.get_detail_info(info['name']))
def action(self, data): message = data['text_digits'] message_ori = data['text'] words = posseg.lcut(message) + posseg.lcut(message_ori) name = '' level = 0 surplus = '' voice_key = '' skill_index = 0 for item in words: # 获取语音关键词 if voice_key == '' and item.word in voices: voice_key = item.word break for item in words: # 获取干员名 if name == '' and item.word in material.operator_list: name = item.word continue # 获取专精或精英等级 if level == 0 and item.word in material.level_list: level = material.level_list[item.word] continue # 获取技能序号 if skill_index == 0 and item.word in material.skill_index_list: skill_index = material.skill_index_list[item.word] continue surplus += item.word skill = find_similar_string(surplus, material.skill_list) if name == '' and skill == '': return Reply('博士,想查询哪位干员或技能的资料呢?请再说一次吧') if level != 0: if level <= 2: # todo 精英化资料 result = material.check_evolve_costs(name, level) else: # todo 专精资料 level -= 2 result = material.check_mastery_costs(name, skill, level, skill_index=skill_index) return Reply(result) if name: # todo 语音资料 if voice_key: return self.find_voice(name, voice_key) if word_in_sentence(message, ['精英', '专精']): return Reply('博士,要告诉阿米娅精英或专精等级哦') if word_in_sentence(message, ['语音']): return Reply('博士,要告诉阿米娅语音的详细标题哦') return Reply('博士,想查询干员%s的什么资料呢' % name)
def action(self, data): message = data['text_digits'] message_ori = remove_punctuation(data['text']) words = jieba.lcut(message.lower().replace(' ', '')) words += jieba.lcut(message_ori.lower().replace(' ', '')) words = sorted(words, reverse=True, key=lambda i: len(i)) operator_id = None info = { 'name': '', 'level': 0, 'skill': '', 'skin_key': '', 'voice_key': '', 'skill_index': 0, 'stories_key': '' } info_source = { 'name': [material_costs.operator_map, material_costs.operator_list], 'level': [material_costs.level_list], 'skill': [material_costs.skill_map], 'skill_index': [material_costs.skill_index_list], 'skin_key': [operator.skins_keywords], 'voice_key': [InitData.voices], 'stories_key': [self.stories_title] } info_key = list(info.keys()) for item in words: try: # 遍历 info_key 在资源 info_source 里逐个寻找关键词 for name in copy.deepcopy(info_key): for source in info_source[name]: # info_source 有两种类型(列表或字典) if item in source: if type(source) is dict: info[name] = source[item] if type(source) is list: info[name] = item if name == 'name': operator_id = database.operator.get_operator_id( operator_name=info[name]) # 找到关键词后删除这个 key,后续不再匹配这个 key 的内容 info_key.remove(name) raise LoopBreak(name=name, value=info[name]) except LoopBreak as value: # print(value) continue # todo 皮肤资料 if info['skin_key']: return self.find_skin(info['skin_key']) if info['name'] == '' and info['skill'] == '': return Reply('博士,想查询哪位干员的资料呢?') if info['level'] != 0: if info['level'] < 0: # todo 精英化资料 info['level'] = abs(info['level']) result = material_costs.check_evolve_costs( info['name'], info['level']) else: if info['level'] >= 8 and '材料' in message: # todo 专精资料 info['level'] -= 7 result = material_costs.check_mastery_costs( info['name'], info['skill'], info['level'], skill_index=info['skill_index']) else: # todo 技能数据 result = operator.get_skill_data( info['name'], info['skill'], info['level'], skill_index=info['skill_index']) return Reply(result) if info['name']: # todo 档案资料 if info['stories_key']: story = database.operator.find_operator_stories( info['name'], info['stories_key']) if story: text = '博士,这是干员%s的《%s》档案\n\n' % (info['name'], info['stories_key']) return Reply(text + story['story_text']) else: return Reply('博士,没有找到干员%s的《%s》档案' % (info['name'], info['stories_key'])) # todo 语音资料 if info['voice_key']: return self.find_voice(info['name'], info['voice_key']) # todo 皮肤列表 if word_in_sentence(message, ['皮肤', '服装']): if operator_id not in operator.skins_table: amiya_id = database.operator.get_operator_id( operator_name='阿米娅') no_skin = '博士,干员%s暂时还没有皮肤哦~(兔兔都有%d个皮肤了 ^.^)' % ( info['name'], len(operator.skins_table[amiya_id])) return Reply(no_skin) skin_list = operator.skins_table[operator_id] r = re.search(re.compile(r'第(\d+)个皮肤'), message) if r: index = abs(int(r.group(1))) - 1 if index >= len(skin_list): index = len(skin_list) - 1 return self.find_skin(skin_list[index]['skin_name']) else: text = '博士,为您找到干员%s的皮肤列表\n\n' % info['name'] for index, item in enumerate(skin_list): idx = ('' if index + 1 >= 10 else '0') + str(index + 1) text += '%s [ %s - %s ] %s\n' % ( idx, item['skin_group'], item['skin_name'], item['skin_usage']) text += '\n请和阿米娅说「阿米娅查看%s第 N 个皮肤」查看详情吧' % info['name'] return Reply(text) if word_in_sentence(message, ['精英', '专精']): return Reply('博士,要告诉阿米娅精英或专精等级哦') if word_in_sentence(message, ['语音']): return Reply('博士,要告诉阿米娅语音的详细标题哦') if info['skill'] or info['skill_index']: return Reply('博士,要查询干员技能资料的话,请加上【技能等级】或者加上【技能等级和“材料”关键字】哦') return Reply(operator.get_detail_info(info['name']))