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.FriendMessageEvent;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.event.events.GroupTempMessageEvent;
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.Scanner;

@RobotListener
public class sendByConsoleListener extends MessageListener {
    public sendByConsoleListener() {
        super(List.of("呼叫管理"), false);
    }

    @RobotListenerHandler(concurrency = true)//收到好友消息后，通过控制台给好友发一条消息
    public void sendMessageToFriend(FriendMessageEvent event) {
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();//控制台输入
        event.getFriend().sendMessage(str);//发送到群聊
        System.out.println("机器人发送：" + str);
    }

    @RobotListenerHandler(contactId = {518909220, 1033597003}, concurrency = true)//当有人消息中带有“呼叫bot”时，可以从控制台输入一条消息发送
    public void sendMessageToGroup(GroupMessageEvent event) {
        String message = event.getMessage().contentToString();
        if (this.invalidText(message)) {
            Scanner input = new Scanner(System.in);
            String str = input.nextLine();
            MessageChain chain = new MessageChainBuilder()
                    .append(new At(event.getSender().getId()))
                    .append(" " + str)
                    .build();
            event.getGroup().sendMessage(chain);
            System.out.println("机器人发送：" + chain);
        }
    }

    @RobotListenerHandler(concurrency = true)
    public void sendMessageToStranger(GroupTempMessageEvent event) {
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        event.getSender().sendMessage(str);
        System.out.println("机器人发送：" + str);
    }
}
