Exemple #1
0
async def _(session: NLPSession):
    global t_global
    stripped_msg_text = session.msg_text.strip()
    if stripped_msg_text in t_global.teach_dict.keys():
        # 以置信度 100.0 返回 teach-search 命令
        return NLPResult(100.0, 'teach-search', {
            'message': stripped_msg_text,
            'image': 0
        })  #image 0 表示完全匹配
    else:
        #开始联想
        for key in t_global.teach_dict.keys():
            #判断image列表中是否全部禁止联想
            flag = True
            for image in t_global.teach_dict[key]['image']:
                if image != 0:
                    flag = False
                    break
            #是,则跳过这个key
            if flag == True:
                continue
            for char in stripped_msg_text:
                if char in key:
                    confident = check_image_match(stripped_msg_text, char, key)
                    if confident != 0:
                        #联想成功,计算置信度
                        return NLPResult(confident + 80, 'teach-search', {
                            'message': key,
                            'image': 1
                        })  #image变量表示是通过联想得到的key
        #失败
        return NLPResult(0.0, 'teach-search', {'message': session.msg_text})
Exemple #2
0
async def _(session: NLPSession):
    global nickname, e7_hero_decode
    if session.ctx.get('group_id') not in GROUP_LIST:
        return None
    res = None
    msg_box = session.msg.strip().split()
    if msg_box[0] == '添加外号':
        e7_hero_decode[msg_box[2]] = e7_hero_decode[msg_box[1]]
        res = NLPResult(100, 'add_nicname', {'message': '外号添加成功'})
        json.dump(e7_hero_decode, open(nickname, 'w'))
        return res
    elif msg_box[0] == '查看外号':
        hero_nick = e7_hero_decode[msg_box[1]]
        nickname_list = []
        for j in filter(lambda x: hero_nick == x[1], e7_hero_decode.items()):
            nickname_list.append(j[0])
        res = NLPResult(100, 'check_nicname',
                        {'message': hero_nick + ':' + ','.join(nickname_list)})
        return res
    elif msg_box[0] == '添加角色':
        heroCNname = msg_box[1]
        heroENname = msg_box[2]
        e7_hero_decode[heroCNname] = msg_box[2]
        res = NLPResult(100, 'add_name',
                        {'message': heroCNname + ':' + heroENname + '添加成功'})
        json.dump(e7_hero_decode, open(nickname, 'w'))
        return res
async def _(session: NLPSession):
    global sleep_flag
    if sleep_flag == True:
        #如果进入睡眠,100%进入睡眠模块而不是进入其他模块
        return NLPResult(100.0, 'sleep-ensurance',
                         {'message': session.msg_text})
    else:
        return NLPResult(0.0, 'sleep-ensurance', {'message': session.msg_text})
Exemple #4
0
async def _(session: NLPSession):
    stripped_msg = session.msg
    if stripped_msg.startswith('跟我说'):
        content = stripped_msg[len('跟我说'):].lstrip()
        return NLPResult(65.0, ('speak', 'to_me'), {'content': content})
    if stripped_msg.startswith('跟大家说'):
        content = stripped_msg[len('跟大家说'):].lstrip()
        return NLPResult(65.0, ('speak', 'to_all'), {'content': content})
Exemple #5
0
async def _(session: NLPSession):
    global b_global
    member_id = str(session.ctx['user_id'])
    if member_id in b_global.block_list:
        #如果被屏蔽,100%进入屏蔽模块而不是进入其他模块
        return NLPResult(100.0, 'block-ensurance', {'message': session.msg_text})
    else:
        return NLPResult(0.0, 'block-ensurance', {'message': session.msg_text})
Exemple #6
0
async def _(session: NLPSession):
    global switch
    msgtype = session.ctx["message_type"]
    if msgtype == "group" or msgtype == "discuss":
        if switch.get(str(session.ctx["group_id"]),0):
            return NLPResult(100.0,("fuduji"),{"message": session.msg})
    elif switch.get(str(session.ctx["user_id"]),0):
        return NLPResult(100.0,("fuduji"),{"message": session.msg})
    return None
