示例#1
0
文件: setu.py 项目: muguangAA/qqBot
async def get_random_image(session: nonebot.CommandSession):
    ctx = session.ctx.copy()
    if 'group_id' not in ctx:
        return

    if admin_control.get_data(ctx['group_id'], 'banned'):
        await session.finish('管理员已设置禁止该群接收色图。如果确认这是错误的话,请联系bot制作者')

    id_num = ctx['group_id']
    user_id = ctx['user_id']
    sanity_meter.set_usage(id_num, 'setu')
    sanity_meter.set_user_data(user_id, 'setu')

    message = await get_random()
示例#2
0
async def av_validator(session: nonebot.CommandSession):
    ctx = session.ctx.copy()
    if get_privilege(ctx['user_id'], perm.BANNED):
        await session.finish('略略略,我主人把你拉黑了。哈↑哈↑哈')

    if not admin_control.get_data(ctx['group_id'], 'R18'):
        await session.finish('请联系BOT管理员开启本群R18权限')

    key_word = session.get('key_word', prompt='在?你要让我查什么啊baka')
    validator = shadiao.Avalidator(text=key_word)
    await validator.get_page_text()
    if 'group_id' in ctx:
        sanity_meter.set_usage(ctx['group_id'], tag='yanche')
        sanity_meter.set_user_data(ctx['user_id'], 'yanche')

    await session.finish(await validator.get_content())
示例#3
0
async def ten_polls(session: nonebot.CommandSession):
    ctx = session.ctx.copy()
    if 'group_id' not in ctx:
        await session.send('这是群组功能')
        return

    if get_privilege(ctx['user_id'], perm.OWNER):
        arknights_api.get_randomized_results(98)

    else:
        offset = ark_pool_pity.get_offset_setting(ctx['group_id'])
        arknights_api.get_randomized_results(offset)
        class_list = arknights_api.random_class
        six_star_count = class_list.count(6)
        if 6 in class_list:
            ark_pool_pity.reset_offset(ctx['group_id'])

        five_star_count = class_list.count(5)

        data = {
            "6": six_star_count,
            "5": five_star_count,
            "4": class_list.count(4),
            "3": class_list.count(3)
        }

        if six_star_count == 0 and five_star_count == 0:
            sanity_meter.set_user_data(ctx['user_id'], 'only_four_three')

        sanity_meter.set_usage(group_id=ctx['group_id'],
                               tag='pulls',
                               data=data)
        sanity_meter.set_usage(group_id=ctx['group_id'], tag='pull')
        sanity_meter.set_user_data(ctx['user_id'], 'six_star_pull',
                                   six_star_count)

    qq_num = ctx['user_id']
    await session.send(f'[CQ:at,qq={qq_num}]\n{arknights_api.__str__()}')
