Exemple #1
0
 async def wait_for_chain(chain: MessageChain, i_sender: Member):
     if i_sender.id == sender.id and i_sender.group.id == sender.group.id:
         await chain.download_binary()
         chain = chain.include(Plain, Image)
         if chain:
             if chain.asDisplay() != "取消":
                 id: int = db.add_cave(sender.name, chain)
                 await app.sendMessage(group,
                                       MessageChain([f"添加成功,ID: {id}"]))
         else:
             await app.sendMessage(group, MessageChain(["请发送图片或文本"]))
         return True
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