Esempio n. 1
0
async def setu(bot: Bot, event: Event):
    """随机叫一份涩图,对每个用户有冷却时间"""
    uid = event.get_user_id()
    if not _nlmt.check(uid):
        await bot.send(event, EXCEED_NOTICE, at_sender=True)
        return
    if not _flmt.check(uid):
        await bot.send(event, '您冲得太快了,请稍候再冲', at_sender=True)
        return
    _flmt.start_cd(uid)
    _nlmt.increase(uid)

    # conditions all ok, send a setu.
    try:
        logger.debug('开始从网络爬取图片。')
        pic = await get_web_img()
    except Exception as e:
        logger.error(f"爬取网络图片失败,将从本地选择。({e})")
        pic = get_local_setu()

    try:
        if pic:
            await bot.send(event, pic.cqcode)
    except Exception as e:
        logger.error(f"发送图片{pic.path}失败")
        logger.exception(e)
        try:
            await bot.send(event, '涩图太涩,发不出去勒...')
        except:
            pass
Esempio n. 2
0
async def _regex_setu_random(bot: Bot, event: Event, state: dict):
    global last_time_Rrandom
    if isinstance(event, GroupMessageEvent):
        if event.group_id in [
                get_driver().config.GroupList['last'],
                get_driver().config.GroupList['test']
        ]:
            start_time = datetime.datetime.now()  # 取现在时间
            # 用于判定程序是否为初次启动,检测last_time是否被赋值
            if isinstance(last_time_Rrandom, datetime.datetime):
                if (start_time - last_time_Rrandom).seconds <= 5:
                    if str(event.user_id) not in masterList:
                        await regex_setu_random.finish(
                            "我球球你了让Senrin歇一会儿吧......爪巴涩图很累的说......")
                        return
                    else:
                        await regex_setu_random.send("我爪巴爪巴......这就去......")
            handle_msg = (f"[CQ:at,qq={event.user_id}]随机涩图触发\n"
                          "触发方式:regex\n"
                          "图片分级:随机\n"
                          "图片数量:1\n"
                          "Loading......(约3秒钟)")
            await regex_setu_random.send(Message(handle_msg))
            setu = await random_setu(Rmodle='regex', level=None, num=1)
        else:
            setu = None
    elif isinstance(event, PrivateMessageEvent):
        if str(event.user_id) in masterList:
            handle_msg = ("随机涩图触发\n"
                          "触发方式:regex\n"
                          "图片分级:随机\n"
                          "图片数量:1\n"
                          "Loading......(约3秒钟)")
            await regex_setu_random.send(Message(handle_msg))
            setu = await random_setu(Rmodle='regex', level=None, num=1)
        else:
            await regex_setu_random.finish("看尼玛涩图给爷爬!")
            setu = None
    else:
        setu = None
    if setu:
        handle_msg = 'Active!!!'
        await regex_setu_random.send(Message(handle_msg))
        for msg in setu:
            await asyncio.sleep(0.1)
            await regex_setu_random.send(Message(msg))
    download_urls.clear()
    if event.get_user_id() not in masterList and resetTime == True:
        last_time_Rrandom = datetime.datetime.now()
    await regex_setu_random.finish()
Esempio n. 3
0
async def _regex_setu_search(bot: Bot, event: Event, state: dict):
    global last_time_command

    async def regex_march():
        if re.match(r'^[来整][几.\S*][张份个]\S*[色涩黄]图$', str(event.get_message())):
            key = re.findall(r'^[来整][几.\S*][张份个](\S*?)[色涩黄]图$',
                             str(event.get_message()))[0]
            num = re.findall(r'^[来整]([几.\S*]?)[张份个]\S*[色涩黄]图$',
                             str(event.get_message()))[0]
            if num == '几':
                num = random.randint(1, 10)
            elif num in word_to_int:
                num = word_to_int[num]
            else:
                await regex_setu_search.finish(
                    "呐很抱歉呢......Senrin这里只有十张以内的涩图的说......")
        else:
            key = re.findall(r'^[来整]点(\S*?)[色涩黄]图$',
                             str(event.get_message()))[0]  # 获取关键词
            num = 1
        return (key, num)

    if isinstance(event, GroupMessageEvent):
        if event.group_id in [
                get_driver().config.GroupList['last'],
                get_driver().config.GroupList['test']
        ]:
            start_time = datetime.datetime.now()  # 取现在时间
            # 用于判定程序是否为初次启动,检测last_time是否被赋值
            if isinstance(last_time_command, datetime.datetime):
                if (start_time - last_time_command).seconds <= 60:
                    if str(event.user_id) not in masterList:
                        await regex_setu_search.finish(
                            "我球球你了让Senrin歇一会儿吧......爪巴涩图很累的说......")
                        return
                    else:
                        await regex_setu_search.send("我爪巴爪巴......这就去......")
            result_march = await regex_march()
            key, num = result_march[0], result_march[1]
            handle_msg = (f"[CQ:at,qq={event.user_id}]随机涩图触发\n"
                          "触发方式:regex\n"
                          f"关键词:{key}\n"
                          f"图片数量:{num}\n"
                          "Loading......(约10秒钟)")
            await regex_setu_search.send(Message(handle_msg))
            setu = await search_setu(Keywords=key, num=num)
        else:
            setu = None
    elif isinstance(event, PrivateMessageEvent):
        if str(event.user_id) in masterList:
            result_march = await regex_march()
            key, num = result_march[0], result_march[1]
            handle_msg = ("定向涩图触发\n"
                          "触发方式:regex\n"
                          f"关键词:{key}\n"
                          f"图片数量:{num}\n"
                          "Loading......(约10秒钟)")
            await regex_setu_search.send(Message(handle_msg))
            setu = await search_setu(Keywords=key, num=num)
        else:
            await regex_setu_search.finish("看尼玛涩图给爷爬!")
            setu = None
    else:
        setu = None
    if setu:
        await regex_setu_search.send('Active!!!')
        for msg in setu:
            await asyncio.sleep(0.1)
            await regex_setu_random.send(Message(msg))
    download_urls.clear()
    if event.get_user_id() not in masterList and resetTime == True:
        last_time_command = datetime.datetime.now()
    await regex_setu_search.finish()
