Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into feat/next-api
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
#	src/main/java/snw/kookbc/impl/command/litecommands/WrappedLiteCommandsBuilder.java
#	src/main/java/snw/kookbc/impl/entity/channel/TextChannelImpl.java
#	src/main/java/snw/kookbc/impl/network/NetworkClient.java
  • Loading branch information
SNWCreations committed Aug 27, 2024
2 parents aa4faa3 + 5dcfd30 commit 0f917a5
Show file tree
Hide file tree
Showing 28 changed files with 1,054 additions and 368 deletions.
10 changes: 9 additions & 1 deletion CLOUD_MIGRATE_TO_LITECOMMANDS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
### 从Cloud迁移到LiteCommands

#### 兼容层

如果你不想迁移,可以安装 [kook-cloud-compatible](https://github.com/huanmeng-qwq/kookbc-cloud-compatible/releases)
插件来允许使用cloud框架注册命令的插件正常运行

### 注解

| Cloud | LiteCommands |
Expand All @@ -9,9 +14,11 @@
| @Argument | @Arg |

### 示例

#### Cloud

```java

@CommandContainer
@CommandPrefix("!")
@CommandMethod("test")
Expand All @@ -24,8 +31,9 @@ public class TestCloudCommand {
```

#### LiteCommands

> Github: [LiteCommands](https://github.com/Rollczi/LiteCommands)
>
>
> IDEA中安装[LiteCommands](https://plugins.jetbrains.com/plugin/20799-litecommands)插件后,可以自动识别LiteCommands的注解,并能够很好的辅助开发。
```java
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<log4j2.version>2.19.0</log4j2.version>
<jkook.version>9a22f1e9</jkook.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mixin.version>0.12.4+mixin.0.8.5</mixin.version>
<mixin.version>0.15.2+mixin.0.8.7</mixin.version>
<asm.version>9.3</asm.version>
<!-- Used by JitPack CI -->
<skipShade>false</skipShade>
Expand Down Expand Up @@ -304,7 +304,7 @@
<dependency>
<groupId>dev.rollczi</groupId>
<artifactId>litecommands-framework</artifactId>
<version>3.3.4</version>
<version>3.4.2</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/snw/kookbc/impl/HttpAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,6 @@ public void handleFriendRequest(int id, boolean accept) {
.put("id", id)
.put("accept", accept ? 1 : 0)
.build();
HttpAPIImpl.this.client.getNetworkClient().post(HttpAPIRoute.FRIEND_HANDLE_REQUEST.toFullURL(), body);
HttpAPIImpl.this.client.getNetworkClient().postContent(HttpAPIRoute.FRIEND_HANDLE_REQUEST.toFullURL(), body);
}
}
55 changes: 26 additions & 29 deletions src/main/java/snw/kookbc/impl/KBCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import snw.jkook.Core;
import snw.jkook.command.CommandExecutor;
import snw.jkook.command.CommandManager;
import snw.jkook.command.JKookCommand;
import snw.jkook.config.ConfigurationSection;
import snw.jkook.entity.User;
import snw.jkook.plugin.InvalidPluginException;
Expand All @@ -51,13 +50,16 @@
import snw.jkook.util.Validate;
import snw.kookbc.SharedConstants;
import snw.kookbc.impl.command.CommandManagerImpl;
import snw.kookbc.impl.command.internal.HelpCommand;
import snw.kookbc.impl.command.litecommands.LiteKookFactory;
import snw.kookbc.impl.command.litecommands.internal.HelpCommand;
import snw.kookbc.impl.command.litecommands.internal.PluginsCommand;
import snw.kookbc.impl.command.litecommands.internal.StopCommand;
import snw.kookbc.impl.command.litecommands.result.ResultTypes;
import snw.kookbc.impl.console.Console;
import snw.kookbc.impl.entity.builder.EntityBuilder;
import snw.kookbc.impl.entity.builder.MessageBuilder;
import snw.kookbc.impl.event.EventFactory;
import snw.kookbc.impl.event.internal.InternalListener;
import snw.kookbc.impl.event.internal.UserClickButtonListener;
import snw.kookbc.impl.network.HttpAPIRoute;
import snw.kookbc.impl.network.NetworkClient;
Expand Down Expand Up @@ -500,50 +502,45 @@ public NetworkSystem getNetworkSystem() {
}

protected void registerInternal() {
this.core.getEventManager().registerHandlers(this.internalPlugin, new InternalListener());
ConfigurationSection commandConfig = getConfig().getConfigurationSection("internal-commands");
if (commandConfig == null) {
commandConfig = getConfig().createSection("internal-commands");
}
List<Class<?>> commands = new ArrayList<>();
if (commandConfig.getBoolean("stop", true)) {
registerStopCommand();
commands.add(StopCommand.class);
}
if (commandConfig.getBoolean("help", true)) {
registerHelpCommand();
this.core.getEventManager()
.registerHandlers(this.internalPlugin, new UserClickButtonListener(this));
commands.add(HelpCommand.class);
}
if (commandConfig.getBoolean("plugins", true)) {
registerPluginsCommand();
commands.add(PluginsCommand.class);
}
registerCommands(commands);
}

protected void registerStopCommand() {
new JKookCommand("stop")
.setDescription("停止 " + SharedConstants.IMPL_NAME + " 实例。")
.setExecutor(wrapConsoleCmd((args) -> shutdown()))
.register(getInternalPlugin());
}

protected void registerPluginsCommand() {
// new JKookCommand("plugins")
// .setDescription("获取已安装到此 " + SharedConstants.IMPL_NAME + " 实例的插件列表。")
// .setExecutor(new PluginsCommand(this))
// .register(getInternalPlugin());
private void registerCommands(List<Class<?>> commands) {
LiteKookFactory.builder(getInternalPlugin())
.commands(new PluginsCommand(this))
.settings((k) -> {
if (!getConfig().contains("internal-commands-reply-result-type")) {
return k;
}
try {
ResultTypes resultTypes = ResultTypes.valueOf(getConfig().getString("internal-commands-reply-result-type"));
k.defaultResultType(resultTypes);
} catch (Exception e) {
getCore().getLogger().error("`internal-commands-reply-result-type` is not a valid result-type");
}
return k;
})
.commands(commands.toArray())
.build()
;
}

protected void registerHelpCommand() {
HelpCommand executor = new HelpCommand(this);
new JKookCommand("help")
.setDescription("获取此帮助列表。")
.executesUser(executor)
.executesConsole(executor)
.register(getInternalPlugin());
this.core.getEventManager()
.registerHandlers(this.internalPlugin, new UserClickButtonListener(this));
}

public CommandManager getCommandManager() {
return commandManager;
}
Expand Down
231 changes: 0 additions & 231 deletions src/main/java/snw/kookbc/impl/command/internal/HelpCommand.java

This file was deleted.

Loading

0 comments on commit 0f917a5

Please sign in to comment.