示例#4
0
文件: setu.py 项目: muguangAA/qqBot
async def pixiv_send(session: nonebot.CommandSession):
    if alarm_api.get_alarm():
        await session.finish('警报已升起!请等待解除!\n' f'{alarm_api.get_info()}')

    ctx = session.ctx.copy()
    message_id = ctx['message_id']
    if get_privilege(ctx['user_id'], perm.BANNED):
        return

    group_id = ctx['group_id'] if 'group_id' in ctx else -1
    user_id = ctx['user_id']
    if 'group_id' in ctx and not get_privilege(user_id, perm.OWNER):
        if admin_control.get_data(ctx['group_id'], 'banned'):
            await session.finish('管理员已设置禁止该群接收色图。如果确认这是错误的话,请联系bot制作者')

    sanity = -1
    monitored = False
    multiplier = 1
    doMultiply = False

    if group_id in sanity_meter.get_sanity_dict():
        sanity = sanity_meter.get_sanity(group_id)

    elif 'group_id' not in ctx and not get_privilege(user_id, perm.WHITELIST):
        await session.finish('我主人还没有添加你到信任名单哦。请找BOT制作者要私聊使用权限~')

    else:
        sanity = sanity_meter.get_max_sanity()
        sanity_meter.set_sanity(group_id=group_id,
                                sanity=sanity_meter.get_max_sanity())

    if sanity <= 0:
        if group_id not in sanity_meter.remind_dict or not sanity_meter.remind_dict[
                group_id]:
            sanity_meter.set_remid_dict(group_id, True)
            await session.finish('您已经理智丧失了,不能再查了哟~(小提示:指令理智查询可以帮您查看本群还剩多少理智)')

        return

    if not admin_control.get_if_authed():
        pixiv_api.set_auth(
            access_token=admin_control.get_access_token(),
            refresh_token='iL51azZw7BWWJmGysAurE3qfOsOhGW-xOZP41FPhG-s')
        admin_control.set_if_authed(True)

    is_exempt = admin_control.get_data(group_id,
                                       'exempt') if group_id != -1 else False

    key_word = str(session.get('key_word', prompt='请输入一个关键字进行查询')).lower()

    if key_word in sanity_meter.get_bad_word_dict():
        multiplier = sanity_meter.get_bad_word_dict()[key_word]
        doMultiply = True
        if multiplier > 0:
            await session.send(
                f'该查询关键词在黑名单中,危机合约模式已开启:本次色图搜索将{multiplier}倍消耗理智')

            if multiplier * 2 > 400:
                sanity_meter.set_user_data(user_id, 'ban_count')
                if sanity_meter.get_user_data_by_tag(user_id,
                                                     'ban_count') >= 2:
                    user_control_module.set_user_privilege(
                        user_id, 'BANNED', True)
                    await session.send(f'用户{user_id}已被封停机器人使用权限')
                    bot = nonebot.get_bot()
                    await bot.send_private_msg(
                        user_id=SUPER_USER,
                        message=
                        f'User {user_id} has been banned for triggering prtection. Keyword = {key_word}'
                    )

                else:
                    await session.send('本次黑名单搜索已触发群保护机制,下次触发将会导致所有功能禁用。')
                    bot = nonebot.get_bot()
                    await bot.send_private_msg(
                        user_id=SUPER_USER,
                        message=
                        f'User {user_id} triggered protection mechanism. Keyword = {key_word}'
                    )

                del bot
                return
        else:
            await session.send(
                f'该查询关键词在白名单中,支援合约已开启:本次色图搜索将{abs(multiplier)}倍补充理智')

    if key_word in sanity_meter.get_monitored_keywords():
        await session.send('该关键词在主人的监控下,本次搜索不消耗理智,且会转发主人一份√')
        monitored = True
        if 'group_id' in ctx:
            sanity_meter.set_user_data(user_id, 'hit_xp')
            sanity_meter.set_xp_data(key_word)

    elif '色图' in key_word:
        await session.finish(
            MessageSegment.image(
                f'file:///{getcwd()}/data/dl/others/QQ图片20191013212223.jpg'))

    elif '屑bot' in key_word:
        await session.finish('你屑你🐴呢')

    json_result = {}

    try:
        if '最新' in key_word:
            json_result = pixiv_api.illust_ranking('week')
        else:
            json_result = pixiv_api.search_illust(word=key_word,
                                                  sort="popular_desc")

    except pixivpy3.PixivError:
        await session.finish('pixiv连接出错了!')

    except Exception as err:
        await session.send(f'发现未知错误!错误信息已发送给bot主人分析!\n' f'{err}')

        bot = nonebot.get_bot()
        await bot.send_private_msg(
            user_id=SUPER_USER,
            message=f'Uncaught error while using pixiv search:\n'
            f'Error from {user_id}\n'
            f'Keyword = {key_word}\n'
            f'Exception = {err}')

        return

    # 看一下access token是否过期
    if 'error' in json_result:
        admin_control.set_if_authed(False)
        try:
            admin_control.set_access_token(access_token=pixiv_api.login(
                username=user_name, password=password).response.access_token)

            await session.send('新的P站匿名访问链接已建立……')
            admin_control.set_if_authed(True)

        except pixivpy3.PixivError as err:
            print(err)
            return

    if '{user='******'{user=(.*?)}', key_word)
        if key_word:
            key_word = key_word[0]
        else:
            await session.send('未找到该用户。')
            return

        json_user = pixiv_api.search_user(word=key_word, sort="popular_desc")
        if json_user.user_previews:
            user_id = json_user.user_previews[0].user.id
            json_result = pixiv_api.user_illusts(user_id)
        else:
            await session.send(f"{key_word}无搜索结果或图片过少……")
            return

    else:
        json_result = pixiv_api.search_illust(word=key_word,
                                              sort="popular_desc")

    if not json_result.illusts or len(json_result.illusts) < 4:
        nonebot.logger.warning(f"未找到图片, keyword = {key_word}")
        await session.send(f"{key_word}无搜索结果或图片过少……")
        return

    sanity_meter.track_keyword(key_word)
    illust = random.choice(json_result.illusts)
    is_r18 = illust.sanity_level == 6
    if not monitored:
        if is_r18:
            sanity_meter.drain_sanity(group_id=group_id,
                                      sanity=2 if not doMultiply else 2 *
                                      multiplier)
        else:
            sanity_meter.drain_sanity(group_id=group_id,
                                      sanity=1 if not doMultiply else 1 *
                                      multiplier)

    start_time = time.time()
    path = await download_image(illust)
    try:
        nickname = ctx['sender']['nickname']
    except TypeError:
        nickname = 'null'

    bot = nonebot.get_bot()
    if not is_r18:
        try:
            await session.send(
                f'[CQ:reply,id={message_id}]'
                f'Pixiv ID: {illust.id}\n'
                f'查询关键词:{key_word}\n'
                f'画师:{illust["user"]["name"]}\n' +
                f'{MessageSegment.image(f"file:///{path}")}\n' +
                f'Download Time: {(time.time() - start_time):.2f}s')

            nonebot.logger.info("sent image on path: " + path)

        except Exception as e:
            nonebot.logger.info('Something went wrong %s' % e)
            await session.send('悲,屑TX不收我图。')
            return

    elif is_r18 and (group_id == -1
                     or admin_control.get_data(group_id, 'R18')):
        await session.send(
            f'[CQ:reply,id={message_id}]'
            f'芜湖~好图来了ww\n'
            f'Pixiv ID: {illust.id}\n'
            f'关键词:{key_word}\n'
            f'画师:{illust["user"]["name"]}\n'
            f'[CQ:image,file=file:///{path}{",type=flash" if not is_exempt else ""}]'
            + f'Download Time: {(time.time() - start_time):.2f}s')

    else:
        if not monitored:
            await session.send('我找到色图了!\n但是我发给我主人了_(:зゝ∠)_')
            await bot.send_private_msg(
                user_id=SUPER_USER,
                message=f"图片来自:{nickname}\n"
                f"来自群:{group_id}\n"
                f"查询关键词:{key_word}\n" + f'Pixiv ID: {illust.id}\n' +
                f'{MessageSegment.image(f"file:///{path}")}\n' +
                f'Download Time: {(time.time() - start_time):.2f}s')

    sanity_meter.set_usage(group_id, 'setu')
    if 'group_id' in ctx:
        sanity_meter.set_user_data(user_id, 'setu')

    if monitored and not get_privilege(user_id, perm.OWNER):
        await bot.send_private_msg(user_id=SUPER_USER,
                                   message=f'图片来自:{nickname}\n'
                                   f'查询关键词:{key_word}\n'
                                   f'Pixiv ID: {illust.id}\n'
                                   '关键字在监控中' +
                                   f'[CQ:image,file=file:///{path}]')