Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 provide model to access qq bot check #45

Merged
merged 6 commits into from
Feb 7, 2025
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fun.blue_millennium.commands;

import fun.blue_millennium.commands.execute.othercommands.sub.report.Report;
import fun.blue_millennium.commands.execute.othercommands.sub.report.ReportQuery;
import org.bukkit.plugin.java.JavaPlugin;

public class CommandManager {
Expand Down Expand Up @@ -33,9 +35,9 @@ public static void registerCommand(JavaPlugin plugin) {
plugin.getCommand("link").setExecutor(new fun.blue_millennium.commands.execute.othercommands.sub.data.Bind());
plugin.getCommand("link").setTabCompleter(new fun.blue_millennium.commands.tab.othercommands.sub.Link());

plugin.getCommand("query-report").setExecutor(new fun.blue_millennium.commands.execute.othercommands.sub.ReportQuery());
plugin.getCommand("query-report").setExecutor(new ReportQuery());

plugin.getCommand("report").setExecutor(new fun.blue_millennium.commands.execute.othercommands.sub.Report());
plugin.getCommand("report").setExecutor(new Report());
plugin.getCommand("report").setTabCompleter(new fun.blue_millennium.commands.tab.othercommands.sub.Report());

plugin.getCommand("rcon").setExecutor(new fun.blue_millennium.commands.execute.othercommands.sub.Rcon());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fun.blue_millennium.commands.execute.othercommands;

import fun.blue_millennium.commands.execute.othercommands.sub.*;
import fun.blue_millennium.commands.execute.othercommands.sub.report.Report;
import fun.blue_millennium.commands.execute.othercommands.sub.report.ReportQuery;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class DataQueryByQQ implements CommandExecutor {

public static long LongProcess(CommandSender sender, String[] args) {
long long_num = 0;
long long_num;
try {
long_num = Long.parseLong(args[0]);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.blue_millennium.commands.execute.othercommands.sub;
package fun.blue_millennium.commands.execute.othercommands.sub.report;

import fun.blue_millennium.Main;
import fun.blue_millennium.config.Config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fun.blue_millennium.commands.execute.othercommands.sub;
package fun.blue_millennium.commands.execute.othercommands.sub.report;

import fun.blue_millennium.data.Report.ReportDataActions;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void BanMessage(String message) {
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (Config.UnionBanEnabled) {
if (!sender.isOp()) {
sender.sendMessage("您没有权限这么做");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void TransferToUnionPardon(String playerName, CommandSender sender
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (Config.UnionBanEnabled) {
if (!sender.isOp()) {
sender.sendMessage("您没有权限这么做");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fun/blue_millennium/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DataManager {
public ArrayList<Data> DATA_LIST = new ArrayList<>();

public void load() {
try (JsonReader jsonReader = new JsonReader(new FileReader(Main.INSTANCE.DATA_FILE))) {
try (JsonReader jsonReader = new JsonReader(new FileReader(Main.DATA_FILE))) {
DATA_LIST = new Gson().fromJson(jsonReader, new TypeToken<ArrayList<Data>>() {
}.getType());

Expand All @@ -38,7 +38,7 @@ public void load() {

public void save() {
try {
FileWriter fileWriter = new FileWriter(Main.INSTANCE.DATA_FILE);
FileWriter fileWriter = new FileWriter(Main.DATA_FILE);
fileWriter.write(new Gson().toJson(DATA_LIST));
fileWriter.close();
} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void reportCharmProcess(String message) {
int firstColumnWidth = 30; // 第一列宽度
int otherColumnWidth = 200; // 其他列宽度
int width = 0;
int height = 0;
int height;

// 计算最大宽度
for (String line : lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class ReportDataManager {
* @param data 新的数据行
*/
public void appendDataToCsv(List<String> data) {
ReportDataActions writer = new ReportDataActions();
writer.writeNewData(data);
ReportDataActions.writeNewData(data);
}

public void ProcessData(@NotNull CommandSender sender, @NotNull String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public static void checkBanData() {


public static class BanPair<T1, T2, T3, T4> {
private T1 uuid;
private T2 reason;
private T3 time;
private final T1 uuid;
private final T2 reason;
private final T3 time;
private T4 sourceServer;

public BanPair(T1 uuid, T2 reason, T3 time, T4 sourceServer) {
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/fun/blue_millennium/message/ImageProcess.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package fun.blue_millennium.message;

import fun.blue_millennium.Main;
import fun.blue_millennium.config.Config;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.bukkit.Bukkit;

import static fun.blue_millennium.rcon.RconCommandExecute.executeRconCommand;

/**
* @author Suisuroru
* Date: 2024/10/3 21:58
Expand All @@ -22,16 +18,26 @@ public static String getImageUrl(Image message) {
return imageurl;
}

public static void sendImageUrl(Image message, GroupMessageEvent event) {
public static String sendImageUrl(Image message) {
String value = null;
try {
String imageurl = getImageUrl(message);
value = processImageUrl(imageurl);
} catch (Exception e) {
Main.INSTANCE.getServer().broadcastMessage("一个错误发生于Chamomile内部,图片无法被展示,请前往控制台查看");
}
return value;
}

public static String processImageUrl(String imageurl) {
try {
MessageChainBuilder builder = new MessageChainBuilder();
builder.append("[[CICode,url=").append(imageurl).append("]]");
// mohist端BUG导致,使用tellraw代替直接发送
String command = "tellraw @a \"" + Config.SayQQMessage.replace("%NAME%", event.getSenderName()).replace("%MESSAGE%", builder.build().contentToString()) + "\"";
executeRconCommand(Config.RconIP, Config.RconPort, Config.RconPassword, command);
Bukkit.getLogger().info("Processed image " + imageurl);
return builder.build().contentToString();
} catch (Exception e) {
Main.INSTANCE.getServer().broadcastMessage("一个错误发生于Chamomile内部,图片无法被展示,请前往控制台查看");
}
return imageurl;
}
}
23 changes: 16 additions & 7 deletions src/main/java/fun/blue_millennium/module/impl/QQCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ public QQCheck() {

public static void GroupCheck(GroupMessageEvent event, MessageChainBuilder builder) {
if (Config.QQCheckEnabled) {
boolean tag = false;
if (builder.build().contentToString().replace(" ", "").replace(Config.QQCheckStartWord, "").equals("test")) {
MessageChainBuilder checkMessage;
checkMessage = new MessageChainBuilder()
.append("Your account was linked!").append("\n")
.append("Player Name: ").append("test").append("\n")
.append("Linked UserID: ").append("ed0da36d-5cd6-4eb1-8fdb-33823927d2fc").append("\n")
.append("Linked Time: ").append(TimeUtil.getNowTime());
event.getGroup().sendMessage(checkMessage.build());
}
boolean check_tag = false;
DataGet dp = new DataGet();
List<PlayerData> pdl = dp.getPlayerDataByUserID(event.getSender().getId());
List<MessageChainBuilder> builderList = new java.util.ArrayList<>(List.of());
for (PlayerData pd : pdl) {
if (Bukkit.getServer().getOperators().contains(Bukkit.getPlayer(pd.playerUuid))) {
tag = true;
check_tag = true;
builderList.add(BuildMessage(event, pd.playerName));
}
}
if (tag) {
if (check_tag) {
MessageChainBuilder finalBuilder = new MessageChainBuilder();
for (MessageChainBuilder txt : builderList) {
finalBuilder.add("-----------------\n");
Expand All @@ -57,7 +66,7 @@ public static void GroupCheck(GroupMessageEvent event, MessageChainBuilder build
finalBuilder.add("-----------------\n");
event.getGroup().sendMessage(finalBuilder.build());
} else {
int code = -1;
int code;
try {
code = Integer.parseInt(builder.build().contentToString().replace(" ", "").replace(Config.QQCheckStartWord, ""));
} catch (Exception exception) {
Expand Down Expand Up @@ -119,13 +128,13 @@ public static Data NullCheck(Data data) {

@Override
public void onEnable() {
Main.INSTANCE.eventChannel.subscribeAlways(NewFriendRequestEvent.class, NewFriendRequestEvent::accept);
Main.eventChannel.subscribeAlways(NewFriendRequestEvent.class, NewFriendRequestEvent::accept);

Main.INSTANCE.eventChannel.subscribeAlways(FriendMessageEvent.class, event -> {
Main.eventChannel.subscribeAlways(FriendMessageEvent.class, event -> {
String message = event.getMessage().contentToString();

if (Config.QQCheckEnabled) {
int code = -1;
int code;
try {
code = Integer.parseInt(message);
} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* function: Check message if need rcon function
*/
public class RconPreCheck extends Module implements Listener {
private List<Long> EnabledGroups = new ArrayList<>();
private final List<Long> EnabledGroups = new ArrayList<>();

public RconPreCheck() {
super("DirectConsoleCommandCheck");
Expand Down Expand Up @@ -63,7 +63,7 @@ public void onEnable() {
return;
}
}
Main.INSTANCE.eventChannel.subscribeAlways(GroupMessageEvent.class, event -> {
Main.eventChannel.subscribeAlways(GroupMessageEvent.class, event -> {
if (!Config.RconEnabled || !EnabledGroups.contains(event.getGroup().getId())) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onLoad() {
public void onEnable() {
if (!Config.QQRobotEnabled) {
try {
reportGroup = Main.INSTANCE.BOT.getGroup(Config.ReportGroup);
reportGroup = Main.BOT.getGroup(Config.ReportGroup);
} catch (Exception e) {
LOGGER.warning("Failed to get report group");
}
Expand Down
47 changes: 39 additions & 8 deletions src/main/java/fun/blue_millennium/module/impl/SyncChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import fun.blue_millennium.Main;
import fun.blue_millennium.config.Config;
import fun.blue_millennium.data.AuthData.DataGet;
import fun.blue_millennium.data.PlayerData;
import fun.blue_millennium.module.Module;
import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.event.events.GroupMessageEvent;
Expand All @@ -12,8 +14,12 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import java.util.List;

import static fun.blue_millennium.Main.LOGGER;
import static fun.blue_millennium.message.ImageProcess.processImageUrl;
import static fun.blue_millennium.message.ImageProcess.sendImageUrl;
import static fun.blue_millennium.rcon.RconCommandExecute.executeRconCommand;

public class SyncChat extends Module implements Listener {
private Group syncGroup = null;
Expand All @@ -24,7 +30,7 @@ public SyncChat() {

@Override
public void onEnable() {
syncGroup = Main.INSTANCE.BOT.getGroup(Config.SyncChatGroup);
syncGroup = Main.BOT.getGroup(Config.SyncChatGroup);

if (!Config.BotModeOfficial) {
if (syncGroup == null) {
Expand All @@ -35,7 +41,7 @@ public void onEnable() {
}
}

Main.INSTANCE.eventChannel.subscribeAlways(GroupMessageEvent.class, event -> {
Main.eventChannel.subscribeAlways(GroupMessageEvent.class, event -> {
if (!Config.BotModeOfficial & (!Config.SyncChatEnabled || event.getGroup() != syncGroup)) {
return;
}
Expand All @@ -44,25 +50,50 @@ public void onEnable() {
if (message instanceof PlainText || message instanceof At || message instanceof AtAll) {
builder.add(message);
} else if (message instanceof Image image) {
sendImageUrl(image, event);
builder.add(sendImageUrl(image));
}
}

if (!builder.isEmpty()) {
if (Config.BotModeOfficial & builder.build().contentToString().replace("/", "").replace(" ", "").startsWith(Config.SyncChatStartWord)) {
String message = Config.SayQQMessage.replace("%NAME%", event.getSenderName()).replace(Config.SyncChatStartWord, "").replace("%MESSAGE%", builder.build().contentToString());
Main.INSTANCE.getServer().broadcastMessage(message);
if (Config.BotModeOfficial & builder.build().contentToString().replace(" ", "").startsWith(Config.SyncChatStartWord)) {
// String avatar = "头像为" + processImageUrl(event.getSender().getAvatarUrl()) + "的QQ用户";
String avatar = "QQ用户";
String id = GetID(event);
String message = Config.SayQQMessage.replace("%NAME%", avatar + id + "发送了以下消息").replace("%MESSAGE%", builder.build().contentToString().replace(Config.SyncChatStartWord, ""));
sendMessage(message);
event.getGroup().sendMessage("已成功发送消息至服务器,以下为发送至服务器的原始数据:\n" + message);
} else if (!Config.BotModeOfficial) {
Main.INSTANCE.getServer().broadcastMessage(Config.SayQQMessage.replace("%NAME%", event.getSenderName()).replace("%MESSAGE%", builder.build().contentToString()));
sendMessage(Config.SayQQMessage.replace("%NAME%", event.getSenderName()).replace("%MESSAGE%", builder.build().contentToString()));
}
if (builder.build().contentToString().replace("/", "").replace(" ", "").startsWith(Config.QQCheckStartWord)) {
if (builder.build().contentToString().replace(" ", "").startsWith(Config.QQCheckStartWord)) {
QQCheck.GroupCheck(event, builder);
}
}
});
}

public void sendMessage(String message) {
String command = "tellraw @a \"" + message + "\"";
executeRconCommand(Config.RconIP, Config.RconPort, Config.RconPassword, command);
}

public String GetID(GroupMessageEvent event) {
DataGet dp = new DataGet();
List<PlayerData> pd = dp.getPlayerDataByUserID(event.getSender().getId());
if (pd.isEmpty()) {
return "(Userid: " + event.getSender().getId() + ")";
} else {
StringBuilder sb = new StringBuilder();
sb.append("(游戏内ID: ");
for (PlayerData p : pd) {
sb.append(p.playerName).append("/");
}
sb.delete(sb.length() - 1, sb.length());
sb.append(")");
return sb.toString();
}
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (Config.SyncChatEnabled & !Config.SyncChatEnabledQ2SOnly & !Config.BotModeOfficial) {
Expand Down