Exemplo n.º 1
0
def AddAnswerBookListener(bcc: Broadcast):
    bcc.receiver("GroupMessage",
                 headless_decorators=[regexPlain(r"^#神启[\s]*([^\s]*)$")
                                      ])(AnswerBookGroup)
    bcc.receiver("FriendMessage",
                 headless_decorators=[regexPlain(r"^#神启[\s]*([^\s]*)$")
                                      ])(AnswerBookFriend)
    bcc.receiver("TempMessage",
                 headless_decorators=[regexPlain(r"^#神启[\s]*([^\s]*)$")
                                      ])(AnswerBookTemp)
async def GroupUnBlockMember(
        app: GraiaMiraiApplication,
        event: GroupMessage,
        regexResult=regexPlain(r"^#解除拉黑([\s]*[\d]*)*$"),
):
    quoted = event.messageChain.get(Source)
    if not checkMemberPermission(app, event.sender,
                                 [MemberPerm.Administrator, MemberPerm.Owner],
                                 quoted):
        return
    target = re.findall(r"[\d]*", regexResult.match)
    succ = []
    for i in target:
        times = GetMemberStatusFromGrouBlockDB(app, event.sender.group, i,
                                               "Blocked")
        if times == None:
            return
        if not InsertMemberStatusToGroupBlockDB(app, event.sender.group, i,
                                                "Blocked", 0):
            return
        succ.append(i.id)
    await app.sendGroupMessage(
        event.sender.group,
        MessageChain.create([Plain(f"操作完成.解除拉黑的对象为:\n{' '.join(succ)}")]),
    )
Exemplo n.º 3
0
 async def wait(
         wait_event: FriendMessage,
         regexResult=regexPlain(r"^#(同意|拒绝)(?:\s*(?<=\s)(.*)|)$"),
 ):
     quote = wait_event.messageChain.get(Quote)
     if (not quote or wait_event.sender.id != target
             or quote[0].id == botMessage.messageId):
         return None
     return regexResult
async def GroupShowSentence(
        app: GraiaMiraiApplication,
        event: GroupMessage,
        regexResult=regexPlain(r"^#群语录[\s]*([\d][\d]*)$"),
):
    quoted = event.messageChain.get(Source)[0]
    SentenceID = int(regexResult.groups()[0])
    result = GetSentenceFromDBById(app, event.sender.group, SentenceID)
    if result:
        result = StrToMessageChain(result)
    else:
        result = MessageChain.create([Plain(f"ID为{SentenceID}的语录不存在")])
    await app.sendGroupMessage(event.sender.group, result, quote=quoted)
async def GroupDeleteSentence(
        app: GraiaMiraiApplication,
        event: GroupMessage,
        regexResult=regexPlain(r"^#删除语录[\s]*([\d]*)"),
):
    quoted = event.messageChain.get(Source)[0]
    SentenceID = int(regexResult.groups()[0])
    message = GetSentenceFromDBById(app, event.sender.group, SentenceID)
    if message:
        message = StrToMessageChain(message)
    else:
        message = MessageChain.create([])
    if DeleteSentenceById(app, event.sender.group, SentenceID):
        message.__root__.insert(0, Plain("语录删除成功,原内容为:\n"))
    else:
        message.__root__.insert(0, Plain("语录删除失败"))
    await app.sendGroupMessage(event.sender.group, message, quote=quoted)
async def GroupMuteMember(
        app: GraiaMiraiApplication,
        event: GroupMessage,
        regexResult=regexPlain(r"^#禁言[\s]*([\d]*)$"),
):
    sender = event.sender
    group = sender.group
    quoted = event.messageChain.get(Source)[0]
    time = int(regexResult.groups()[0])
    if not await checkMemberPermission(
            app, sender, [MemberPerm.Owner, MemberPerm.Administrator], quoted):
        return
    target = await getTargetFromAt(app, group, event.messageChain)
    for i in target:
        if not await muteMember(app, group, i, time, quoted):
            return
    await app.sendGroupMessage(group,
                               MessageChain.create([Plain("操作完成.")]),
                               quote=quoted)
Exemplo n.º 7
0
async def GroupDeleteAnswer(
    app: GraiaMiraiApplication,
    event: GroupMessage,
    regexResult=regexPlain(r"^#删除进群答案[\s]*([^\s]*)$"),
):
    quoted = event.messageChain.get(Source)[0]
    if not await checkMemberPermission(
        app, event.sender, [MemberPerm.Administrator, MemberPerm.Owner], quoted
    ):
        return
    answer = regexResult.groups()[0]
    if not answer:
        return
    if DeleteFromGroupDB(app, event.sender.group, "GroupAnswer", "Answer", answer):
        await app.sendGroupMessage(
            event.sender.group, MessageChain.create([Plain("答案删除成功")]), quote=quoted
        )
    else:
        await app.sendGroupMessage(
            event.sender.group, MessageChain.create([Plain("答案删除失败")]), quote=quoted
        )