def run(self): @self.bcc.receiver(GroupMessage, headless_decoraters=[Depend(self.atOrQuoteFilter)]) async def groupAtOrQuoteHandler(app: Slave, message: GroupMessage): await self.atOrQuoteHandler(app, message) @self.bcc.receiver(GroupMessage, headless_decoraters=[Depend(self.cmdFilter)]) async def groupCmdHandler(app: Slave, message: GroupMessage): await self.commandHandler(app, message) @self.bcc.receiver(GroupMessage) async def groupMessageHandler(app: Slave, message: GroupMessage): await self.shutTheFuckUp(app, message) if self.Economy: add = 0 if images := message.messageChain.get(Image): image: Image for image in images: by: bytes = await request(url=image.url) add += 1 if len(by) > 100000 else 0 else: add += 1 if random.randint(0, 10) < 2 else 0 if add: for _ in range(0, add): await self.Economy.Economy.addMoney( message.sender.id, 5) await self.Economy.Economy.addValue(5) await self.Economy.Economy.trySave()
def __init__(self, tag: str, settings: dict, bcc: Broadcast): self.tag = tag self.settings = settings def judge_friend_message_depend_target(app: GraiaMiraiApplication, friend: Friend, message: MessageChain): self.judge(app, friend, message) @bcc.receiver( FriendMessage, headless_decoraters=[Depend(judge_friend_message_depend_target)]) async def on_receive_friend_message(app: GraiaMiraiApplication, friend: Friend, message: MessageChain): await self.on_receive(app, friend, message) def judge_group_message_depend_target(app: GraiaMiraiApplication, group: Group, message: MessageChain): self.judge(app, group, message) @bcc.receiver( GroupMessage, headless_decoraters=[Depend(judge_group_message_depend_target)]) async def on_receive_group_message(app: GraiaMiraiApplication, group: Group, message: MessageChain): await self.on_receive(app, group, message)
def run(self): @self.bcc.receiver(GroupMessage, headless_decoraters=[Depend(self.cmdFilter)]) async def groupCmdHandler(app: Slave, message: GroupMessage): await self.commandHandler(app, message) @self.bcc.receiver(FriendMessage, headless_decoraters=[Depend(self.quoteFilter)]) async def groupCmdHandler(app: Slave, message: FriendMessage): await self.quoteHandler(app, message)
def run(self): @self.bcc.receiver(GroupMessage, headless_decoraters=[Depend(self.cmdFilter)]) async def groupCmdHandler(app: Slave, message: GroupMessage): commands = message.messageChain.asDisplay().split(' ') await self.MSGDeaHandler(app, message, commands) await self.RipperHandler(app, message, commands) @self.bcc.receiver(GroupMessage, headless_decoraters=[Depend(self.quoteFilter)]) async def groupQuoteHandler(app: Slave, message: GroupMessage): await self.PicDeaHandler(app, message)
def inGroups(*groupsList: Tuple[int]) -> Callable: groups = list(groupsList) def wrapper(event: MemberJoinRequestEvent) -> None: if not event.groupId in groups: raise ExecutionStop() return Depend(wrapper)
async def Group_Ask_Daanshu(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(regexPlain(r"^#神启[\s]*([^\s]*)$"))): queted=event.messageChain.get(Source)[0] question=regexResult.groups()[0] if not question: return await app.sendGroupMessage(event.sender.group,MessageChain.create([ Plain(await AskDaanshu(question)) ]),quote=queted)
async def GroupNeteaseMusic(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(regexPlain(r'^#网易云音乐[\s]*(.*)$'))): quoted=event.messageChain.get(Source)[0] key=regexResult.groups()[0].strip() if not key: return content,jumpUrl,songUrl=await SearchSongsInNeteaseCloudMusic(key) await app.sendGroupMessage(event.sender.group,MessageChain.create([ Plain(f"歌曲链接: {jumpUrl}\n音乐链接: {songUrl}"), App(content=content) ]),quote=quoted)
async def GroupShowSentence(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(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 Group_Mute_Member(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(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)
async def GroupDeleteAnswer(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(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)
event: MemberCardChangeEvent): member = event.member group = member.group GP = groupPermissions(member.id) # 防止滥用 if GP.isBlocked(): return None if group.id in [ settings.specialqq.littleskin_main, settings.specialqq.littleskin_cafe, settings.specialqq.csl_group ]: await app.sendGroupMessage( group, MessageChain.create([Plain(tF.constance_refresh_name)])) # 指令监听 @bcc.receiver(GroupMessage, headless_decoraters=[Depend(onCommand('help'))]) async def command_help(app: GraiaMiraiApplication, group: Group): await app.sendGroupMessage(group, MessageChain.create([Plain(tF.help)])) @bcc.receiver(GroupMessage, headless_decoraters=[Depend(onCommand('manual'))]) async def command_manual(app: GraiaMiraiApplication, group: Group): await app.sendGroupMessage( group, MessageChain.create( [Image.fromLocalFile('./images/rtfm.png'), Plain(tF.manual)])) @bcc.receiver(GroupMessage, headless_decoraters=[Depend(onCommand('faq'))]) async def command_faq(app: GraiaMiraiApplication, group: Group):
if group.id in WelcomeScence: talk = WelcomeScence[group.id] else: talk = "欢迎小可爱来到本群" await app.sendGroupMessage( group, MessageChain.create([Plain(talk), At(event.member.id)])) ''' 修改群迎新词 ''' @bcc.receiver('GroupMessage', headless_decoraters=[Depend(judge_depend_target)]) async def changeWelcome(message: GroupMessage, group: Group): if not parser(message, "修改迎新词 "): return if not message.messageChain.has(Plain): return plain = message.messageChain.get(Plain) txt = plain[0].text.replace("修改迎新词 ", "") if len(txt) > 0: WelcomeScence[group.id] = txt status = "修改成功" else: status = "修改失败,不合法!" await app.sendGroupMessage(group, MessageChain.create([Plain(status)]))
return func1 def generator(num): async def func2(message: MessageChain, event: GroupMessage): print(f"In listener:{num}") #if(num>90000): return func2 for _ in range(30): bcc.receiver("GroupMessage", headless_decoraters=[ Depend(warpper(random.randint(0, 10000))) ])(generator(random.randint(0, 100000))) print("reciver added") async def main(): for _ in range(100000): group = GroupMessage(messageChain=MessageChain.create( [Plain(f"test{random.randint(0,1000000)}")]), sender=Member(id=123456, memberName="tempNember", permission=MemberPerm.Member, group=Group( id=123456789, name="tempGroup", permission=MemberPerm.Member)))
async def GroupDeleteMessage(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(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)
from autoreply import QQButtonAutoReply,GenerateAutoReplyButton loop=asyncio.get_event_loop() bcc=Broadcast(loop=loop) app=GraiaMiraiApplication( broadcast=bcc, connect_info=connection_config(), enable_chat_log=False ) @bcc.receiver(ApplicationLaunched) async def InitDataBase(app:GraiaMiraiApplication): await InitGroupDataBase(app) @bcc.receiver("GroupMessage",headless_decoraters=[Depend(strictPlainCommand('#睡眠套餐'))]) 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]
async def Group_UnMute_Member(app:GraiaMiraiApplication,event:GroupMessage,regexResult=Depend(strictPlainCommand("#解除禁言"))): quoted=event.messageChain.get(Source)[0] if not await checkMemberPermission(app,event.sender,[MemberPerm.Owner,MemberPerm.Administrator],quoted): return target =await getTargetFromAt(app,event.sender.group,event.messageChain) for i in target: if not await unMuteMember(app,event.sender.group,i,quoted): return await app.sendGroupMessage(event.sender.group,MessageChain.create([ Plain("操作完成.") ]),quote=quoted)
import asyncio loop=asyncio.get_event_loop() bcc=Broadcast(loop=loop) def warpper(num): def func1(message:MessageChain): if(num<9000): raise ExecutionStop() print(f"In headless:{num}") return func1 def generator(num): async def func2(message:MessageChain,event:GroupMessage): print(f"In listener:{num}") #if(num>90000): return func2 for _ in range(30): bcc.receiver("GroupMessage",headless_decoraters=[Depend(warpper(random.randint(0,10000)))])(generator(random.randint(0,100000))) print("reciver added") async def main(): for _ in range(60000): group=GroupMessage( messageChain=MessageChain.create([Plain(f"test{random.randint(0,1000000)}")]), sender=Member( id=123456, memberName="tempNember", permission=MemberPerm.Member, group=Group( id=123456789, name="tempGroup", permission=MemberPerm.Member ) )