mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Add] Core 添加一个内部使用(也可能会用到模版上)的 BotCode 实现;
[Add] BasicBotCode 添加内部实现的 BotCode;
This commit is contained in:
parent
e4617e6fee
commit
7ea90284e7
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user