Skip to content

Commit

Permalink
+ fix #120
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Nov 12, 2023
1 parent 86c4d4f commit 62c604e
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 51 deletions.
2 changes: 1 addition & 1 deletion fabric/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ minecraft_version=1.20.1
loader_version=0.14.21
fabric_version=0.83.1+1.20.1
onebot_client_version=0.3.6-light
toml_version=0.1.0
toml_version=0.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
} else {
ModConfig.INSTANCE.getCommon().addChannelId(id);
}
ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("已成功添加QQ群号:" + id + "!"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal("已设置Mirai框架的VerifyKey为:" + id), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal("已设置机器人QQ号为:" + id + "!"), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static int cqhttpExecute(CommandContext<CommandSourceStack> context) thro
}
ModConfig.INSTANCE.getStatus().setREnable(true);
ModConfig.INSTANCE.getCommon().setEnable(true);

ModConfig.INSTANCE.save();
return 1;

} else {
Expand Down Expand Up @@ -89,7 +89,7 @@ public static int miraiExecute(CommandContext<CommandSourceStack> context) throw
}
ModConfig.INSTANCE.getStatus().setREnable(true);
ModConfig.INSTANCE.getCommon().setEnable(true);

ModConfig.INSTANCE.save();
return 1;

} else {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static int cqhttpCommonExecute(CommandContext<CommandSourceStack> context
}
ModConfig.INSTANCE.getStatus().setREnable(true);
ModConfig.INSTANCE.getCommon().setEnable(true);

ModConfig.INSTANCE.save();
return 1;

}
Expand All @@ -149,8 +149,7 @@ public static int miraiCommonExecute(CommandContext<CommandSourceStack> context)
}
ModConfig.INSTANCE.getStatus().setREnable(true);
ModConfig.INSTANCE.getCommon().setEnable(true);


