async def GroupRemoveAdmin(app: GraiaMiraiApplication, event: GroupMessage): quoted = event.messageChain.get(Source)[0] if not await checkMemberPermission( app, event.sender, [MemberPerm.Administrator, MemberPerm.Owner], quoted ): return target = set(map(lambda at: at.target, event.messageChain.get(At))) succ_result = [] fail_result = [] for i in target: if DeleteFromGroupDB(app, event.sender.group, "GroupPermission", "AdminID", i): succ_result.append(At(i)) else: fail_result.append(At(i)) await app.sendGroupMessage( event.sender.group, MessageChain.create( [ Plain("操作完成\n以下成员取消权限成功:\n"), *succ_result, Plain("\n以下成员取消权限失败:\n"), *fail_result, ] ), quote=quoted, )
async def GroupMemberJoin(app: GraiaMiraiApplication, event: MemberJoinEvent): message = GetFromGroupInfoDB(app, event.member.group, "MemberJoinMessage") if not message: message = MessageChain.create([At(event.member.id), Plain("欢迎入群")]) else: message = StrToMessageChain(message) message.__root__.insert(0, At(event.member)) await app.sendGroupMessage(event.member.group, message)
async def Group_Member_Join(app:GraiaMiraiApplication,event:MemberJoinEvent): message=GetFromGroupInfoDB(app,event.member.group,"MemberJoinMessage") if not message: return message=StrToMessageChain(message) message.__root__.insert(0,At(event.member)) await app.sendGroupMessage(event.member.group,message)
async def Group_Member_Sleep(app:GraiaMiraiApplication,event:GroupMessage): quoted=event.messageChain.get(Source)[0] group=event.sender.group startTime=datetime.now() endTime=datetime(startTime.year,startTime.month,startTime.day,7,0,0) if startTime.hour<7: delta=(endTime-startTime).total_seconds() else : delta=24*3600-(startTime-endTime).total_seconds() delta//=60 random.gauss(delta,30.0) target=await getTargetFromAt(app,group,event.messageChain) if not target: target=[event.sender] elif not await checkMemberPermission(app,event.sender,[MemberPerm.Administrator,MemberPerm.Owner],quoted): target=[] for i in target: if not await muteMember(app,group,i,delta,quoted): break await app.sendGroupMessage(group,MessageChain.create([ At(i.id), Plain(f"\n你的睡眠套餐已到账,请查收.\n总时长为{delta}分钟") ]),quote=(quoted if i==event.sender else {}))
async def GroupWarnMember(app:GraiaMiraiApplication,event:GroupMessage): quoted=event.messageChain.get(Source)[0] if not await checkMemberPermission(app,event.sender,[MemberPerm.Administrator,MemberPerm.Owner],quoted): return target=getTargetFromAt(app,event.sender.group,event.messageChain) for i in target: reply=[At(target=i.id)] times=GetMemberStatusFromGrouBlockDB(app,event.sender.group,i,"Warn") if times==None: return times+=1 if not InsertMemberStatusToGroupBlockDB(app,event.sender.group,i,"Warn",times): return if times==1: reply.append(Plain("第一次警告,注意群规.")) elif times==2: reply.append(Plain("第二次警告,注意群规.关小黑屋1天.")) await muteMember(app,event.sender.group,i,24*60,quoted) elif times==3: reply.append(Plain("第三次警告,注意群规.关小黑屋一个月.下次直接飞机票.")) await muteMember(app,event.sender.group,i,30*24*60-1,quoted) elif times==4: reply.append(Plain("第四次警告,飞机票.")) await kickMember(app,event.sender.group,i,quoted) block=GetMemberStatusFromGrouBlockDB(app,event.sender.group,i,"Blocked") if block==None: return block+=1 if not InsertMemberStatusToGroupBlockDB(app,event.sender.group,i,"Blocked",block): return await app.sendGroupMessage(event.sender.group,MessageChain.create(reply)) await app.sendGroupMessage(event.sender.group,MessageChain.create([ Plain("操作完成") ]),quote=quoted)
async def memberjoinevent_listener(app: GraiaMiraiApplication, event: MemberJoinEvent): member = event.member group = member.group if group.id == qq.littleskin_main: await app.sendGroupMessage( group, MessageChain.create([At(member.id), Plain(tF.join_welcome)]))
async def GroupCancelWarnMember(app:GraiaMiraiApplication,event:GroupMessage): qutoed=event.messageChain.get(Source)[0] if not checkMemberPermission(app,event.sender,[MemberPerm.Administrator,MemberPerm.Owner],qutoed): return target=getTargetFromAt(app,event.sender.group,event.messageChain) succ=[] for i in target: if InsertMemberStatusToGroupBlockDB(app,event.sender.group,i,"Warn",0): succ.append(At(i)) await app.sendGroupMessage(event.sender.group,MessageChain.create([ Plain("操作完成.以下成员解除警告:\n"), *succ]))
async def command_ot(app: GraiaMiraiApplication, group: Group, _gm: GroupMessage): M = MessagePro(_gm) atList: List[Optional[At]] = [At(t.target) for t in M.at] if M.at != [] else [] await app.sendGroupMessage( group, MessageChain.create([ Image.fromLocalFile('./images/off-topic.png'), *atList, # 仅在 LittleSkin 主群中启用此文本消息 *([Plain(tF.ot)] if group.id == qq.littleskin_main else []) ]))
async def command_ot(app: GraiaMiraiApplication, group: Group, _gm: GroupMessage): CP = CommandParser(_gm, settings.commandSymbol) atList: List[Optional[At]] = [At(t.target) for t in CP.at] if CP.at != [] else [] await app.sendGroupMessage( group, MessageChain.create([ *atList, Image.fromLocalFile('./images/off-topic.png'), *([Plain(tF.ot)] if group.id == settings.specialqq.littleskin_main else []) # 仅在 LittleSkin 主群中启用此文本消息 ]))
async def memberjoinevent_listener(app: GraiaMiraiApplication, event: MemberJoinEvent): member = event.member group = member.group if group.id == settings.specialqq.littleskin_main: await app.sendGroupMessage( group, MessageChain.create([Plain(tF.constance_refresh_name)])) await app.sendGroupMessage( group, MessageChain.create( [At(member.id), Plain(tF.welcome_to_littleskin)])) elif group.id == settings.specialqq.littleskin_cafe: await app.sendGroupMessage( group, MessageChain.create([Plain(tF.constance_refresh_name)]))
async def Group_Member_Sleep(app: GraiaMiraiApplication, event: GroupMessage): quoted = event.messageChain.get(Source)[0] group = event.sender.group target = await getTargetFromAt(app, group, event.messageChain) if not target: target = [event.sender] elif not await checkMemberPermission( app, event.sender, [MemberPerm.Administrator, MemberPerm.Owner], quoted): target = [] for i in target: delta = GenerateSleepTime() if not await muteMember(app, group, i, delta, quoted): break await app.sendGroupMessage( group, MessageChain.create( [At(i.id), Plain(f"\n你的睡眠套餐已到账,请查收.\n总时长为{delta}分钟")]), quote=(quoted if i == event.sender else {}), )
def test_full_match(full_match_result, event: GroupMessage): print(full_match_result) @bcc.receiver("GroupMessage", dispatchers=[ Kanata([ RegexMatch(r"test regex match:(.*)"), RequireParam("regex_match_result") ], stop_exec_if_fail=True) ]) def test_regex_match(regex_match_result, event: GroupMessage): print("regex match") print(regex_match_result) postGroupMessage( MessageChain.create([Plain("test regex match:2134e"), Face(faceId=123)]), bcc) postGroupMessage( MessageChain.create([ Plain("test full match: "), Face(faceId=12), At(target=987654321), Plain("test full match:dqwoefr") ]), bcc) loop.run_until_complete(asyncio.sleep(10))
async def unmute_notice(app: GraiaApp, group: Group, member: Member = "target"): await app.sendGroupMessage( group, MessageChain.create([At(member.id), Plain("开始学了")]))
async def mute_notice(app: GraiaApp, event: MemberMuteEvent): await app.sendGroupMessage( event.member.group, MessageChain.create([At(event.member.id), Plain("被卷死了")]))
async def group_message_handler(app: GraiaMiraiApplication, message: MessageChain, group: Group, member: Member): if message.asDisplay().startswith("复读"): await app.sendGroupMessage( group, message.create( [At(member.id), Plain(message.exclude(Image).asDisplay())]), quote=message.__root__[0].id) if re.search(r"色图 \d", message.asDisplay()) and (group.id in schedulepermission): setuInd = Universe.get_value("setuInd") setuId = message.asDisplay().split(" ")[1] setuId = eval(setuId) - 1 await app.sendGroupMessage( group, message.create([ Image.fromLocalFile( extraEvent.setuList[setuId % len(extraEvent.setuList)]) ])) await app.sendGroupMessage( group, message.create([Plain("今日发送的第{}份色图".format(setuInd))])) print(extraEvent.setuList[setuInd % len(extraEvent.setuList)]) setuInd += 1 Universe.set_value("setuInd", setuInd) elif re.search(r"好图 \d", message.asDisplay()) and (group.id in schedulepermission): haotuInd = Universe.get_value("haotuInd") haotuId = message.asDisplay().split(" ")[1] haotuId = eval(haotuId) - 1 await app.sendGroupMessage( group, message.create([ Image.fromLocalFile( extraEvent.haotuList[haotuId % len(extraEvent.haotuList)]) ])) await app.sendGroupMessage( group, message.create([Plain("今日发送的第{}份好图".format(haotuInd))])) print(extraEvent.haotuList[haotuInd % len(extraEvent.haotuList)]) haotuInd += 1 Universe.set_value("haotuInd", haotuInd) if message.asDisplay() == "色图一览": print(Universe.get_value("setuScan")) print(os.path.abspath(Universe.get_value("setuScan"))) await app.sendGroupMessage( group, message.create( [Image.fromLocalFile(Universe.get_value("setuScan"))])) elif message.asDisplay() == "好图一览": await app.sendGroupMessage( group, message.create( [Image.fromLocalFile(Universe.get_value("haotuScan"))])) if member.permission is MemberPerm.Owner: if message.asDisplay().startswith("Update"): await app.sendGroupMessage( group, message.create([Plain("开始更新今日色图......")])) threadDaily = threading.Thread(target=extraEvent.DayilyMission, args=(group, 0)) threadDaily.start() elif message.asDisplay().startswith("Init"): await app.sendGroupMessage(group, message.create([Plain("初始化......")])) extraEvent.initNow(app, message, group, loop) elif message.asDisplay() == "图裂了": await app.sendFriendMessage( group, message.create([Plain("正在想办法处理......")])) extraEvent.fixPics(app, message, group, loop) if message.has(Image): #图片保存 # 日常收集图片 savePicLs = message[Image] counter = len(savePicLs) sourceid = message.__root__[0].id #await app.sendGroupMessage(group, message.create([Plain("{}张".format(counter))])) threadPic = threading.Thread(target=extraEvent.savePic, args=(savePicLs, counter, app, sourceid, group, loop)) threadPic.start()
# 计算终点坐标. text_index = None latest_element = message_chain.__root__[-1] if isinstance(latest_element, Plain): text_index = len(latest_element.text) stop_index = (len(message_chain.__root__), text_index) match_result[matching_recevier] = (start_index, stop_index) return match_result if __name__ == "__main__": from graia.ptilopsis.signature import Require from graia.ptilopsis.utilles import silce_chain_stop from devtools import debug from graia.application.entry import At # 这里是测试代码 test_message_chain = MessageChain.create([ Plain("test_matchre_test_argumentafterafter23123312323123231232323"), At(123) ]) test_signature_chain = ( FullMatch("test_match"), Require(name="require_1", isGreed=True), (FullMatch("after"), Require(name="require_2")) ) test_station = Station(test_signature_chain) match_result = test_station.match(test_message_chain) debug(match_result) debug({k: silce_chain_stop(silce_chain_start(test_message_chain, v[0]), v[1]) for k, v in match_result.items()})