Exemple #1
0
async def rm_banner(app: Mirai, group: Group, member: Member,
                    cp: CommandParser):
    if member.id in conf.get("permission", "operator"):
        pa = cp.parse_with_valid(["String", ("Int", "At")])
        if isinstance(pa, str):
            return await app.sendGroupMessage(
                group, [At(member.id), Plain(pa)])
        elif not pa:
            return await app.sendGroupMessage(
                group, [At(member.id), Plain("参数不能为空")])
        if pa[0][1] == "group":
            target = "group_id"
        elif pa[0][1] == "member":
            target = "qq_id"
        else:
            return await app.sendGroupMessage(
                group, [At(member.id), Plain("类型错误")])
        if pa[1][1] not in conf.get("banner", target):
            return await app.sendGroupMessage(
                group, [At(member.id), Plain("还不在清单里")])
        conf.get("banner", target).remove(pa[1][1])
        await app.sendGroupMessage(
            group, [At(member.id), Plain(f"移除{pa[1][1]}成功")])
    else:
        await app.sendGroupMessage(group, [At(member.id), Plain("权限不足")])
Exemple #2
0
async def search_image(app: Mirai, group: Group, member: Member, cp: CommandParser, message: MessageChain):
    pa = cp.parse_with_valid(["[Image"])
    if isinstance(pa, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(pa)])
    elif not pa:
        return await app.sendGroupMessage(group, [At(member.id), Plain("参数不能为空")])
    img = message.getFirstComponent(Image)
    with open(f"{ROOT}{str(img.imageId)}.jpg", "wb") as f:
        f.write((await img.toBytes()).getvalue())
    try:
        _, raw = await wget(f"https://saucenao.com/search.php?output_type=2&testmode=0&numres=4&url=https://www.pixivdl.net/static/img/{str(img.imageId)}.jpg")
    finally:
        os.remove(f"{ROOT}{str(img.imageId)}.jpg")
    data = Parser.parse_raw(raw)
    if data.header.status != 0:
        print(raw)
        return await app.sendGroupMessage(group, [At(member.id), Plain(f"发生错误:status: {data.header.status}")])
    result = ["查询结果:\n", f"作品类型:{DataBase.get(data.results[0].header.index_id)}\n",
              f"准确度:{data.results[0].header.similarity}%\n", f"剩余次数:{data.header.long_remaining}\n"]
    if data.results[0].header.index_id in (21, 22):  # Anime, HAnime
        result.append(f"作品名:{data.results[0].data.source}\n")
        result.append(f"年份:{data.results[0].data.year}\n")
        result.append(f"目标位置:第{data.results[0].data.part}集,{data.results[0].data.est_time}\n")
    elif data.results[0].header.index_id in (5, 31, 33, 34):  # Image
        result.append(f"标题:{data.results[0].data.title}\n")
    result.append(f"更多信息:{data.results[0].data.ext_urls[0]}")
    await app.sendGroupMessage(group, [At(member.id), *(Plain(msg) for msg in result)])
Exemple #3
0
async def join(app: Mirai, group: Group, member: Member, cp: CommandParser):
    pa = cp.parse_with_valid(["Int"])
    if isinstance(pa, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(pa)])
    elif not pa:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("参数不能为空")])
    if pa[0][1] not in bind:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("没有找到这个房间")])
    elif member.id in bind:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("你不能加入自己的房间")])
    elif len(room[pa[0][1]]) > 1:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("已经开始了")])
    else:
        room[pa[0][1]].append(member.id)
        state[member.id] = state[pa[0][1]]
        await app.sendGroupMessage(
            group,
            [At(member.id), Plain("加入成功,若图片无法正常加载可输入!cget")])
    await app.sendGroupMessage(group, [
        At(pa[0][1]),
        Image.fromBytes(bind[state[member.id]].get_image()),
        Plain("输入!p x y来放置棋子")
    ])
Exemple #4
0
async def repeat(app: Mirai, group: Group, member: Member, cp: CommandParser):
    args = cp.parse_with_valid(("Int", ("Int", "String")))  # count, content
    if isinstance(args, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(args)])
    if member.id not in admin and args[0][1] > 3:
        return await app.sendGroupMessage(group, [At(member.id), Plain("次数不能大于3")])
    for _ in range(args[0][1]):
        await app.sendGroupMessage(group, [Plain(str(args[1][1]))])
