[Add] Core 添加一个内部使用(也可能会用到模版上)的 BotCode 实现;

[Add] BasicBotCode 添加内部实现的 BotCode;
This commit is contained in:
LamGC 2020-11-19 14:13:54 +08:00
parent e4617e6fee
commit 7ea90284e7
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 LamGC
*
* ContentGrabbingJi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* ContentGrabbingJi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.lamgc.cgj.bot.framework.base;
import net.lamgc.cgj.bot.framework.Platform;
import net.lamgc.cgj.bot.framework.message.AbstractBotCode;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* ContentGrabbingJi 内部 BotCode 实现.
* <p> 参数形式与 Url 查询参数格式一致.
* @author LamGC
*/
public class BasicBotCode extends AbstractBotCode {
private final static Platform PLATFORM = new Platform("ContentGrabbingJi", "CGJ");
@Override
public Platform getPlatform() {
return PLATFORM;
}
@Override
public String contentToString() {
StringBuilder builder = new StringBuilder('[' + getFunctionName());
if (getPropertiesKeys().size() == 0) {
return builder.append(']').toString();
} else {
builder.append(':');
for (String key : getPropertiesKeys()) {
try {
builder.append(key).append('=')
.append(URLEncoder.encode(getProperty(key), "UTF-8")).append('&');
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}
return builder.deleteCharAt(builder.lastIndexOf("&")).toString();
}
}
}