[Add] pom.xml 增加JLine库;

[Update] ConsoleMain 增强Cli使用体验;
[Add] BotEventHandler 增加同步执行命令的方法'executeMessageEvent(MessageEvent, boolean)';
[Change] Main 适配ConsoleMain的更改;
This commit is contained in:
2020-06-09 09:50:16 +08:00
parent 6789b5b7c5
commit 438d0a95d3
4 changed files with 54 additions and 13 deletions

View File

@ -3,22 +3,36 @@ package net.lamgc.cgj.bot.framework.cli;
import net.lamgc.cgj.bot.boot.ApplicationBoot;
import net.lamgc.cgj.bot.event.BotEventHandler;
import net.lamgc.cgj.bot.message.MessageSenderBuilder;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.impl.history.DefaultHistory;
import org.jline.terminal.TerminalBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Scanner;
import java.io.IOException;
public class ConsoleMain {
public static void start() {
MessageSenderBuilder.setCurrentMessageSenderFactory(new ConsoleMessageSenderFactory());
private final static Logger log = LoggerFactory.getLogger(ConsoleMain.class);
public static void start() throws IOException {
ConsoleMessageSenderFactory senderFactory = new ConsoleMessageSenderFactory();
MessageSenderBuilder.setCurrentMessageSenderFactory(senderFactory);
ApplicationBoot.initialBot();
Scanner scanner = new Scanner(System.in);
System.out.print("会话QQ:");
long qqId = scanner.nextLong();
System.out.print("会话群组号:");
long groupId = scanner.nextLong();
LineReader lineReader = LineReaderBuilder.builder()
.appName("CGJ")
.history(new DefaultHistory())
.terminal(TerminalBuilder.builder()
.dumb(true)
.build())
.build();
long qqId = Long.parseLong(lineReader.readLine("会话QQ: "));
long groupId = Long.parseLong(lineReader.readLine("会话群组号:"));
boolean isGroup = false;
do {
String input = scanner.nextLine();
String input = lineReader.readLine("App " + qqId + (isGroup ? "@" + groupId : "$private") + " >");
if(input.equalsIgnoreCase("#exit")) {
System.out.println("退出应用...");
break;
@ -27,7 +41,11 @@ public class ConsoleMain {
System.out.println("System: 群模式状态已变更: " + isGroup);
continue;
}
BotEventHandler.executeMessageEvent(new ConsoleMessageEvent(isGroup ? groupId : 0, qqId, input));
try {
BotEventHandler.executeMessageEvent(new ConsoleMessageEvent(isGroup ? groupId : 0, qqId, input), true);
} catch (InterruptedException e) {
log.error("执行时发生中断", e);
}
} while(true);
}