Exemple #7
0
async def _(session: NLPSession):
    # 以置信度 60.0 返回 tuling 命令
    # 确保任何消息都在且仅在其它自然语言处理器无法理解的时候使用 tuling 命令
    if 'at_me' in session.ctx.keys():
        if session.ctx['at_me'] == False:
            return NLPResult(59.0, 'tuling', {'message': session.msg_text})
        else:
            return NLPResult(60.0, 'tuling', {'message': session.msg_text})
    else:
        return NLPResult(59.0, 'tuling', {'message': session.msg_text})
Exemple #8
0
async def _(session:NLPSession):
    if not session.ctx['to_me']:
        if session.ctx['message_type'] == 'group' and session.ctx['group_id'] not in get_bot().config.SELL_GROUP:
            return
    if session.msg_text.strip()[0] == '求':
        if session.msg_text.strip() == '求':
            return NLPResult(90,'want_item',)
        else:
            item_name = session.msg_text.strip()[1:]
            return NLPResult(90,'want_item',{'item_name':item_name})
async def _(session: NLPSession):
    stripped_msg_text = session.msg_text.strip()
    numbers = check_string_contain_word_num(stripped_msg_text, '哈')
    if numbers > 2 and FUNCTION_SWITCH:
        return NLPResult(80.0, 'graceful_laugh_reply', {
            'message': stripped_msg_text,
            'numbers': numbers
        })
    else:
        return NLPResult(0.0, 'graceful_laugh_reply', {
            'message': stripped_msg_text,
            'numbers': numbers
        })
Exemple #10
0
async def _(session:NLPSession):
    if not session.ctx['to_me']:
        if session.ctx['message_type'] == 'group' and session.ctx['group_id'] not in get_bot().config.SELL_GROUP:
            return
    if session.msg_text.strip()[0] != '收':
        return
    if session.msg_text.strip() == '收':
        return NLPResult(90,'find_item',{'type':'sell','key_word':None})
    elif ' ' in session.msg_text.strip():
        key_words = session.msg_text.strip().split()
        key_words.pop(0)
        return NLPResult(90, 'find_item', {'type': 'sell', 'key_word': key_words})
    else:
        key_words  = await get_item_nlp(session.msg_text)
        return NLPResult(90,'find_item', {'type': 'sell', 'key_word':key_words})
Exemple #11
0
async def _(session: NLPSession):
    if session.ctx.get('group_id') not in GROUP_LIST:
        return None
    global _last_session, _repeate_wd, repeat_box, repeat_time
    result = None
    if _last_session and \
            _last_session.ctx['user_id'] != session.ctx['user_id'] and \
            _last_session.msg == session.msg and \
            _last_session.msg != _repeate_wd and \
            len(repeat_box) == repeat_time:
        result = NLPResult(100.0, 'repeat', {'message': _last_session.msg})
        _repeate_wd = _last_session.msg
        repeat_box = []
        repeat_time = randint(1, 2)
    elif _last_session and \
            _last_session.ctx['user_id'] != session.ctx['user_id'] and \
            _last_session.msg == session.msg and \
            _last_session.msg != _repeate_wd:
        repeat_box.append(_last_session.msg)
    else:
        repeat_box = []
        _last_session = session
        repeat_time = randint(1, 2)
        repeat_box.append(_last_session.msg)
    return result
async def _(session: NLPSession):
    stripped_msg_text = session.msg_text.strip()
    return NLPResult(75.0 if FUNCTION_SWITCH else 0,
                     'graceful_reply_call_master', {
                         'message': stripped_msg_text,
                         'command': 'call_master'
                     })
Exemple #13
0
async def _(session: NLPSession):
    sp = re.split('|'.join(CALLING_KEYWORDS), session.msg_text, maxsplit=1)
    if sp:
        return NLPResult(90.0, 'music', {
            'keyword': sp[-1].strip(' 吧呗'),
            'from_nlp': True
        })