Esempio n. 4
0
async def _command_setu(bot: Bot, event: Event, state: dict):
    global last_time_command

    def check_tpye(arg):  # 检查命令格式
        if arg:
            if arg[0] == 'random':
                try:
                    level = int(arg[1])
                    num = int(arg[2])
                except:
                    check_type = False
                else:
                    if level in [1, 2, 0] and num <= 10:
                        check_type = True
                    else:
                        check_type = False
            elif arg[0] == 'search':
                try:
                    num = int(arg[2])
                except:
                    check_type = False
                else:
                    check_type = True if num <= 10 else False
            else:
                check_type = False
        else:
            check_type = False
        return check_type

    if isinstance(event, GroupMessageEvent):
        if event.group_id in [
                get_driver().config.GroupList['last'],
                get_driver().config.GroupList['test']
        ]:
            arg = str(event.get_message()).split()
            checked_type = check_tpye(arg)
            if checked_type == False:
                setu = None
                await command_setu.finish(
                    Message(
                        f"[CQ:at,qq={event.user_id}]传入了不正确的参数......\n然后指令坏掉了,Senrin处理了个寂寞"
                    ))
            else:
                if arg[0] == 'random':
                    level, num = arg[1], int(arg[2])
                    start_time = datetime.datetime.now()  # 取现在时间
                    # 用于判定程序是否为初次启动,检测last_time是否被赋值
                    if isinstance(last_time_command, datetime.datetime):
                        if (start_time - last_time_command).seconds <= 60:
                            if str(event.user_id) not in masterList:
                                await command_setu.finish(
                                    "我球球你了让Senrin歇一会儿吧......爪巴涩图很累的说......")
                                return
                            else:
                                await command_setu.send("我爪巴爪巴......这就去......")
                    level_zh = level_zh_dic[str(level)]
                    handle_msg = (f"[CQ:at,qq={event.user_id}]随机涩图触发\n"
                                  "触发方式:command\n"
                                  f"图片分级:{level_zh}\n"
                                  f"图片数量:{num}\n"
                                  "Loading......(约15秒钟)")
                    await command_setu.send(Message(handle_msg))
                    setu = await random_setu(Rmodle='random',
                                             level=level,
                                             num=num)
                elif arg[0] == 'search':
                    keywords, num = arg[1], int(arg[2])
                    start_time = datetime.datetime.now()  # 取现在时间
                    # 用于判定程序是否为初次启动,检测last_time是否被赋值
                    if isinstance(last_time_command, datetime.datetime):
                        if (start_time - last_time_command).seconds <= 60:
                            if str(event.user_id) not in masterList:
                                await command_setu.finish(
                                    "我球球你了让Senrin歇一会儿吧......爪巴涩图很累的说......")
                                return
                            else:
                                await command_setu.send("我爪巴爪巴......这就去......")
                    handle_msg = ("定向涩图触发\n"
                                  "触发方式:command\n"
                                  f"关键词:{keywords}\n"
                                  f"图片数量:{num}\n"
                                  "Loading......(约15秒钟)")
                    await command_setu.send(Message(handle_msg))
                    setu = await search_setu(Keywords=keywords, num=num)
                else:
                    setu = None
        else:
            setu = None
    elif isinstance(event, PrivateMessageEvent):
        if str(event.user_id) in masterList:
            arg = str(event.get_message()).split()
            checked_type = check_tpye(arg)
            if checked_type == False:
                setu = None
                await command_setu.finish(
                    "传入了不正确的参数......\n然后指令坏掉了,Senrin处理了个寂寞")
            else:
                if arg[0] == 'random':
                    level, num = arg[1], arg[2]
                    level_zh = level_zh_dic[str(level)]
                    handle_msg = (f"[CQ:at,qq={event.user_id}]随机涩图触发\n"
                                  "触发方式:command\n"
                                  f"图片分级:{level_zh}\n"
                                  f"图片数量:{num}\n"
                                  "Loading......(约15秒钟)")
                    await command_setu.send(Message(handle_msg))
                    setu = await random_setu(Rmodle='random',
                                             level=level,
                                             num=num)
                elif arg[0] == 'search':
                    keywords, num = arg[1], int(arg[2])
                    handle_msg = ("定向涩图触发\n"
                                  "触发方式:command\n"
                                  f"关键词:{keywords}\n"
                                  f"图片数量:{num}\n"
                                  "Loading......(约15秒钟)")
                    await command_setu.send(Message(handle_msg))
                    setu = await search_setu(Keywords=keywords, num=num)
                else:
                    setu = None
        else:
            setu = None
    else:
        setu = None
    if setu:
        await command_setu.send('Active!!!')
        for msg in setu:
            await command_setu.send(Message(msg))
            await asyncio.sleep(0.1)
    if event.get_user_id() not in masterList and resetTime == True:
        last_time_command = datetime.datetime.now()
    download_urls.clear()
    await command_setu.finish()