Beispiel #1
0
async def _(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice(
                    [
                        'zzzz......',
                        'zzzzzzzz......',
                        'zzz...好涩哦..zzz....',
                        '别...不要..zzz..那..zzz..',
                        '嘻嘻..zzz..呐~..zzzz..'
                    ]
                )
            )
        else:
            if checkSwitch(__plugin_name__, group):
                await session.send('ATRI正在获取P站每日排行榜前五作品...')

                start =time.perf_counter()

                try:
                    dc = json.loads(request_api(URL_3))
                except:
                    session.finish(errorBack('请求数据失败'))

                d = {}

                try:
                    for i in range(0,5):
                        pid = dc["response"][0]["works"][i]["work"]["id"]
                        pidURL = f'https://pixiv.cat/{pid}.jpg'
                        d[i] = [f'{pid}',f'{pidURL}']
                except:
                    session.finish('处理数据失败')

                msg0 = (f'[CQ:at,qq={user}]')

                result = sorted(
                    d.items(),
                    key = lambda x:x[1],
                    reverse = True
                )

                t = 0

                for i in result:
                    t += 1
                    msg = (f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
                    msg0 += msg
                end = time.perf_counter()

                msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
                msg0 += msg1

                await session.send(msg0)
            
            else:
                await session.send('该功能已关闭...')
Beispiel #2
0
async def _(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice(
                    [
                        'zzzz......',
                        'zzzzzzzz......',
                        'zzz...好涩哦..zzz....',
                        '别...不要..zzz..那..zzz..',
                        '嘻嘻..zzz..呐~..zzzz..'
                    ]
                )
            )
        else:
            if checkSwitch(__plugin_name1__, group):
                pid = session.current_arg.strip()

                if not pid:
                    pid = session.get('message', prompt = '请告诉ATRI需要查询的Pid码')
                
                start =time.perf_counter()
                await session.send('开始P站搜图')

                URL = URL_1 + pid

                try:
                    dc = json.loads(request_api(URL))
                except:
                    session.finish(errorBack('请求数据失败'))

                img = f'https://pixiv.cat/{pid}.jpg'
                

                end = time.perf_counter()

                try:
                    await session.send(
                        IMG_SEACH_REPLY.format(
                            user = user,
                            pid = pid,
                            title = dc["response"][0]["title"],
                            width = dc["response"][0]["width"],
                            height = dc["response"][0]["height"],
                            tags = dc["response"][0]["tags"],
                            account = dc["response"][0]["user"]["account"],
                            name = dc["response"][0]["user"]["name"],
                            user_link = f'https://www.pixiv.net/users/' + f'{dc["response"][0]["user"]["id"]}',
                            img = img,
                            time = round(end - start, 3)
                        )
                    )
                except:
                    session.finish(errorBack('处理数据失败'))
            
            else:
                await session.send('该功能已关闭...')
Beispiel #3
0
async def _(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice([
                    'zzzz......', 'zzzzzzzz......', 'zzz...好涩哦..zzz....',
                    '别...不要..zzz..那..zzz..', '嘻嘻..zzz..呐~..zzzz..'
                ]))
        else:
            if checkSwitch(__plugin_name2__):
                author_id = session.current_arg.strip()

                if not author_id:
                    author_id = session.get('message',
                                            prompt='请告诉ATRI需要查询的画师ID')

                start = time.perf_counter()
                await session.send(
                    f'开始获取画师{author_id}的前三项作品\n如获取时间过长或许为图片过大上传较慢')

                URL = URL_2 + author_id

                dc = json.loads(response.request_api(URL))

                if not dc:
                    session.finish('ATRI在网络上走散了...请重试...')

                d = {}

                for i in range(0, 3):
                    pid = dc["response"][i]["id"]
                    pidURL = f'https://pixiv.cat/{pid}.jpg'
                    d[i] = [f'{pid}', f'{pidURL}']

                msg0 = (f'[CQ:at,qq={user}]\n画师id:{author_id},接下来展示前三作品')

                result = sorted(d.items(), key=lambda x: x[1], reverse=True)

                t = 0

                for i in result:
                    t += 1
                    msg = (
                        f'\n---------------\n({t})\nPid: {i[1][0]}\n{i[1][1]}')
                    msg0 += msg
                end = time.perf_counter()

                msg1 = (f'\n---------------\n完成时间:{round(end - start, 3)}s')
                msg0 += msg1

                await session.send(msg0)

            else:
                await session.send('该功能已关闭...')
Beispiel #4
0
async def SaucenaoSearch(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    msg = session.current_arg.strip()

    if checkNoob(user, group):
        if sleepTime():
            await session.send(sleepTime())
        else:
            if checkSwitch(__plugin_name__, group):
                if not msg:
                    msg = session.get('message', prompt="请发送一张图片")

                await session.send("开始以图识图")

                try:
                    p = '\\[CQ\\:image\\,file\\=.*?\\,url\\=(.*?)\\]'

                    img = re.findall(p, msg)

                    task = SauceNAO(api_key=API_KEY)
                    data = task.search(url=img)
                    msg0 = ''

                    try:
                        data = json.loads(data)['results'][0]
                        title = data['data']['title']
                        pixiv_id = data['data']['pixiv_id']
                        member_name = data['data']['member_name']
                        member_id = data['data']['member_id']
                        similarity = data['header']['similarity']
                        mini_url = data['header']['thumbnail']
                        msg0 = f'[CQ:at,qq={user}]'
                        msg0 += f'SauceNAO结果:'
                        msg0 += f'[CQ:image,file={mini_url}]\n'
                        msg0 += f'相似度:{similarity}%\n'
                        msg0 += f'标题:{title}\n'
                        msg0 += f'插画ID:{pixiv_id}\n'
                        msg0 += f'画师:{member_name}\n'
                        msg0 += f'画师ID:{member_id}\n'
                        msg0 += f'直链:https://pixiv.cat/{pixiv_id}.jpg'
                    except:
                        msg = '数据处理失败'

                    if float(similarity) > 70:
                        await session.send(msg0)
                    else:
                        await session.send("找不到相似的图呢...")

                except Exception:
                    session.finish(errorBack(msg))
            else:
                session.finish('该功能已关闭...')
Beispiel #5
0
async def _(context):
    group = context["group_id"]
    user = context["user_id"]
    if sleepTime():
        pass
    else:
        if checkNoob(user, group):
            msg = str(context["message"])
            print(msg)
            if "搜图" in msg or "识图" in msg:
                if checkSwitch("saucenao_search", group):
                    try:
                        pattern = r"CQ:reply,id=(.*?)]"
                        info = re.findall(pattern, msg)
                        msgID = info[0]
                        print(msgID)
                    except:
                        print('ERROR-onMessage')
                        return

                    try:
                        with open(
                                Path('.') / 'ATRI' / 'data' / 'groupData' /
                                f'{group}' / 'msgData.json', 'r') as f:
                            data = json.load(f)
                    except:
                        data = {}

                    if msgID in data.keys():
                        msgR = data[f"{msgID}"]["msg"]

                        pattern = r"url=(.*?)]"
                        info = re.findall(pattern, msgR)
                        picURL = info[0]

                        try:
                            task = SauceNAO(api_key=API_KEY)
                            data = task.search(url=picURL)
                            msg0 = ''
                        except:
                            await bot.send_msg(group_id=group,
                                               message=errorBack('请求数据失败')
                                               )  # type: ignore
                            return

                        print(data)
                        try:
                            data = json.loads(data)['results'][0]
                            title = data['data']['title']
                            pixiv_id = data['data']['pixiv_id']
                            member_name = data['data']['member_name']
                            member_id = data['data']['member_id']
                            similarity = data['header']['similarity']
                            mini_url = data['header']['thumbnail']
                            msg0 = f'[CQ:at,qq={user}]'
                            msg0 += f'SauceNAO结果:'
                            msg0 += f'[CQ:image,file={mini_url}]\n'
                            msg0 += f'相似度:{similarity}%\n'
                            msg0 += f'标题:{title}\n'
                            msg0 += f'插画ID:{pixiv_id}\n'
                            msg0 += f'画师:{member_name}\n'
                            msg0 += f'画师ID:{member_id}\n'
                            msg0 += f'直链:https://pixiv.cat/{pixiv_id}.jpg'
                        except:
                            await bot.send_msg(group_id=group,
                                               message=errorBack('处理数据失败')
                                               )  # type: ignore
                            return
                        if msg0:
                            if float(similarity) > 70:
                                await bot.send_msg(group_id=group,
                                                   message=msg0
                                                   )  # type: ignore
                            else:
                                await bot.send_msg(group_id=group,
                                                   message='ATRI无法找到相似的图呢...'
                                                   )  # type: ignore

                else:
                    await bot.send_msg(group_id=group,
                                       message='该功能已关闭...')  # type: ignore

            else:
                try:
                    with open(
                            Path('.') / 'ATRI' / 'plugins' / 'LearnRepo' /
                            'LearnRepo.json', 'r') as f:
                        data = json.load(f)
                except:
                    data = {}

                if str(msg) in data.keys():
                    lt = data[f"{msg}"]
                    msg = lt[0]
                    prob = int(lt[1])
                    res = randint(1, prob)
                    if res == 1:
                        await bot.send_msg(group_id=group,
                                           message=msg)  # type: ignore
Beispiel #6
0
async def AnimeSearch(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    msg = session.current_arg.strip()

    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice([
                    'zzzz......', 'zzzzzzzz......', 'zzz...好涩哦..zzz....',
                    '别...不要..zzz..那..zzz..', '嘻嘻..zzz..呐~..zzzz..'
                ]))
        else:
            if checkSwitch(__plugin_name__):
                if not msg:
                    msg = session.get('message', prompt="请发送一张图片")

                await session.send("开始以图搜番\n(如搜索时间过长或无反应则为图片格式有问题)")

                p = '\\[CQ\\:image\\,file\\=.*?\\,url\\=(.*?)\\]'

                img = re.findall(p, msg)

                if img:
                    URL = f'https://trace.moe/api/search?url={img[0]}'

                    req = await get_bytes(URL)

                    if req:
                        data = json.loads(req.decode())

                        d = {}

                        for i in range(len(data['docs'])):
                            if data['docs'][i]['title_chinese'] in d.keys():
                                d[data['docs'][i]['title_chinese']][0] += data[
                                    'docs'][i]['similarity']

                            else:
                                m = data['docs'][i]['at'] / 60
                                s = data['docs'][i]['at'] % 60

                                if data['docs'][i]['episode'] == '':
                                    n = 1

                                else:
                                    n = data['docs'][i]['episode']

                                d[toSimpleString(
                                    data['docs'][i]['title_chinese'])] = [
                                        data['docs'][i]['similarity'],
                                        f'第{n}集', f'{int(m)}分{int(s)}秒处'
                                    ]

                        result = sorted(d.items(),
                                        key=lambda x: x[1],
                                        reverse=True)

                        t = 0

                        msg0 = f'[CQ:at,qq={user}]\n根据所提供的图片按照相似度找到{len(d)}个结果:'

                        for i in result:
                            t += 1
                            lk = ('%.2f%%' % (i[1][0] * 100))
                            msg = (
                                f'\n——————————\n({t})\n相似度:{lk}\n动漫名:《{i[0]}》\n时间点:{i[1][1]} {i[1][2]}'
                            )
                            msg0 += msg

                        await session.send(msg0)

                    else:
                        await session.send("搜索似乎失败了呢...")

            else:
                session.finish('该功能已关闭...')
Beispiel #7
0
async def setu(session: CommandSession):
    start = time.perf_counter()
    user = session.event.user_id
    group = session.event.group_id
    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice([
                    'zzzz......', 'zzzzzzzz......', 'zzz...好涩哦..zzz....',
                    '别...不要..zzz..那..zzz..', '嘻嘻..zzz..呐~..zzzz..'
                ]))
        else:
            if checkSwitch(__plugin_name__, group):
                res = randint(1, 10)
                if 1 <= res <= 9:
                    res = randint(1, 4)
                    if 1 <= res <= 3:
                        if setu_type == 1:
                            res = randint(1, 5)
                            await session.send('别急!正在找图!')
                            con = sqlite3.connect(
                                Path('.') / 'ATRI' / 'data' / 'sqlite' /
                                'setu' / 'nearR18.db')
                            cur = con.cursor()
                            msg = cur.execute(
                                'SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;'
                            )

                            if 1 <= res <= 4:
                                for i in msg:
                                    pid = i[0]
                                    title = i[1]
                                    img = i[7]
                                    end = time.perf_counter()
                                    await session.send(
                                        SETU_REPLY.format(title=title,
                                                          pid=pid,
                                                          setu=img,
                                                          time=round(
                                                              end - start, 3)))
                            elif res == 5:
                                for i in msg:
                                    pid = i[0]
                                    title = i[1]
                                    img = i[7]
                                    end = time.perf_counter()
                                    await session.send(
                                        '我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆')
                                    await send_to_superusers(
                                        bot,
                                        message=
                                        f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{img}\nComplete time: {round(end - start, 3)}"
                                    )

                        elif setu_type == 2:
                            res = randint(1, 5)
                            await session.send('别急!正在找图!')
                            start = time.perf_counter()
                            values = {
                                "apikey": apikey_LOLI,
                                "r18": "0",
                                "num": "1"
                            }

                            try:
                                dc = json.loads(request_api_params(
                                    URL, values))
                                title = dc["data"][0]["title"]
                                pid = dc["data"][0]["pid"]
                                setu = dc["data"][0][
                                    "url"]  #b64.b64_str_img_url(dc["data"][0]["url"])
                            except:
                                session.finish(errorBack('请求数据失败'))

                            if 1 <= res <= 4:
                                end = time.perf_counter()
                                await session.send(
                                    SETU_REPLY.format(
                                        title=title,
                                        pid=pid,
                                        setu=dc["data"][0]["url"],
                                        time=round(end - start, 3)))
                            elif res == 5:
                                end = time.perf_counter()
                                await session.send(
                                    '我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆')
                                await send_to_superusers(
                                    bot,
                                    message=
                                    f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{setu}\nComplete time: {round(end - start, 3)}"
                                )
                    elif res == 4:
                        img = choice(['SP.jpg', 'SP1.jpg', 'SP2.jpg'])
                        img = Path('.') / 'ATRI' / 'data' / 'emoji' / f'{img}'
                        img = os.path.abspath(img)
                        await session.send(f'[CQ:image,file=file:///{img}]')

                elif res == 10:
                    img = choice([
                        'GDZ.png', 'SHZY1.jpg', 'SHZY2.jpg', 'SHZY3.jpg',
                        'SHZY4.jpg', 'SHZY5.jpg', 'SHZY6.jpg'
                    ])
                    img = Path(
                        '.') / 'ATRI' / 'data' / 'img' / 'niceIMG' / f'{img}'
                    img = os.path.abspath(img)
                    await session.send(f'[CQ:image,file=file:///{img}]')

            else:
                await session.send('该功能已关闭...')
Beispiel #8
0
async def _(context):
    start = time.perf_counter()
    user = context["user_id"]
    group = context["group_id"]
    if checkNoob(user, group):
        if checkSwitch(__plugin_name1__, group):
            try:
                img = str(context["message"])
                pattern = re.compile(r"url=(.*)]")
                img = re.findall(pattern, img)
                img = img[0].replace('url=', '')
                img = img.replace(']', '')
                print(img)
            except:
                return

            try:
                img = b64_str_img_url(img)
                print('转换图片至base64成功')
            except:
                return

            try:
                host = f'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={API_KEY}&client_secret={SECRECT_KEY}'
                headers = {'Content-Type': 'application/json;charset=UTF-8'}
                res = json.loads(request_api_params(host, headers))
                access_token = res['access_token']
                url = f'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token={access_token}'
                headers = {'Content-Type': 'application/x-www-form-urlencoded'}
                data = urlencode({'image': img})

                # res = requests.post(url=url, headers=headers, data=data)
                async def func0(url, headers, data):
                    async with aiohttp.ClientSession() as client:
                        async with client.post(url, headers=headers,
                                               data=data) as req:
                            res = await req.read()
                    return res

                words = json.loads(str(func0(
                    url, headers, data)))['words_result'][0]['words']
                print('BaiduAPI请求成功')
            except:
                return

            if re.findall(r"[涩色]图|炼铜", words):
                if checkSwitch(__plugin_name__, group):
                    res = randint(1, 10)
                    if 1 <= res <= 9:
                        res = randint(1, 5)
                        if 1 <= res <= 4:
                            if setu_type == 1:
                                res = randint(1, 5)
                                await bot.send_group_msg(group_id=group,
                                                         message='别急!正在找图!'
                                                         )  # type: ignore
                                con = sqlite3.connect(
                                    Path('.') / 'ATRI' / 'data' / 'sqlite' /
                                    'setu' / 'nearR18.db')
                                cur = con.cursor()
                                msg = cur.execute(
                                    'SELECT * FROM nearR18 ORDER BY RANDOM() limit 1;'
                                )

                                if 1 <= res <= 4:
                                    for i in msg:
                                        pid = i[0]
                                        title = i[1]
                                        img = i[7]
                                        end = time.perf_counter()
                                        msg = SETU_REPLY.format(
                                            title=title,
                                            pid=pid,
                                            setu=img,
                                            time=round(end - start, 3))
                                        await bot.send_group_msg(
                                            group_id=group,
                                            message=msg)  # type: ignore
                                elif res == 5:
                                    for i in msg:
                                        pid = i[0]
                                        title = i[1]
                                        img = i[7]
                                        end = time.perf_counter()
                                        await bot.send_group_msg(
                                            group_id=group,
                                            message='我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆'
                                        )  # type: ignore
                                        await send_to_superusers(
                                            bot,
                                            message=
                                            f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{img}\nComplete time: {round(end - start, 3)}"
                                        )

                            elif setu_type == 2:
                                res = randint(1, 5)
                                await bot.send_group_msg(group_id=group,
                                                         message='别急!正在找图!'
                                                         )  # type: ignore
                                start = time.perf_counter()
                                values = {
                                    "apikey": apikey_LOLI,
                                    "r18": "0",
                                    "num": "1"
                                }

                                try:
                                    dc = json.loads(
                                        request_api_params(URL, values))
                                    title = dc["data"][0]["title"]
                                    pid = dc["data"][0]["pid"]
                                    setu = dc["data"][0][
                                        "url"]  #b64.b64_str_img_url(dc["data"][0]["url"])
                                except:
                                    await bot.send_group_msg(
                                        group_id=group,
                                        message=errorBack('数据请求失败')
                                    )  # type: ignore
                                    return
                                if 1 <= res <= 4:
                                    end = time.perf_counter()
                                    msg = SETU_REPLY.format(title=title,
                                                            pid=pid,
                                                            setu=img,
                                                            time=round(
                                                                end - start,
                                                                3))
                                    await bot.send_group_msg(group_id=group,
                                                             message=msg
                                                             )  # type: ignore
                                elif res == 5:
                                    end = time.perf_counter()
                                    await bot.send_group_msg(
                                        group_id=group,
                                        message='我找到涩图了!但我发给主人了\nο(=•ω<=)ρ⌒☆'
                                    )  # type: ignore
                                    await send_to_superusers(
                                        bot,
                                        message=
                                        f"主人,从群{group}来的涩图!热乎着!\nTitle: {title}\nPid: {pid}\n{setu}\nComplete time: {round(end - start, 3)}"
                                    )
                        elif res == 5:
                            img = choice(['SP.jpg', 'SP1.jpg', 'SP2.jpg'])
                            img = Path(
                                '.') / 'ATRI' / 'data' / 'emoji' / f'{img}'
                            img = os.path.abspath(img)
                            await bot.send_group_msg(
                                group_id=group,
                                message=f'[CQ:image,file=file:///{img}]'
                            )  # type: ignore

                    elif res == 10:
                        img = choice([
                            'GDZ.png', 'SHZY1.jpg', 'SHZY2.jpg', 'SHZY3.jpg',
                            'SHZY4.jpg', 'SHZY5.jpg', 'SHZY6.jpg'
                        ])
                        img = Path(
                            '.'
                        ) / 'ATRI' / 'data' / 'img' / 'niceIMG' / f'{img}'
                        img = os.path.abspath(img)
                        await bot.send_group_msg(
                            group_id=group,
                            message=f'[CQ:image,file=file:///{img}]'
                        )  # type: ignore

                else:
                    pass

        else:
            pass
Beispiel #9
0
async def AIchFace(session: CommandSession):
    user = session.event.user_id
    group = session.event.group_id
    if checkNoob(user, group):
        if 0 <= now_time() < 5.5:
            await session.send(
                choice([
                    'zzzz......', 'zzzzzzzz......', 'zzz...好涩哦..zzz....',
                    '别...不要..zzz..那..zzz..', '嘻嘻..zzz..呐~..zzzz..'
                ]))
        else:
            if checkSwitch(__plugin_name__):
                img1 = session.get('message1', prompt='请发送需要换脸的图片')
                img2 = session.get('message2', prompt='请发送素材图片')

                # 我承认了,我是取名废!
                a = img1.split(',')
                a = a[2].replace(']', '')
                a = a.replace('url=', '')
                imgres1 = requests.get(a)

                b = img2.split(',')
                b = b[2].replace(']', '')
                b = b.replace('url=', '')
                imgres2 = requests.get(b)

                try:
                    file1 = f'ATRI/data/temp/face/{user}'
                    if not os.path.exists(file1):
                        os.mkdir(file1)
                    with open(file1 + '/img1.jpg', 'wb') as f:
                        f.write(imgres1.content)

                    file2 = f'ATRI/data/temp/face/{user}'
                    if not os.path.exists(file2):
                        os.mkdir(file2)
                    with open(file2 + '/img2.jpg', 'wb') as f:
                        f.write(imgres2.content)
                except:
                    session.finish('请求数据貌似失败了...')

                img1File = Path(
                    '.'
                ) / 'ATRI' / 'data' / 'temp' / 'face' / f'{user}' / 'img1.jpg'
                img2File = Path(
                    '.'
                ) / 'ATRI' / 'data' / 'temp' / 'face' / f'{user}' / 'img2.jpg'

                try:
                    change_face(img1File, img2File, user, 1)
                except:
                    session.finish('emm...貌似失败了呢......')

                time.sleep(0.5)
                doneIMG = Path(
                    '.'
                ) / 'ATRI' / 'data' / 'temp' / 'face' / f'{user}' / 'img3.jpg'
                img = os.path.abspath(doneIMG)
                await session.send(f'[CQ:image,file=file:///{img}]')
                files = f'ATRI/data/temp/face/{user}'
                os.remove(files)

            else:
                session.finish('该功能已关闭...')