async def image_waiter(waiter_group: Group, waiter_member: Member,
                        waiter_message: MessageChain):
     if waiter_group.id == group.id and waiter_member.id == member.id:
         if waiter_message.has(Image):
             return await waiter_message.getFirst(Image).get_bytes()
         else:
             return False
Exemple #2
0
async def repeater_handler(app: Ariadne, message: MessageChain, group: Group):
    if not await group_setting.get_setting(
            group, Setting.repeat) or not await group_setting.get_setting(
                group, Setting.switch):
        return
    global group_repeat
    if (message.has(Forward) or message.has(App) or message.has(Json)
            or message.has(Xml) or message.has(MarketFace)):
        group_repeat[group.id] = {
            "msg": message.asPersistentString(),
            "count": -1
        }
        return
    msg = message.copy()
    for i in msg.__root__:
        if isinstance(i, MultimediaElement):
            i.url = ""
    message_serialization = msg.asPersistentString()
    if group.id not in group_repeat.keys():
        group_repeat[group.id] = {"msg": message_serialization, "count": 1}
    else:
        if message_serialization == group_repeat[group.id]["msg"]:
            if group_repeat[group.id]["count"] == -1:
                return
            count = group_repeat[group.id]["count"] + 1
            if count == 2:
                group_repeat[group.id]["count"] = count
                msg = message.include(Plain, Image, At, Quote, AtAll, Face,
                                      Poke)
                if msg.asDisplay() == "<! 不支持的消息类型 !>":
                    group_repeat[group.id] = {
                        "msg": msg.asPersistentString(),
                        "count": -1,
                    }
                    return
                return await app.sendGroupMessage(group, msg.asSendable())
            else:
                group_repeat[group.id]["count"] = count
                return
        else:
            group_repeat[group.id]["msg"] = message_serialization
            group_repeat[group.id]["count"] = 1
 async def handle(app: Ariadne, message: MessageChain, group: Group,
                  member: Member):
     if message.asDisplay().startswith("/fake "):
         content = "".join(i.text for i in message.get(Plain))[6:]
         if not message.has(At):
             return MessageItem(MessageChain.create([Plain(text="未指定目标!")]),
                                Normal())
         sender = message.get(At)[0]
         forward_nodes = [
             ForwardNode(
                 senderId=sender.target,
                 time=datetime.now(),
                 senderName=(await app.getMember(group,
                                                 sender.target)).name,
                 messageChain=MessageChain.create(Plain(text=content)),
             )
         ]
         return MessageItem(
             MessageChain.create(Forward(nodeList=forward_nodes)), Normal())
async def flash_image_catcher(app: Ariadne, message: MessageChain, group: Group):
    if message.has(FlashImage) and await group_setting.get_setting(group.id, Setting.anti_flash_image):
        await app.sendGroupMessage(
            group, MessageChain([Plain(text="FlashImage => Image\n"), message[FlashImage][0].toImage()])
        )