76 lines
2.8 KiB
Java
76 lines
2.8 KiB
Java
package plugin;
|
|
|
|
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
|
|
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
|
|
import net.mamoe.mirai.event.GlobalEventChannel;
|
|
import net.mamoe.mirai.event.events.FriendMessageEvent;
|
|
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
|
import net.mamoe.mirai.utils.MiraiLogger;
|
|
import plugin.constant.ChatConstant;
|
|
import plugin.listener.FriendMessageListener;
|
|
import plugin.listener.GroupMessageListener;
|
|
import plugin.listener.OwnerMessageListener;
|
|
import plugin.pojo.Config;
|
|
import plugin.utils.ConfigUtil;
|
|
|
|
import java.io.IOException;
|
|
import java.util.HashMap;
|
|
|
|
|
|
public final class App extends JavaPlugin {
|
|
public static final App INSTANCE = new App();
|
|
private String owner, bot;
|
|
private static HashMap<String,String> customCommands;
|
|
|
|
private App() {
|
|
super(new JvmPluginDescriptionBuilder("com.plugin.chatAI-InGroup-v2", "0.1.0")
|
|
.name("ChatAI-InGroup-v2")
|
|
.author("SLHAF")
|
|
.build());
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
//加载配置
|
|
try {
|
|
ConfigUtil.load();
|
|
Thread.sleep(1500);
|
|
Config config = ConfigUtil.getConfig();
|
|
owner = config.getOwner().substring(1);
|
|
bot = config.getBot().substring(1);
|
|
customCommands = config.getCustomCommands();
|
|
|
|
} catch (IOException | ClassNotFoundException | InterruptedException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
getLogger().info("ChatAI-InGroup-v2 loaded!");
|
|
|
|
|
|
//群聊监听器
|
|
GlobalEventChannel.INSTANCE.filterIsInstance(GroupMessageEvent.class)
|
|
.filter(event -> {
|
|
String msg = event.getMessage().contentToString();
|
|
return (msg.startsWith(".") && msg.length() != 1) || msg.startsWith("@"+bot) || customCommands.containsKey(msg.split(" ")[0]);
|
|
}).registerListenerHost(new GroupMessageListener());
|
|
|
|
//所有者监听
|
|
GlobalEventChannel.INSTANCE.filterIsInstance(GroupMessageEvent.class)
|
|
.filter(event -> {
|
|
String msg = event.getMessage().contentToString();
|
|
String sender = String.valueOf(event.getSender().getId());
|
|
return msg.startsWith(ChatConstant.SET) && sender.equals(owner);
|
|
}).registerListenerHost(new OwnerMessageListener());
|
|
|
|
//私聊监听器
|
|
GlobalEventChannel.INSTANCE.filterIsInstance(FriendMessageEvent.class)
|
|
.filter(event -> true)
|
|
.registerListenerHost(new FriendMessageListener());
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
getLogger().info("ChatAI-InGroup-v2 disabled!");
|
|
}
|
|
} |