[Add] Framework-API 添加 BotCodeFunction 用于描述 BotCode;

[Add] BotCodeFunction 添加用于描述 BotCode 的功能描述接口;
[Add] StandardBotCodeFunction, CustomBotCodeFunction 添加一个受到 ContentGrabbingJi 内部支持的 Function Enum, 和一个可用于创建平台特有, 或补充功能用的 Function 自定义实现;
[Change] AbstractBotCode, AbstractBotCodeTest 适配修改;
[Change] BotCode 适配修改;
[Change] BasicBotCode, BasicBotCodeTest 适配修改;
[Change] MessageChainTest 适配修改;
This commit is contained in:
2020-12-18 20:06:43 +08:00
parent 5ef90a1756
commit 2ea0c08149
9 changed files with 199 additions and 53 deletions

View File

@ -20,6 +20,7 @@ package net.lamgc.cgj.bot.framework.base;
import net.lamgc.cgj.bot.framework.Platform;
import net.lamgc.cgj.bot.framework.message.AbstractBotCode;
import net.lamgc.cgj.bot.framework.message.BotCode;
import net.lamgc.cgj.bot.framework.message.BotCodeFunction;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
@ -34,16 +35,16 @@ public class BasicBotCode extends AbstractBotCode {
private final static Platform PLATFORM = new Platform("ContentGrabbingJi", "CGJ");
public BasicBotCode(String functionName) {
super(functionName);
public BasicBotCode(BotCodeFunction function) {
super(function);
}
public BasicBotCode(BotCode botCode) {
super(botCode);
}
public BasicBotCode(String functionName, Map<String, String> functionProperties) {
super(functionName, functionProperties);
public BasicBotCode(BotCodeFunction function, Map<String, String> functionProperties) {
super(function, functionProperties);
}
@Override
@ -53,7 +54,7 @@ public class BasicBotCode extends AbstractBotCode {
@Override
public String contentToString() {
StringBuilder builder = new StringBuilder('[' + getFunctionName());
StringBuilder builder = new StringBuilder('[' + getFunction().getFunctionName());
if (getPropertiesKeys().size() == 0) {
return builder.append(']').toString();
} else {

View File

@ -20,6 +20,8 @@ package net.lamgc.cgj.bot.framework.base;
import net.lamgc.cgj.bot.framework.Platform;
import net.lamgc.cgj.bot.framework.message.AbstractBotCode;
import net.lamgc.cgj.bot.framework.message.BotCode;
import net.lamgc.cgj.bot.framework.message.BotCodeFunction;
import net.lamgc.cgj.bot.framework.message.StandardBotCodeFunction;
import org.junit.Assert;
import org.junit.Test;
@ -33,7 +35,7 @@ public class BasicBotCodeTest {
@Test
public void getPlatform() {
BotCode botCode = new BasicBotCode("test");
BotCode botCode = new BasicBotCode(StandardBotCodeFunction.AT);
Assert.assertEquals("ContentGrabbingJi", botCode.getPlatform().getPlatformName());
Assert.assertEquals("CGJ", botCode.getPlatform().getPlatformIdentify());
@ -41,9 +43,9 @@ public class BasicBotCodeTest {
@Test
public void contentToStringWithoutParameter() {
BotCode botCode = new BasicBotCode("test");
BotCode botCode = new BasicBotCode(StandardBotCodeFunction.FILE);
Assert.assertEquals("[test]", botCode.contentToString());
Assert.assertEquals("[file]", botCode.contentToString());
}
@Test
@ -53,16 +55,16 @@ public class BasicBotCodeTest {
argumentsMap.put("arg2", "Hello World.");
argumentsMap.put("arg3", "测试");
BotCode botCode = new BasicBotCode("test", argumentsMap);
Assert.assertEquals("[test:arg3=%E6%B5%8B%E8%AF%95&arg2=Hello+World.&arg1=value1]", botCode.contentToString());
BotCode botCode = new BasicBotCode(StandardBotCodeFunction.EMOJI, argumentsMap);
Assert.assertEquals("[emoji:arg3=%E6%B5%8B%E8%AF%95&arg2=Hello+World.&arg1=value1]", botCode.contentToString());
}
@Test
public void createInstanceByBotCode() {
class TestBotCode extends AbstractBotCode {
public TestBotCode(String functionName, Map<String, String> functionProperties) {
super(functionName, functionProperties);
public TestBotCode(BotCodeFunction function, Map<String, String> functionProperties) {
super(function, functionProperties);
}
@Override
@ -81,10 +83,10 @@ public class BasicBotCodeTest {
argumentsMap.put("arg2", "Hello World.");
argumentsMap.put("arg3", "测试");
BotCode expectBotCode = new TestBotCode("function", argumentsMap);
BotCode expectBotCode = new TestBotCode(StandardBotCodeFunction.AUDIO, argumentsMap);
BotCode botCode = new BasicBotCode(expectBotCode);
Assert.assertEquals(expectBotCode.getFunctionName(), botCode.getFunctionName());
Assert.assertEquals(expectBotCode.getFunction(), botCode.getFunction());
Assert.assertTrue(expectBotCode.getPropertiesKeys().containsAll(botCode.getPropertiesKeys()));
for (String key : expectBotCode.getPropertiesKeys()) {