Exemple #14
0
async def _(session: NLPSession):
    text = re.sub(r'\s+', '', session.msg_text.strip())
    if not text:
        return

    confidence = 59.0

    if re.match(r'(?:怎么|咋)样\S{0,5}$', text) or \
            re.search(r'查(?:一?下|查看?)', text):
        confidence += 15.0
    if text.endswith('?') or text.endswith('?'):
        confidence += 5.0

    args = {}

    words = (await nlp.lexer(text))[0]
    for word in words:
        if word['ne'] == 'LOC':
            location = await nlp.parse_location(word['basic_words'])
            if any((location.province, location.city, location.district)):
                args['location'] = location
        elif word['ne'] == 'TIME':
            args['time'] = word['item']

    confidence += len(args) * 10.0 / 2.0 + 10.0 if args else 0.0
    return NLPResult(min(confidence, 100.0), ('weather', 'weather'), args)
Exemple #15
0
async def _(session: NLPSession):
    m = re.match(r'(?:b\s*站)?(?P<day_str>(?:前|昨|今|明|大?后)天)?(?P<name>.+?)'
                 r'(?P<day_str2>(?:前|昨|今|明|大?后)天)?[会有]?更(?:不更)?新',
                 session.msg_text, re.IGNORECASE)
    day_str, name = None, None
    if m:
        day_str = m.group('day_str') or m.group('day_str2')
        name = m.group('name')

    if not name:
        return None

    possibility = 92
    if not day_str:
        possibility -= 5
    if '吗' in session.msg_text:
        possibility += 3
    if not re.search(r'b\s*站', session.msg_text, re.IGNORECASE):
        possibility -= 10

    delta_day_dict = {'前天': -2, '昨天': -1, '今天': 0,
                      '明天': 1, '后天': 2, '大后天': 3}
    delta_day = delta_day_dict.get(day_str, 0)
    date = (datetime.now() + timedelta(days=delta_day)).strftime('%m-%d')

    return NLPResult(possibility, ('bilibili_anime', 'timeline'),
                     {'date': date, 'name': name})
Exemple #16
0
async def _(session: NLPSession):
    confidence = None  # by default we don't return result

    if session.ctx['to_me']:
        # if the user is talking to us, we may consider reply to him/her
        confidence = 60.0

    ctx_id = context_id(session.ctx)
    if ctx_id in tuling_sessions:
        ne_type = tuling_sessions[ctx_id]
        lex_result = await nlp.lexer(session.msg_text)
        # we only mind the first paragraph
        words = lex_result[0] if lex_result else []
        for w in words:
            if ne_type == w['ne']:
                # if there is a tuling session existing,
                # and the user's input is exactly what tuling wants,
                # we are sure that the user is replying tuling
                confidence = 100.0 - len(words) * 5.0
                break

    if confidence:
        return NLPResult(confidence, 'tuling', {
            'message': session.msg,
            'one_time': True
        })
Exemple #17
0
async def _(session: NLPSession):
    if check_blacklist(session.ctx.get('user_id')
                       ) or session.msg.strip()[0] == ".":
        return None
    if not check_whitelist(session.ctx.get('group_id')):
        return None
    result = NLPResult(70.0, 'DoNothing', {'message': session.msg})
    return result
Exemple #18
0
async def _(session: NLPSession):
    args = await curriculum_nlp(session.msg_text)
    #await session.send(f'''NLP DEBUG_INFO:{args['debug_info']}+  SCORE:{args['score']}''')
    if args['score']>= 0.66 or '课程表' in session.msg_text or '课表' in session.msg_text:
        args.pop('debug_info')
        args.pop('score')
        return NLPResult(90,'kcb',args)
    else:
        return None
Exemple #19
0
async def _(session: NLPSession):
    NLP_result = 50
    if '什么' in session.msg_text:
        NLP_result += 5
    if '材料' in session.msg_text:
        NLP_result += 8
    if '要什么材料' in session.msg_text or '要哪些材料' in session.msg_text:
        NLP_result += 20
    return NLPResult(NLP_result, 'calc_450_help', {})
Exemple #20
0
async def _(session: NLPSession):
    stripped_msg_text = session.msg_text.strip()
    words = posseg.lcut(stripped_msg_text)
    city = None
    # 返回处理结果,3 个参数分别为置信度、命令名、命令会话的参数
    for word in words:
        if word.flag == 'ns':
            city = word.word
    return NLPResult(90.0, 'weather', {'city': city})
