mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-08-21 13:57:25 +00:00
[Add] pom.xml 增加JLine库;
[Update] ConsoleMain 增强Cli使用体验; [Add] BotEventHandler 增加同步执行命令的方法'executeMessageEvent(MessageEvent, boolean)'; [Change] Main 适配ConsoleMain的更改;
This commit is contained in:
5
pom.xml
5
pom.xml
@ -179,6 +179,11 @@
|
|||||||
<artifactId>gifencoder</artifactId>
|
<artifactId>gifencoder</artifactId>
|
||||||
<version>0.10.1</version>
|
<version>0.10.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jline</groupId>
|
||||||
|
<artifactId>jline</artifactId>
|
||||||
|
<version>3.15.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -93,7 +93,7 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
public static void consoleMode() {
|
public static void consoleMode() throws IOException {
|
||||||
ConsoleMain.start();
|
ConsoleMain.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,20 +120,38 @@ public class BotEventHandler implements EventHandler {
|
|||||||
*/
|
*/
|
||||||
@NotAccepted
|
@NotAccepted
|
||||||
public static void executeMessageEvent(MessageEvent event) {
|
public static void executeMessageEvent(MessageEvent event) {
|
||||||
|
try {
|
||||||
|
executeMessageEvent(event, false);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("执行时发生异常", e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投递消息事件
|
||||||
|
* @param event 事件对象
|
||||||
|
*/
|
||||||
|
@NotAccepted
|
||||||
|
public static void executeMessageEvent(MessageEvent event, boolean sync) throws InterruptedException {
|
||||||
String debuggerName = SettingProperties.getProperty(0, "debug.debugger");
|
String debuggerName = SettingProperties.getProperty(0, "debug.debugger");
|
||||||
if(!event.getMessage().startsWith(ADMIN_COMMAND_PREFIX) &&
|
if(!event.getMessage().startsWith(ADMIN_COMMAND_PREFIX) &&
|
||||||
!Strings.isNullOrEmpty(debuggerName)) {
|
!Strings.isNullOrEmpty(debuggerName)) {
|
||||||
try {
|
try {
|
||||||
MessageEventExecutionDebugger debugger = MessageEventExecutionDebugger.valueOf(debuggerName.toUpperCase());
|
MessageEventExecutionDebugger debugger = MessageEventExecutionDebugger.valueOf(debuggerName.toUpperCase());
|
||||||
debugger.debugger.accept(executor, event, SettingProperties.getProperties(SettingProperties.GLOBAL),
|
debugger.debugger.accept(executor, event, SettingProperties.getProperties(SettingProperties.GLOBAL),
|
||||||
MessageEventExecutionDebugger.getDebuggerLogger(debugger));
|
MessageEventExecutionDebugger.getDebuggerLogger(debugger));
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
log.warn("未找到指定调试器: '{}'", debuggerName);
|
log.warn("未找到指定调试器: '{}'", debuggerName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("事件调试处理时发生异常", e);
|
log.error("事件调试处理时发生异常", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
BotEventHandler.executor.executor(event);
|
if(sync) {
|
||||||
|
BotEventHandler.executor.executorSync(event);
|
||||||
|
} else {
|
||||||
|
BotEventHandler.executor.executor(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,22 +3,36 @@ package net.lamgc.cgj.bot.framework.cli;
|
|||||||
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
||||||
import net.lamgc.cgj.bot.event.BotEventHandler;
|
import net.lamgc.cgj.bot.event.BotEventHandler;
|
||||||
import net.lamgc.cgj.bot.message.MessageSenderBuilder;
|
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 class ConsoleMain {
|
||||||
|
|
||||||
public static void start() {
|
private final static Logger log = LoggerFactory.getLogger(ConsoleMain.class);
|
||||||
MessageSenderBuilder.setCurrentMessageSenderFactory(new ConsoleMessageSenderFactory());
|
|
||||||
|
public static void start() throws IOException {
|
||||||
|
ConsoleMessageSenderFactory senderFactory = new ConsoleMessageSenderFactory();
|
||||||
|
MessageSenderBuilder.setCurrentMessageSenderFactory(senderFactory);
|
||||||
ApplicationBoot.initialBot();
|
ApplicationBoot.initialBot();
|
||||||
Scanner scanner = new Scanner(System.in);
|
LineReader lineReader = LineReaderBuilder.builder()
|
||||||
System.out.print("会话QQ:");
|
.appName("CGJ")
|
||||||
long qqId = scanner.nextLong();
|
.history(new DefaultHistory())
|
||||||
System.out.print("会话群组号:");
|
.terminal(TerminalBuilder.builder()
|
||||||
long groupId = scanner.nextLong();
|
.dumb(true)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
long qqId = Long.parseLong(lineReader.readLine("会话QQ: "));
|
||||||
|
long groupId = Long.parseLong(lineReader.readLine("会话群组号:"));
|
||||||
boolean isGroup = false;
|
boolean isGroup = false;
|
||||||
do {
|
do {
|
||||||
String input = scanner.nextLine();
|
String input = lineReader.readLine("App " + qqId + (isGroup ? "@" + groupId : "$private") + " >");
|
||||||
if(input.equalsIgnoreCase("#exit")) {
|
if(input.equalsIgnoreCase("#exit")) {
|
||||||
System.out.println("退出应用...");
|
System.out.println("退出应用...");
|
||||||
break;
|
break;
|
||||||
@ -27,7 +41,11 @@ public class ConsoleMain {
|
|||||||
System.out.println("System: 群模式状态已变更: " + isGroup);
|
System.out.println("System: 群模式状态已变更: " + isGroup);
|
||||||
continue;
|
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);
|
} while(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user