ModConfig.INSTANCE.save();
return 1;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("已关闭开发者模式"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//#else
//$$ import net.minecraft.network.chat.TextComponent;
//#endif
public class RemoveChannelIDCommand {
public class DelChannelIDCommand {


public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Expand All @@ -26,7 +26,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("子频道号:" + id + "并未出现!"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//#else
//$$ import net.minecraft.network.chat.TextComponent;
//#endif
public class RemoveGroupIDCommand {
public class DelGroupIDCommand {


public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Expand All @@ -26,7 +26,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("QQ群号:" + id + "并未出现!"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
}
ModConfig.INSTANCE.getCommon().setEnable(false);
}

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal("已设置互通的频道号为:" + id), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@



import cn.evole.mods.mcbot.init.config.ModConfig;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import lombok.val;
Expand Down Expand Up @@ -70,7 +71,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal(toSend).append(urlC).append(endC), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.evole.mods.mcbot.command;


import cn.evole.mods.mcbot.init.config.ModConfig;
import cn.evole.mods.mcbot.init.handler.CustomCmdHandler;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
Expand All @@ -25,7 +26,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal(out.toString()), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("已关闭自动重连"), true);
//#endif
}


ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static int allExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("全局接收群消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -58,7 +58,7 @@ public static int chatExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("接收群内聊天消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;

}
Expand All @@ -84,7 +84,7 @@ public static int cmdExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("接收群内命令消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ReloadConfigCmd {
public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
try {

ModConfig.INSTANCE.reload();
if (ModConfig.INSTANCE == null) {
//#if MC >= 12000
context.getSource().sendSuccess(()->Component.literal("重载配置失败"), true);
Expand All @@ -44,7 +44,6 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//$$ context.getSource().sendSuccess(Component.literal("重载配置失败"), true);
//#endif
}

return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static int qqLeaveExecute(CommandContext<CommandSourceStack> context) thr
//$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -61,7 +61,7 @@ public static int qqWelcomeExecute(CommandContext<CommandSourceStack> context) t
//$$ context.getSource().sendSuccess(Component.literal("发送新人加入QQ群的消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -85,7 +85,7 @@ public static int allExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("全局发送消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -110,7 +110,7 @@ public static int joinExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("发送玩家加入游戏消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -135,7 +135,7 @@ public static int leaveExecute(CommandContext<CommandSourceStack> context) throw
//$$ context.getSource().sendSuccess(Component.literal("发送玩家离开游戏消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -160,7 +160,7 @@ public static int deathExecute(CommandContext<CommandSourceStack> context) throw
//$$ context.getSource().sendSuccess(Component.literal("发送玩家死亡游戏消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -185,7 +185,7 @@ public static int chatExecute(CommandContext<CommandSourceStack> context) throws
//$$ context.getSource().sendSuccess(Component.literal("发送玩家聊天游戏消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand All @@ -210,7 +210,7 @@ public static int achievementsExecute(CommandContext<CommandSourceStack> context
//$$ context.getSource().sendSuccess(Component.literal("发送玩家成就游戏消息开关已被设置为关闭"), true);
//#endif
}

ModConfig.INSTANCE.save();
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static int execute(CommandContext<CommandSourceStack> context) throws Com
//#else
//$$ context.getSource().sendSuccess(Component.literal(toSend), true);
//#endif

ModConfig.INSTANCE.save();
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class CommonConfig extends AutoLoadTomlConfig {
@TableField(rightComment = "开启q群功能")
private boolean groupOn = true;
@TableField(rightComment = "支持多个q群")
private Long[] groupIdList = new Long[0];//支持多个q群
private List<Long> groupIdList = new ArrayList<Long>(){};//支持多个q群
@TableField(rightComment = "是否开启频道")
private boolean guildOn = false;//是否开启频道
@TableField(rightComment = "频道id")
private String guildId = "";//频道id
@TableField(rightComment = "子频道列表")
private String[] channelIdList = new String[0];//子频道列表
private List<String> channelIdList = new ArrayList<String>(){};//子频道列表
@TableField(rightComment = "机器人qq")
private long botId = 0;//机器人qq
@TableField(rightComment = "是否启用")
Expand All @@ -51,27 +51,19 @@ public CommonConfig(TomlTable source) {
}

public void addChannelId(String id) {
if (!Arrays.stream(channelIdList).toList().contains(id)) Arrays.stream(channelIdList).toList().add(id);
if (!channelIdList.contains(id)) channelIdList.add(id);
}

public void removeChannelId(String id) {
Arrays.stream(channelIdList).toList().remove(id);
channelIdList.remove(id);
}

public void removeGroupId(long id) {
Arrays.stream(groupIdList).toList().remove(id);
groupIdList.remove(id);
}

public void addGroupId(long id) {
if (!Arrays.stream(groupIdList).toList().contains(id)) Arrays.stream(groupIdList).toList().add(id);
if (!groupIdList.contains(id)) groupIdList.add(id);
}


public List<Long> getGroupIdList() {
return Arrays.asList(groupIdList);
}

public List<String> getChannelIdList() {
return Arrays.asList(channelIdList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ public ModConfig(TomlTable source) {
this.load(ModConfig.class);
}

public void save(){
TomlUtil.writeConfig(McBot.CONFIG_FILE,INSTANCE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher){
.executes(AddChannelIDCommand::execute)))
.then(Commands.literal("delChannelId")
.then(Commands.argument("ChannelId", StringArgumentType.greedyString())
.executes(RemoveChannelIDCommand::execute)))
.executes(DelChannelIDCommand::execute)))
.then(Commands.literal("setGuild")
.then(Commands.argument("GuildId", StringArgumentType.greedyString())
.executes(GuildIDCommand::execute)))
Expand All @@ -54,9 +54,9 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher){
.then(Commands.literal("addGroup")
.then(Commands.argument("GroupId", LongArgumentType.longArg())
.executes(AddGroupIDCommand::execute)))
.then(Commands.literal("removeGroup")
.then(Commands.literal("delGroup")
.then(Commands.argument("GroupId", LongArgumentType.longArg())
.executes(RemoveGroupIDCommand::execute)))
.executes(DelGroupIDCommand::execute)))
.then(Commands.literal("setBot")
.then(Commands.argument("BotId", LongArgumentType.longArg())
.executes(BotIDCommand::execute)))
Expand Down

0 comments on commit 62c604e

Please sign in to comment.