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.At;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;

import java.util.List;
import java.util.Random;

@RobotListener
public class fishListener extends MessageListener {
    public static int fishCount = 0;
    String[] fishes = {"鲨鱼", "金龙鱼", "鲤鱼", "鲫鱼", "鲅鱼", "罗非鱼", "鲸鱼", "闲鱼", ""};

    public fishListener() {
        super(List.of("钓鱼"), true);
    }

    @RobotListenerHandler(order = 1)
    public void fishing(GroupMessageEvent event) throws InterruptedException {
        Random random = new Random();

        String message = event.getMessage().contentToString();
        if (this.invalidText(message)) {
            MessageChain chain = new MessageChainBuilder()
                    .append(new At(event.getSender().getId()))
                    .append(" 开始钓鱼，10秒后收杆")
                    .build();
            event.getGroup().sendMessage(chain);//发送消息到群聊
            System.out.println(chain);
            Thread.sleep(10000);
            int whichFish = random.nextInt(fishes.length);
            if (whichFish == fishes.length - 1) {
                chain = new MessageChainBuilder()
                        .append(new At(event.getSender().getId()))
                        .append(" 你空军了！")
                        .build();
                event.getGroup().sendMessage(chain);
                System.out.println(chain);
            } else {
                chain = new MessageChainBuilder()
                        .append(new At(event.getSender().getId()))
                        .append(" 你钓上来了一条" + fishes[whichFish])
                        .build();
                event.getGroup().sendMessage(chain);//发送消息到群聊
                System.out.println(chain);
            }
            fishCount++;
        }
    }
}
