Skip to content

Commit

Permalink
refactor(config): change botId configuration to string type
Browse files Browse the repository at this point in the history
- Update botId configuration from ConfigInteger to ConfigString- Modify related commands and events to use string value for botId
- Update language files to use common prefix for configuration options
- Add client-side setup for configuration screen
  • Loading branch information
cnlimiter committed Oct 26, 2024
1 parent 28a1a82 commit f5fb026
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BotIDCommand {

public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
int id = context.getArgument("BotId", Integer.class);
ModConfig.get().getBotConfig().getBotId().setIntegerValue(id);
ModConfig.get().getBotConfig().getBotId().setValueFromString(String.valueOf(id));
context.getSource().sendSuccess(() -> Component.literal("已设置机器人QQ号为:" + id + "!"), true);
ModConfig.get().save();
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
boolean connected = Constants.onebot.getWs().isOpen();
boolean white = Constants.SERVER.getPlayerList().isUsingWhitelist();
String host = ModConfig.get().getBotConfig().getUrl().getStringValue();
long QQid = ModConfig.get().getBotConfig().getBotId().getIntegerValue();
String QQid = ModConfig.get().getBotConfig().getBotId().getStringValue();
String toSend =
"\n姬妻人服务状态:\n"
+ "姬妻人QQId:" + QQid + " \n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BotConfig extends AutoInitConfigContainer.AutoInitConfigCategoryBas
public ConfigString tag = new ConfigString("config.mcbot.bot.tag", "main", "跨服支持,权限支持");
public ConfigString url = new ConfigString("config.mcbot.bot.url", "127.0.0.1", "地址(支持域名和ipv6)");
public ConfigString token = new ConfigString("config.mcbot.bot.token", "", "鉴权");
public ConfigInteger botId = new ConfigInteger("config.mcbot.bot.botId", 0, 0, Integer.MAX_VALUE, "机器人qq");
public ConfigString botId = new ConfigString("config.mcbot.bot.botId", "0", "机器人qq");
public ConfigBoolean reconnect = new ConfigBoolean("config.mcbot.bot.reconnect", true, "自动重连");
public ConfigInteger maxReconnectAttempts = new ConfigInteger("config.mcbot.bot.maxReconnectAttempts", 3, 0, 10, "自动重连次数");
public ConfigInteger timeoutCompensation = new ConfigInteger("config.mcbot.bot.timeoutCompensation", 1000, 0, 10000, "超时宽容度(毫秒)");
Expand All @@ -30,7 +30,7 @@ public BotConfig() {
}

public cn.evole.onebot.client.core.BotConfig build() {
return new cn.evole.onebot.client.core.BotConfig(url.getStringValue(), token.getStringValue(), botId.getIntegerValue(), token.getStringValue().startsWith("mirai_"), reconnect.getBooleanValue(), maxReconnectAttempts.getIntegerValue());
return new cn.evole.onebot.client.core.BotConfig(url.getStringValue(), token.getStringValue(), Long.parseLong(botId.getStringValue()), token.getStringValue().startsWith("mirai_"), reconnect.getBooleanValue(), maxReconnectAttempts.getIntegerValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class IBotEvent implements Listener {
public void onGroup(GroupMessageEvent event) {
if (ModConfig.get().getCommon().getGroupIdList().getStrings().contains(String.valueOf(event.getGroupId()))//判断是否是配置中的群
&& ModConfig.get().getStatus().getREnable().getBooleanValue()//总接受开关
&& event.getUserId() != ModConfig.get().getBotConfig().getBotId().getIntegerValue()//过滤机器人
&& !String.valueOf(event.getUserId()).equals(ModConfig.get().getBotConfig().getBotId().getStringValue())//过滤机器人
) {
String send = CQUtils.replace(event, 2000);//暂时匹配仅符合字符串聊天内容与图片
if (!send.startsWith(ModConfig.get().getCmd().getCmdStart().getStringValue())//过滤命令前缀
Expand Down
16 changes: 8 additions & 8 deletions common/src/main/resources/assets/mcbot/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"config.mcbot.status.sChatEnable" : "发送服务器聊天",
"config.mcbot.status.sAdvanceEnable" : "发送成就消息",

"config.mcbot.status.groupOn" : "开启q群功能",
"config.mcbot.status.groupIdList" : "支持多个q群",
"config.mcbot.status.enable" : "是否启用",
"config.mcbot.status.debug" : "是否开发模式,将显示事件信息操作",
"config.mcbot.status.languageSelect" : "选择语言系统,zh_cn为简体中文,en_us为英文",
"config.mcbot.status.autoOpen" : "自动连接",
"config.mcbot.status.imageOn" : "是否开启聊天栏图片功能",
"config.mcbot.status.bindOn" : "是否开启绑定校验"
"config.mcbot.common.groupOn" : "开启q群功能",
"config.mcbot.common.groupIdList" : "支持多个q群",
"config.mcbot.common.enable" : "是否启用",
"config.mcbot.common.debug" : "是否开发模式,将显示事件信息操作",
"config.mcbot.common.languageSelect" : "选择语言系统,zh_cn为简体中文,en_us为英文",
"config.mcbot.common.autoOpen" : "自动连接",
"config.mcbot.common.imageOn" : "是否开启聊天栏图片功能",
"config.mcbot.common.bindOn" : "是否开启绑定校验"

}
16 changes: 8 additions & 8 deletions common/src/main/resources/assets/mcbot/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"config.mcbot.status.sChatEnable" : "发送服务器聊天",
"config.mcbot.status.sAdvanceEnable" : "发送成就消息",

"config.mcbot.status.groupOn" : "开启q群功能",
"config.mcbot.status.groupIdList" : "支持多个q群",
"config.mcbot.status.enable" : "是否启用",
"config.mcbot.status.debug" : "是否开发模式,将显示事件信息操作",
"config.mcbot.status.languageSelect" : "选择语言系统,zh_cn为简体中文,en_us为英文",
"config.mcbot.status.autoOpen" : "自动连接",
"config.mcbot.status.imageOn" : "是否开启聊天栏图片功能",
"config.mcbot.status.bindOn" : "是否开启绑定校验"
"config.mcbot.common.groupOn" : "开启q群功能",
"config.mcbot.common.groupIdList" : "支持多个q群",
"config.mcbot.common.enable" : "是否启用",
"config.mcbot.common.debug" : "是否开发模式,将显示事件信息操作",
"config.mcbot.common.languageSelect" : "选择语言系统,zh_cn为简体中文,en_us为英文",
"config.mcbot.common.autoOpen" : "自动连接",
"config.mcbot.common.imageOn" : "是否开启聊天栏图片功能",
"config.mcbot.common.bindOn" : "是否开启绑定校验"

}
Binary file added common/src/main/resources/mcbot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions forge/src/main/java/cn/evole/mods/mcbot/forge/McBotForge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
import cn.evole.mods.mcbot.api.event.server.ServerGameEvents;
import cn.evole.mods.mcbot.common.event.ICmdEvent;
import cn.evole.mods.mcbot.common.event.ITickEvent;
import com.iafenvoy.jupiter.Jupiter;
import com.iafenvoy.jupiter.config.FileConfigContainer;
import com.iafenvoy.jupiter.forge.ForgeEntryPointLoader;
import com.iafenvoy.jupiter.malilib.config.ConfigManager;
import com.iafenvoy.jupiter.screen.ConfigSelectScreen;
import com.iafenvoy.jupiter.test.TestConfig;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.TickEvent;
Expand All @@ -17,7 +27,9 @@
import net.minecraftforge.event.server.ServerStoppedEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import org.jetbrains.annotations.NotNull;

@Mod(Constants.MOD_ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cn.evole.mods.mcbot.forge;

import cn.evole.mods.mcbot.common.config.ModConfig;
import com.iafenvoy.jupiter.screen.ConfigSelectScreen;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

/**
* @Project: McBot
* @Author: cnlimiter
* @CreateTime: 2024/10/27 03:21
* @Description:
*/
@Mod.EventBusSubscriber(
bus = Mod.EventBusSubscriber.Bus.MOD,
value = {Dist.CLIENT}
)
public class McBotForgeClient {
public McBotForgeClient() {
}

@SubscribeEvent
public static void processClient(FMLClientSetupEvent event) {
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory(
(client, screen) ->
new ConfigSelectScreen<>(Component.translatable("config.mcbot.title"), screen, ModConfig.INSTANCE, null)));
}

}

0 comments on commit f5fb026

Please sign in to comment.