Exemple #5
0
async def lm(app: Mirai, group: Group, member: Member, cp: CommandParser):
    arg = cp.parse_with_valid(["Int"])
    if not arg:
        await app.sendGroupMessage(group, await lm_create(app, sabee, group.id, member.id))
    elif isinstance(arg, str):
        await app.sendGroupMessage(group, Plain(arg))
    else:
        if os.path.isfile(getpath(arg[0][1])):
            await app.sendGroupMessage(group, await lm_create(app,
                                                              json.load(open(getpath(arg[0][1]), "r")),
                                                              group.id, member.id))
        else:
            await app.sendGroupMessage(group, [At(member.id), Plain(f"没有找到日期为{arg[0][1]}的记录")])
    return True
Exemple #6
0
async def edit_nick(app: Mirai, group: Group, member: Member,
                    cp: CommandParser):
    if member.id in conf.get("permission", "operator"):
        pa = cp.parse_with_valid([("Int", "String")])
        if isinstance(pa, str):
            return await app.sendGroupMessage(
                group, [At(member.id), Plain(pa)])
        elif not pa:
            return await app.sendGroupMessage(
                group, [At(member.id), Plain("参数不能为空")])
        info = await app.botMemberInfo(group)
        info.modify({"name": pa[0][1]})
        await app.changeMemberInfo(group, app.qq, info)
        await app.sendGroupMessage(group, [At(member.id), Plain("修改成功")])
    else:
        await app.sendGroupMessage(group, [At(member.id), Plain("权限不足")])
Exemple #7
0
async def put(app: Mirai, group: Group, member: Member, source: Source,
              cp: CommandParser):
    pa = cp.parse_with_valid(["Int", "Int"])
    if isinstance(pa, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(pa)])
    elif not pa:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("参数不能为空")])
    if member.id not in state:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("你没有加入房间")])
    if room[state[member.id]][0] == member.id:
        if member.id in bind:
            code = bind[state[member.id]].put(pa[0][1], pa[1][1], -1)
        else:
            code = bind[state[member.id]].put(pa[0][1], pa[1][1], 1)
        if code == 1:
            await app.sendGroupMessage(group, [
                At(member.id),
                Plain("胜出\n"),
                Image.fromBytes(bind[state[member.id]].get_image())
            ])
            for m in room[state[member.id]]:
                try:
                    state.pop(m)
                    room.pop(m)
                    bind.pop(m)
                except KeyError:
                    pass
        elif code == 0:
            await app.sendGroupMessage(group, [
                At(room[state[member.id]][1]),
                Plain("轮到你了"),
                Image.fromBytes(bind[state[member.id]].get_image())
            ],
                                       quoteSource=source)
            room[state[member.id]].insert(0, room[state[member.id]].pop(1))
        elif code == -1:
            await app.sendGroupMessage(
                group, [At(member.id), Plain("这里已经有棋子了")])
        elif code == -2:
            await app.sendGroupMessage(group, [At(member.id), Plain("你放过界了")])
    else:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("还没有轮到你")])
Exemple #8
0
async def bangumi_push(app: Mirai, member: Member, group: Group, cp: CommandParser):
    global nt
    pa = cp.parse_with_valid(["Int"])
    if isinstance(pa, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(pa)])
    elif not pa:
        week = datetime.today().isoweekday()
    else:
        week = pa[0][1]
    if nt+3600 < time.time():
        l.clear()
        l.update(await kisssub())
        if l:
            nt = time.time()
    print(l)
    now = l[str(week)]
    await app.sendGroupMessage(group, [At(member.id), Plain(f"{now[0]['utime'][3]}的番剧列表:\n"),
                                       *(Plain(f"{b['name']}:{b['tag']}\n") for b in now)])
Exemple #9
0
async def make(app: Mirai, group: Group, member: Member, cp: CommandParser):
    pa = cp.parse_with_valid(["Int"])
    if isinstance(pa, str):
        return await app.sendGroupMessage(group, [At(member.id), Plain(pa)])
    elif not pa:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("参数不能为空")])
    if pa[0][1] > 20:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("棋盘太大了")])
    elif pa[0][1] < 5:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("棋盘太小了")])
    elif member.id in state:
        return await app.sendGroupMessage(
            group, [At(member.id), Plain("你已经在一个房间里面了")])
    cc = ChessControl(pa[0][1] + 2)  # 修正边界问题
    bind[member.id] = cc
    room[member.id] = [member.id]
    state[member.id] = member.id
    await app.sendGroupMessage(
        group,
        Plain(f'已经创建大小为{pa[0][1]}*{pa[0][1]}的棋盘\n输入"!cjoin {member.id}"即可加入'))
Exemple #10
0
async def test(app: Mirai, group: Group, message: MessageChain):
    xd = CommandParser(message).parse_raw()
    return await app.sendGroupMessage(group, [Plain(json.dumps(xd))])