Esempio n. 1
0
async def add_job(session: CommandSession):
    global saved_jobs
    global running_jobs
    stripped_arg = session.current_arg_text.strip()
    id = str(time.time())
    if session.is_first_run and stripped_arg:
        id = stripped_arg
    gid = session.event['group_id']
    hour: str = session.get('hour', prompt='您想几点运行,多个时间用逗号隔开')
    minute: str = session.get('minute', prompt='您想几分运行,多个时间用逗号隔开')
    msg: str = session.get('msg', prompt='请输入要发送的内容')
    saved_jobs[id] = {
        'groups': [gid],
        'hour': hour,
        'minute': minute,
        'msg': msg
    }
    try:
        job = add_cron_job(send_group_msg,
                           id=id,
                           hour=hour,
                           minute=minute,
                           args=[gid, msg])
        running_jobs.append(job)
        save_config(saved_jobs, job_path)
        await bot.send(session.event,
                       f'好的,我记住了,将在每天{hour}点{minute}分发送{msg}',
                       at_sender=True)
    except Exception as ex:
        sv.logger.error(f'添加定时任务时出现异常{ex}')
        await session.finish('参数错误,请重新设置')
Esempio n. 2
0
async def _(session: CommandSession):
    stripped_arg = session.current_arg_text.strip()
    if session.is_first_run:
        if stripped_arg:
            session.state['keyword'] = stripped_arg
        return
    if not stripped_arg:
        session.pause('要翻译的内容不能为空呢,请重新输入')
    session.state[session.current_key] = stripped_arg
Esempio n. 3
0
def get_dummy_group_message_session(group_id: int,
                                    sender_role: str = None,
                                    sender_id: int = None,
                                    message_text: str = '') -> CommandSession:
    command = ''
    args = ''
    if message_text:
        command_args = message_text.split(' ', 1)
        command = command_args[0][1:]
        if len(command_args) > 1:
            args = command_args[1]
    event = CQEvent()
    event['post_type'] = 'message'
    event['message_type'] = 'group'
    event['group_id'] = group_id
    event['user_id'] = sender_id
    event['sender'] = {'role': sender_role}

    return CommandSession(nonebot.NoneBot(),
                          event,
                          Command(name=(command, ),
                                  func=lambda x: x,
                                  only_to_me=False,
                                  privileged=False,
                                  perm_checker_func=lambda x: x,
                                  session_class=CommandSession),
                          current_arg=args)
Esempio n. 4
0
async def Mars(session:CommandSession):
    #args = session.current_arg_text.strip(' ',1)
    #if not args[0]:
    keyword = session.get('keyword', prompt='你想翻译什么内容呢?')
    #else:
    #    keyword = args[0]
    Marsstr = await get_Mars(keyword)
    await session.send(Marsstr, at_sender=True)
Esempio n. 5
0
async def dream(session: CommandSession):
    args = session.current_arg_text.strip(' ', 1)
    if not args[0]:
        keyword = session.get('keyword', prompt='昨晚梦到了什么呢?')
    else:
        keyword = args[0]
    analyse = await get_dsp(keyword)
    await session.send(analyse, at_sender=True)
Esempio n. 6
0
async def _(session: CommandSession):
    args = session.current_arg_text.strip().split(' ', 1)
    if not args[0]:
        ret = session.get(key='ret', prompt='请问要搜索什么内容呢?(返回内容为百度百科)', at_sender=True)
    else :
        ret = args[0]
    ans = get_baike(ret)
    await session.send(ans,at_sender=True)
Esempio n. 7
0
async def music(session: CommandSession):
    #args = session.current_arg_text.strip(' ',1)
    #if not args[0]:
    keyword = session.get('keyword',
                          prompt='你想听什么歌呢?',
                          arg_filters=[
                              extractors.extract_text, str.strip,
                              validators.not_empty('歌名不能为空哦,请重新发送')
                          ])
    #else:
    #    keyword = args[0]
    song_id = await search_song_id(keyword)
    if song_id is None:
        await session.send('没有找到这首歌呢', at_sender=True)
    else:
        await session.send(MessageSegment.music('qq', song_id), at_sender=True)
Esempio n. 8
0
async def weather(session: CommandSession):
    city = session.get('city', prompt='你想查询哪个城市的天气呢?')
    weather_report = await get_weather(city)
    await session.send(weather_report, at_sender=True)
Esempio n. 9
0
async def _(session: CommandSession):
    city = session.get('city', prompt='输入您所在城市')
    keyword = session.get('keyword', prompt='输入您要查询的具体位置')
    location = get_location(keyword, city)
    reps = MessageSegment.location(location['lat'], location['lng'])
    await session.send(reps)
