mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Add] 增加控制台框架以进行本地测试, 或非聊天机器人使用;
This commit is contained in:
parent
e803d2161b
commit
9ce18469e6
@ -7,6 +7,9 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.lamgc.cgj.bot.boot.ApplicationBoot;
|
||||||
|
import net.lamgc.cgj.bot.boot.BotGlobal;
|
||||||
|
import net.lamgc.cgj.bot.framework.cli.ConsoleMain;
|
||||||
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
|
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
|
||||||
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
|
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
|
||||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||||
@ -104,6 +107,11 @@ public class Main {
|
|||||||
main.close();
|
main.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
public static void consoleMode() {
|
||||||
|
ConsoleMain.start();
|
||||||
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
|
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
|
||||||
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
|
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
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 java.util.Scanner;
|
||||||
|
|
||||||
|
public class ConsoleMain {
|
||||||
|
|
||||||
|
public static void start() {
|
||||||
|
MessageSenderBuilder.setCurrentMessageSenderFactory(new ConsoleMessageSenderFactory());
|
||||||
|
ApplicationBoot.initialBot();
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
boolean isGroup = false;
|
||||||
|
do {
|
||||||
|
String input = scanner.nextLine();
|
||||||
|
if(input.equalsIgnoreCase("#exit")) {
|
||||||
|
System.out.println("退出应用...");
|
||||||
|
break;
|
||||||
|
} else if(input.equalsIgnoreCase("#setgroup")) {
|
||||||
|
isGroup = !isGroup;
|
||||||
|
System.out.println("System: 群模式状态已变更: " + isGroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BotEventHandler.executeMessageEvent(new ConsoleMessageEvent(input, isGroup));
|
||||||
|
} while(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package net.lamgc.cgj.bot.framework.cli;
|
||||||
|
|
||||||
|
import net.lamgc.cgj.bot.event.MessageEvent;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class ConsoleMessageEvent extends MessageEvent {
|
||||||
|
|
||||||
|
public ConsoleMessageEvent(String message, boolean isGroup) {
|
||||||
|
super(isGroup ? 1 : 0, 1, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int sendMessage(String message) {
|
||||||
|
System.out.println(new Date() + " Bot: " + message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getImageUrl(String image) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package net.lamgc.cgj.bot.framework.cli;
|
||||||
|
|
||||||
|
import net.lamgc.cgj.bot.message.MessageSender;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class ConsoleMessageSender implements MessageSender {
|
||||||
|
@Override
|
||||||
|
public synchronized int sendMessage(String message) {
|
||||||
|
System.out.println(new Date() + " Bot: " + message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package net.lamgc.cgj.bot.framework.cli;
|
||||||
|
|
||||||
|
import net.lamgc.cgj.bot.message.MessageSender;
|
||||||
|
import net.lamgc.cgj.bot.message.MessageSenderFactory;
|
||||||
|
import net.lamgc.cgj.bot.message.MessageSource;
|
||||||
|
|
||||||
|
public class ConsoleMessageSenderFactory implements MessageSenderFactory {
|
||||||
|
|
||||||
|
private final static ConsoleMessageSender sender = new ConsoleMessageSender();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageSender createMessageSender(MessageSource source, long id) {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user