def onGroupMessage(app: MiraiApp, event: GroupMessageEvent): words = ['是的呢', '对', '对的', '说得好', '是这样的', 'TQL', '没错', '嗯', '的确', '确实'] # ret = requests.get('https://chp.shadiao.app/api.php') message = MessageChain.create([Plain(random.choice(words))]) if event.sender.group.id == 667481568: app.sendGroupMessage(target=event.sender.group.id, message=message)
async def fetchMessage(self, count: int) -> T.List[T.Union[FriendMessage, GroupMessage, ExternalEvent]]: result = assertOperatorSuccess( await fetch.http_get(f"{self.baseurl}/fetchMessage", { "sessionKey": self.session_key, "count": count } ), raise_exception=True, return_as_is=True) for index in range(len(result)): # 因为重新生成一个开销太大, 所以就直接在原数据内进行遍历替换 if result[index]['type'] in MessageTypes: # 判断当前项是否为 Message if 'messageChain' in result[index]: # 使用 custom_parse 方法处理消息链 result[index]['messageChain'] = MessageChain.custom_parse(result[index]['messageChain']) result[index] = \ MessageTypes[result[index]['type']].parse_obj(result[index]) elif hasattr(ExternalEvents, result[index]['type']): # 判断当前项是否为 Event result[index] = \ ExternalEvents[result[index]['type']].value.parse_obj(result[index]) return result
def onBotUnmute(app: MiraiApp, event: BotUnmuteEvent): message = MessageChain.create([Plain('嘻嘻我被放出来了')]) group_id = event.operator.group.id app.sendGroupMessage(target=group_id, message=message)
def onFriendMessage(app: MiraiApp, event: FriendMessageEvent): words = ['是的呢', '对', '对的', '说得好', '是这样的', 'TQL', '没错', '嗯', '的确', '确实'] message = MessageChain.create([Plain(random.choice(words))]) sender_id = event.sender.id app.sendFriendMessage(target=sender_id, message=message)
def parse_obj(cls, obj: Dict) -> "GroupMessageEvent": return GroupMessageEvent( messageChain=MessageChain.parse_obj(obj['messageChain']), sender=GroupMessageSender.parse_obj(obj['sender']))
def parse_obj(cls, obj: Dict) -> "FriendMessageEvent": return FriendMessageEvent(messageChain=MessageChain.parse_obj( obj['messageChain']), sender=Friend.parse_obj(obj['sender']))