package com.mtz.qqbot.Listener;

import net.itbaima.robot.event.RobotListener;
import net.itbaima.robot.event.RobotListenerHandler;
import net.itbaima.robot.listener.MessageListener;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.*;

import java.util.List;

@RobotListener//群聊里发关键词,bot自动艾特并回复
public class ReceiveGroupListener extends MessageListener {
    public static int receiveCount = 0;

    public ReceiveGroupListener() {
        super(List.of("111"), false);//自定义关键词
    }

    @RobotListenerHandler(contactId = {518909220, 1033597003})
    public void receive(GroupMessageEvent event) {
        String message = event.getMessage().contentToString();
        if (this.invalidText(message)) {//当检测到关键词
            MessageChain chain = new MessageChainBuilder()//此为固定写法
                    .append(new At(event.getSender().getId()))//自动艾特
                    .append(new PlainText(" 你好，"))
                    .append(new PlainText("请问有什么可以帮到你"))
                    .build();
            //上面的代码构建了一个MessageChain集合，用来储存要发送的内容
            event.getGroup().sendMessage(chain);//发送消息到群聊
            System.out.println(chain);
            receiveCount++;
        }
    }
}
