package com.mtz.qqbot.Listener;

import com.mtz.qqbot.Tool.invalidMember;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RobotListener
public class RecallMessageListener extends MessageListener {
    public static int group1InvalidCount = 0;
    public static int group2InvalidCount = 0;

    public Map<Long, Integer> group1MemberInvalidedCountList = new HashMap<Long, Integer>();
    public static List<Long> group1InvalidMember = new ArrayList<Long>();
    public Map<Long, Integer> group2MemberInvalidedCountList = new HashMap<Long, Integer>();
    public static List<Long> group2InvalidMember = new ArrayList<Long>();

    public RecallMessageListener() {
        super(List.of("原神", "OP"), true);//自定义违禁词
    }

    public void recall(GroupMessageEvent event) throws InterruptedException {//当有人发违禁词自动撤回并禁言一分钟
        String message = event.getMessage().contentToString();
        if (this.invalidText(message)) {
//            event.getSender().mute(60);//禁言60秒
            Thread.sleep(500);//半秒后撤回方便演示
            this.recallMessage(event.getMessage());
        }
    }

    @RobotListenerHandler(contactId = 518909220)//监控增加群聊1
    public void recallGroup1Message(GroupMessageEvent event) throws InterruptedException {
        recall(event);
        group1InvalidCount++;
        invalidMember.invalidCountList(group1MemberInvalidedCountList, event);
        invalidMember.invalidMemberList(group1InvalidMember, group1MemberInvalidedCountList, event);
    }

    @RobotListenerHandler(contactId = 1033597003)//监控增加群聊2
    public void recallGroup2Message(GroupMessageEvent event) throws InterruptedException {
        recall(event);
        group2InvalidCount++;
        invalidMember.invalidCountList(group2MemberInvalidedCountList, event);
        invalidMember.invalidMemberList(group2InvalidMember, group2MemberInvalidedCountList, event);
    }
}