async def _(session: NLPSession):
    global LAST_CONTENT
    LAST_CONTENT = session.msg_text
    stripped_msg_text = session.msg_text.strip()
    return NLPResult(
        95.0 if FUNCTION_SWITCH and session.msg_text != FUDU_CONTENT else 0,
        'graceful_praise_reply', {
            'message': stripped_msg_text,
            'command': 'praise'
        })
Exemple #22
0
async def _(session: NLPSession):
    if check_blacklist(session.ctx.get('user_id')
                       ) or session.msg.strip()[0] == ".":
        return None
    if session.ctx.get('group_id') == 【数据删除】:
        return None
    if not check_whitelist(session.ctx.get('group_id')):
        return None
    result = NLPResult(75.0, 'TheStrongOne', {'message': session.msg})
    return result
Exemple #23
0
async def _(session:NLPSession):
    if not session.ctx['to_me']:
        if session.ctx['message_type'] == 'group' and session.ctx['group_id'] not in get_bot().config.SELL_GROUP:
            return
    if session.msg_text.strip()[0] == '删':
        id = session.msg_text.strip()[1:]
        try:
            int(id)
            return NLPResult(90,'del_item',{'id':id})
        except Exception:
            pass
async def _(session: NLPSession):
    # 去掉消息首尾的空白符
    stripped_msg_text = session.msg_text.strip().replace('英雄榜', '')
    NLP_result = 64.0
    if find_string(stripped_msg_text, '?') != -1:
        NLP_result += 1
    elif find_string(stripped_msg_text, '?') != -1:
        NLP_result += 1

    stripped_msg_text = stripped_msg_text.replace('?', '')
    stripped_msg_text = stripped_msg_text.replace('?', '')

    index1 = find_string(stripped_msg_text, '查询')
    index2 = find_string(stripped_msg_text, '查')
    if index1 != -1 or index2 != -1:
        NLP_result += 12

    stripped_msg_text = stripped_msg_text.replace('查询', '')
    stripped_msg_text = stripped_msg_text.replace('查', '')

    raid = get_herolist_raid_name(stripped_msg_text)
    if raid == 'None':
        NLP_result -= 10
    else:
        stripped_msg_text = stripped_msg_text.replace(raid, '')
    server = get_herolist_server_name(stripped_msg_text)
    if server == 'None':
        NLP_result -= 10
    else:
        stripped_msg_text = stripped_msg_text.replace(server, '')

    name = ''
    if ',' in stripped_msg_text:
        msg_list = stripped_msg_text.split(',')
    elif ',' in stripped_msg_text:
        msg_list = stripped_msg_text.split(',')
    else:
        msg_list = stripped_msg_text
    for msg in msg_list:
        name_index = find_string(msg, 'id')
        if name_index != -1:
            name_index += 2
            if name_index < len(msg) - 1:
                name = msg[name_index:]
                if name[0] == '是' or name[0] == '为' or name[0] == '叫':
                    name = name[1:]
                    if name[-1] == '的':
                        name = name[:-1]
    if name == '':
        name = session.ctx['sender']['card'].split('-')[0]
    name = name.replace(' ', '')
    print(raid + ' ' + name + ' ' + server)
    return NLPResult(NLP_result, 'herolist',
                     {'nlp_result': raid + ' ' + name + ' ' + server})
Exemple #25
0
async def _(session: NLPSession):
    if check_blacklist(session.ctx.get('user_id')
                       ) or session.msg.strip()[0] == ".":
        return None
    if not check_whitelist(session.ctx.get('group_id')):
        return None
    if session.ctx.get('group_id') == 【数据删除】:
        return None
    if not check_whitelist(session.event.group_id):
        return None
    result = NLPResult(85.0, 'Zhangyuwang', {'message': session.msg})
    return result
async def _(session: NLPSession):
    global LAST_CONTENT
    global LAST_CONTENT_USER_ID
    global FUDU_CONTENT
    if session.msg_text != LAST_CONTENT or LAST_CONTENT_USER_ID == session.ctx[
            'user_id'] or session.msg_text == FUDU_CONTENT:
        confident = 0.0
        LAST_CONTENT = session.msg_text
    else:
        confident = 96.0
    LAST_CONTENT_USER_ID = session.ctx['user_id']
    return NLPResult(confident, 'graceful_fudu_reply',
                     {'message': session.msg_text})