Esempio n. 10
0
async def translate(session: CommandSession):
    subject = await session.aget(
        'subject',
        prompt='你想啥样的类型?',
        arg_filters=[
            extractors.extract_text,  # 取纯文本部分
            controllers.handle_cancellation(session),  # 处理用户可能的取消指令
            str.strip  # 去掉两边空白字符
        ])
    if subject == "数学":
        await session.finish("数学题目属于图片,暂时发不出来")
    elif subject not in ["语文", "数学", "计算机", "英语", "政治"]:
        await session.finish("不支持你所输入的科目,仅支持语文,数学,计算机,英语,政治")
        question = {}

    while True:
        try:
            question = await random_question(subject)
            while question == {}:
                question = await random_question(subject)
            print(question)
            print(question == {})
            types = question.get("type")
            # 随机题库
            anwser = "随机的题库为:《{}》\n{}\n \n".format(question.get("title"),
                                                   question.get("question"))
            gets = question.get("choose")

            if (types != 3):
                if (type(gets).__name__ == "list"):
                    if (len(gets)) != 0:
                        inx = 0
                        for choose in gets:
                            anwser = anwser + tran_numer_to_char(
                                inx) + ":" + choose + "\n"
                            inx = inx + 1
                else:
                    anwser = anwser + gets + "\n"

            await session.send(anwser)
            isFigth = False
            rigth_number = 0

            # 正确与错误判断逻辑
            if (types == 1):
                # 单选题逻辑
                user_anwser = await session.aget(
                    'ansser',
                    prompt='这是一道选择题,请输入你的答案 ',
                    arg_filters=[
                        extractors.extract_text,  # 取纯文本部分
                        controllers.handle_cancellation(
                            session),  # 处理用户可能的取消指令
                        str.strip,  # 去掉两边空白字符
                        validators.match_regex(r'^[a,b,c,d,A,B,C,D]$',
                                               '请输入a b c d'),
                    ])
                print(user_anwser)
                upper = str.upper(user_anwser)
                number_inx = int(question.get("question_standard_answer"))
                number = tran_numer_to_char(number_inx)
                print("答案是{}".format(number))
                if (upper == number):
                    isFigth = True
                else:
                    rigth_number = number
                # await session.send("这是一道选择题,请输入前面的索引 如1,2,3,4")
            elif (types == 2):
                print("多选")
                # 多选题逻辑
                user_anwsers = await session.aget(
                    'ansser',
                    prompt='这是一道多选题,请输入你的答案,以空格分割。 ',
                    arg_filters=[
                        extractors.extract_text,  # 取纯文本部分
                        controllers.handle_cancellation(
                            session),  # 处理用户可能的取消指令
                        str.strip,  # 去掉两边空白字符
                    ])
                tran_user_anwser = []
                # 正确答案转换为abc
                tran_str_answser = []
                str_anwsers = str.split(
                    replace_to_arry(question.get("question_standard_answer")),
                    ",")
                for str_anwser_one in str_anwsers:
                    tran_str_answser.append(
                        tran_numer_to_char(int(str_anwser_one)))

                # 将用户的回答转换,排序
                strip_anwser_list = user_anwsers.split(" ")
                print(strip_anwser_list)
                for strip_anwser in strip_anwser_list:
                    tran_user_anwser.append(str.upper(strip_anwser))

                tran_user_anwser.sort()

                if (tran_user_anwser == tran_str_answser):
                    isFigth = True
                else:
                    rigth_number = tran_str_answser

            elif (types == 3):
                # 填空题逻辑
                user_anwsers = await session.aget(
                    'ansser',
                    prompt='这是一道填空题,请输入你的答案 ',
                    arg_filters=[
                        extractors.extract_text,  # 取纯文本部分
                        controllers.handle_cancellation(
                            session),  # 处理用户可能的取消指令
                        str.strip,  # 去掉两边空白字符
                    ])
                replace = question.get("question_standard_answer")
                if (user_anwsers == replace):
                    isFigth = True
                else:
                    rigth_number = replace

            else:
                await session.send("sorry,现在只支持单选题")

            if isFigth:
                await session.send("恭喜您答对了,\n这道题目的解析是\n{}".format(
                    question.get("question_analyze")))
                sender = session.event.sender
                addRanking(sender.get("user_id"), sender.get("nickname"))
            else:
                await session.send("抱歉你回答错了,\n正确答案是{},\n这道题目的解析是\n{}".format(
                    rigth_number, question.get("question_analyze")))
            session.state.pop("ansser")
            time.sleep(2)
        except Exception:
            print(Exception.__name__)
            session.finish("让我休息0.00001秒")