Exemple #27
0
async def _(session: NLPSession):
    if check_blacklist(session.ctx.get('user_id')
                       ) or session.msg.strip()[0] == ".":
        return None
    group_id = session.ctx.get('group_id')
    global group_list
    global group_dict
    if group_id not in group_list:
        group_list.append(group_id)
        group_dict[group_id] = [None, None]
    global _can_break
    global _can_repeat
    result = None
    if group_dict[group_id][0] is None:
        group_dict[group_id][0] = session
        return None
    if group_dict[group_id][1] is None:
        group_dict[group_id][1] = session
        return None
    if group_dict[group_id][1] and \
            group_dict[group_id][1].msg == session.msg and \
            group_dict[group_id][1].ctx['user_id'] != session.ctx['user_id'] and \
            group_dict[group_id][1].ctx['user_id'] != group_dict[group_id][0].ctx['user_id'] and \
            group_dict[group_id][1].msg == group_dict[group_id][0].msg:
        if _can_break:
            result = NLPResult(
                100.0, '说打断', {
                    'message': group_dict[group_id][1].msg})
        if _can_repeat:
            result = NLPResult(
                100.0, '复读', {
                    'message': group_dict[group_id][1].msg})
        group_dict[group_id][1] = None
        group_dict[group_id][0] = None
    else:
        group_dict[group_id][0] = group_dict[group_id][1]
        group_dict[group_id][1] = session
    return result
Exemple #28
0
async def _(session: NLPSession):
    m = re.match(r'(?:b\s*站)?(?P<name>.+?)(?:(?:什么|啥)时候)?[会有]?更新',
                 session.msg_text, re.IGNORECASE)
    name = m.group('name') if m else None

    if not name:
        return None

    possibility = 90
    if not re.search(r'b\s*站', session.msg_text, re.IGNORECASE):
        possibility -= 10

    return NLPResult(possibility, ('bilibili_anime', 'timeline'),
                     {'name': name})
Exemple #29
0
async def _(session: NLPSession):
    if session.ctx.get('group_id') != 672076603:
        return None

    global _last_session
    result = None
    if _last_session and \
            _last_session.ctx['user_id'] != session.ctx['user_id'] and \
            _last_session.msg == session.msg:
        result = NLPResult(61.0, 'echo', {'message': _last_session.msg})
        _last_session = None
    else:
        _last_session = session
    return result
Exemple #30
0
async def _(session: NLPSession):
    global nickname
    if session.ctx.get('group_id') not in GROUP_LIST:
        return None
    res = None
    msg_box = session.msg.strip().split()
    if msg_box[0] == '添加外号':
        # 得到英雄id
        Hero_id = dbsession.query(Hero).join(Nicename).filter(
            Nicename.nicename == msg_box[1]).one().id
        # 构造插入语句
        insert = {'hero_id': Hero_id, 'nicename': msg_box[2], 'delete': 1}
        try:
            rs = savesth(insert)
            if rs:
                # e7_hero_decode[msg_box[2]] = e7_hero_decode[msg_box[1]]
                res = NLPResult(100, 'add_nicname', {'message': '外号添加成功'})
                # json.dump(e7_hero_decode, open(nickname, 'w'))
                return res
            res = NLPResult(100, 'add_nicname', {'message': '外号添加超时'})
            return res
        except:
            res = NLPResult(100, 'add_nicname', {'message': '外号添加超时'})
            return res

    if msg_box[0] == '查看外号':
        try:
            hero_obj = dbsession.query(Hero).join(Nicename).filter(
                Nicename.nicename == msg_box[1]).one()
            res = NLPResult(
                100, 'check_nicname',
                {'message': hero_obj.heroname + f':{hero_obj.nicename}'})
            return res
        except:
            res = NLPResult(100, 'check_nicname',
                            {'message': '没有这个人或者查询超时,请重试'})
            return res