Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
[#] 命名规范
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoCurit committed Feb 13, 2024
1 parent d69227b commit 095da0b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.nio.file.Paths;

public class ConfigManage {
public static ConfigData Configs;
public static ConfigData configs;
private static final Logger logger = LogManager.getLogger(ConfigManage.class);


Expand All @@ -23,7 +23,7 @@ public static void ReadConfig () {
logger.info("加载配置成功");
} catch (Exception e) {
logger.warn("加载配置失败",e);
Configs = Configs == null ? new ConfigData() : Configs;
configs = configs == null ? new ConfigData() : configs;
}
}
public static void DefaultConfig() {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/catx/feitu/coze_discord_bridge/GPTManage.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static void deleteGPT(String botID) {
CozeGPT GPT = ResponseMap.get(botID);
try {
GPT.Logout();
} catch (Exception ignored) {
}
} catch (Exception ignored) { }
Files.writeString(new File("conversation_" + botID + ".json").toPath(), ConversationHelper.conversation2JsonString(GPT.conversations));
ResponseMap.remove(botID);
} catch (Exception ignored) {}
Expand All @@ -62,12 +61,12 @@ public static void keepalive() {
if (Duration.between(
cozeGPT.getLatestReceiveCozeMsgInstant(),
Instant.now()).toMinutes() >
ConfigManage.Configs.Keepalive_maxIntervalMinutes
ConfigManage.configs.Keepalive_maxIntervalMinutes
) {
try {
try { cozeGPT.GetConversationInfo(ConfigManage.Configs.Keepalive_sendChannel); }
catch (Exception e) { cozeGPT.CreateConversation(ConfigManage.Configs.Keepalive_sendChannel); }
cozeGPT.Chat(ConfigManage.Configs.Keepalive_sendChannel ,ConfigManage.Configs.Keepalive_sendMessage);
try { cozeGPT.GetConversationInfo(ConfigManage.configs.Keepalive_sendChannel); }
catch (Exception e) { cozeGPT.CreateConversation(ConfigManage.configs.Keepalive_sendChannel); }
cozeGPT.Chat(ConfigManage.configs.Keepalive_sendChannel ,ConfigManage.configs.Keepalive_sendMessage);
logger.info("[keepalive] " + cozeGPT.getMark() + " 成功");
success++;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,36 @@ public class HttpServerManage {
public static void start() throws Exception {
boolean SuccessOne = false;
try {
threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(ConfigManage.Configs.APIMaxThread);
logger.info("初始化线程池成功 最大线程:" + ConfigManage.Configs.APIMaxThread);
threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(ConfigManage.configs.APIMaxThread);
logger.info("初始化线程池成功 最大线程:" + ConfigManage.configs.APIMaxThread);
} catch (Exception e){
logger.error("初始化线程池失败" ,e);
throw e;
}

try {
if (ConfigManage.Configs.APIPort != 0) {
server = HttpServer.create(new InetSocketAddress(ConfigManage.Configs.APIPort), 0);
if (ConfigManage.configs.APIPort != 0) {
server = HttpServer.create(new InetSocketAddress(ConfigManage.configs.APIPort), 0);
server.createContext("/", new HttpHandle());
server.setExecutor(threadPoolExecutor); // 线程池设置
server.start();
logger.info("监听HTTP服务 0.0.0.0:" + ConfigManage.Configs.APIPort + " 成功");
logger.info("监听HTTP服务 0.0.0.0:" + ConfigManage.configs.APIPort + " 成功");
SuccessOne = true;
}
} catch (Exception e) {
logger.error("监听HTTP服务 0.0.0.0:" + ConfigManage.Configs.APIPort + " 失败" ,e);
logger.error("监听HTTP服务 0.0.0.0:" + ConfigManage.configs.APIPort + " 失败" ,e);
}


try {
if (ConfigManage.Configs.APISSLPort != 0) {
if (ConfigManage.configs.APISSLPort != 0) {
KeyStore keyStore = KeyStore.getInstance("JKS");
FileInputStream keyStoreIS = new FileInputStream(ConfigManage.Configs.APISSL_keyStorePath);
keyStore.load(keyStoreIS, ConfigManage.Configs.APISSL_keyStorePassword.toCharArray());
FileInputStream keyStoreIS = new FileInputStream(ConfigManage.configs.APISSL_keyStorePath);
keyStore.load(keyStoreIS, ConfigManage.configs.APISSL_keyStorePassword.toCharArray());
keyStoreIS.close();
// 初始化密钥管理器
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, ConfigManage.Configs.APISSL_keyStorePassword.toCharArray());
keyManagerFactory.init(keyStore, ConfigManage.configs.APISSL_keyStorePassword.toCharArray());
// 初始化信任管理器
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
Expand All @@ -87,7 +87,7 @@ public static void start() throws Exception {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());

server_https = HttpsServer.create(new InetSocketAddress(ConfigManage.Configs.APISSLPort), 0);
server_https = HttpsServer.create(new InetSocketAddress(ConfigManage.configs.APISSLPort), 0);
server_https.createContext("/", new HttpHandle());

server_https.setExecutor(threadPoolExecutor); // 线程池设置
Expand All @@ -101,11 +101,11 @@ public void configure(HttpsParameters params) {


server_https.start();
logger.info("监听HTTPS服务 0.0.0.0:" + ConfigManage.Configs.APISSLPort + " 成功");
logger.info("监听HTTPS服务 0.0.0.0:" + ConfigManage.configs.APISSLPort + " 成功");
SuccessOne = true;
}
} catch (Exception e) {
logger.error("监听HTTPS服务 0.0.0.0:" + ConfigManage.Configs.APISSLPort + " 失败",e);
logger.error("监听HTTPS服务 0.0.0.0:" + ConfigManage.configs.APISSLPort + " 失败",e);
}

if (!SuccessOne) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ResponseType handle(HandleType Handle) {
"gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613",
"gpt-3.5-turbo-1196", "gpt-3.5-turbo-16k-0613", "gemini-pro"};

switch (ConfigManage.Configs.OpenAPI_Chat_Default_Models2Conversation) {
switch (ConfigManage.configs.OpenAPI_Chat_Default_Models2Conversation) {
case 0: // 通过读取 model 参数 , 如果 model 是OpenAI已存在的模型 那就通过传递过来的上下文自动判断
String LatestMessage = "";
for (int i = 0; i < messagesArray.size(); i++) {
Expand All @@ -56,7 +56,7 @@ public ResponseType handle(HandleType Handle) {
LatestMessage = messageObject.getString("content");
}
}
Channel_id = ConfigManage.Configs.OpenAPI_Chat_Default_Channel;
Channel_id = ConfigManage.configs.OpenAPI_Chat_Default_Channel;
SendMessage.add(LatestMessage); // 最后一条消息
break;
case 1:
Expand All @@ -66,11 +66,11 @@ public ResponseType handle(HandleType Handle) {
SendMessageL.add(messageObject.getString("role") + ":" + messageObject.getString("content"));
}
Channel_id = Arrays.asList(ForceDefaultModel).contains(Handle.RequestParams.getString("model")) ?
ConfigManage.Configs.OpenAPI_Chat_Default_Channel:
ConfigManage.configs.OpenAPI_Chat_Default_Channel:
Handle.RequestParams.getString("model");
SendMessage.add(ConfigManage.Configs.OpenAPI_Chat_MsgForward_Prefix
SendMessage.add(ConfigManage.configs.OpenAPI_Chat_MsgForward_Prefix
+ "\n\n" + String.join("\n",SendMessageL)
+ "\n\n" + ConfigManage.Configs.OpenAPI_Chat_MsgForward_Suffix); // 最后一条消息
+ "\n\n" + ConfigManage.configs.OpenAPI_Chat_MsgForward_Suffix); // 最后一条消息
break;
case 2:
Channel_id = Handle.RequestParams.getString("model");
Expand All @@ -87,10 +87,10 @@ public ResponseType handle(HandleType Handle) {
JSONObject messageObject = messagesArray.getJSONObject(i);
SendMessageR.add(messageObject.getString("role") + ":" + messageObject.getString("content"));
}
Channel_id = ConfigManage.Configs.OpenAPI_Chat_Default_Channel;
SendMessage.add(ConfigManage.Configs.OpenAPI_Chat_MsgForward_Prefix
Channel_id = ConfigManage.configs.OpenAPI_Chat_Default_Channel;
SendMessage.add(ConfigManage.configs.OpenAPI_Chat_MsgForward_Prefix
+ "\n\n" + String.join("\n",SendMessageR)
+ "\n\n" + ConfigManage.Configs.OpenAPI_Chat_MsgForward_Suffix); // 最后一条消息
+ "\n\n" + ConfigManage.configs.OpenAPI_Chat_MsgForward_Suffix); // 最后一条消息
break;
}
logger.info(String.join("|",SendMessage));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public ResponseType handle(HandleType Handle) {
JSONObject json = new JSONObject(true);
try {
// 创建频道
try { Handle.CozeGPT.GetConversationInfo(ConfigManage.Configs.OpenAPI_ImageGenerate_Default_Channel); }
catch (InvalidConversationException e) { Handle.CozeGPT.CreateConversation(ConfigManage.Configs.OpenAPI_ImageGenerate_Default_Channel); }
try { Handle.CozeGPT.GetConversationInfo(ConfigManage.configs.OpenAPI_ImageGenerate_Default_Channel); }
catch (InvalidConversationException e) { Handle.CozeGPT.CreateConversation(ConfigManage.configs.OpenAPI_ImageGenerate_Default_Channel); }
GenerateMessage Generate = Handle.CozeGPT.Chat(
ConfigManage.Configs.OpenAI_ImageGenerate_Prompt_Prefix +
ConfigManage.configs.OpenAI_ImageGenerate_Prompt_Prefix +
Handle.RequestParams.getString("prompt") +
ConfigManage.Configs.OpenAI_ImageGenerate_Prompt_Suffix,
ConfigManage.Configs.OpenAPI_ImageGenerate_Default_Channel
ConfigManage.configs.OpenAI_ImageGenerate_Prompt_Suffix,
ConfigManage.configs.OpenAPI_ImageGenerate_Default_Channel
);
JSONArray dataArray = new JSONArray();
json.put("created", Instant.now().toEpochMilli() / 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class KeepaliveTimer {
// 定义你的任务
private final Runnable task = GPTManage::keepalive;
public void start() {
scheduler.scheduleAtFixedRate(task, 0, ConfigManage.Configs.Keepalive_timer, TimeUnit.MINUTES);
scheduler.scheduleAtFixedRate(task, 0, ConfigManage.configs.Keepalive_timer, TimeUnit.MINUTES);
}
public void stop() {
scheduler.shutdown();
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/catx/feitu/coze_discord_bridge/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public static void main(String[] args) {
Proxy proxy = ConfigManage.Configs.UsingProxy ? new Proxy(
Objects.equals(ConfigManage.Configs.ProxyType, "HTTP") ?
Proxy.Type.HTTP : Proxy.Type.SOCKS,
new InetSocketAddress(ConfigManage.Configs.ProxyIP, ConfigManage.Configs.ProxyPort)):
new InetSocketAddress(ConfigManage.configs.ProxyIP, ConfigManage.configs.ProxyPort)):
null;
if (proxy != null) {
logger.info("使用代理 " + ConfigManage.Configs.ProxyType + "://" +
ConfigManage.Configs.ProxyIP + ":" + ConfigManage.Configs.ProxyPort + "/");
logger.info("使用代理 " + ConfigManage.configs.ProxyType + "://" +
ConfigManage.configs.ProxyIP + ":" + ConfigManage.configs.ProxyPort + "/");
}
boolean successOne = false;
for (int i = 0;ConfigManage.Configs.Bots.size() > i;i++) {
ConfigBotsData BotData = ConfigManage.Configs.Bots.get(i);
for (int i = 0; ConfigManage.configs.Bots.size() > i; i++) {
ConfigBotsData BotData = ConfigManage.configs.Bots.get(i);
CozeGPTConfig GPTConfig = new CozeGPTConfig();
try {
BotData.Key = Objects.equals(BotData.Key, "") ? "default" : BotData.Key;
Expand All @@ -49,11 +49,11 @@ public static void main(String[] args) {
GPTConfig.Discord_CreateChannel_Category = BotData.CreateChannel_Category;
GPTConfig.CozeBot_id = BotData.CozeBot_id;

GPTConfig.generate_timeout = ConfigManage.Configs.generate_timeout;
GPTConfig.generate_timeout = ConfigManage.configs.generate_timeout;

GPTConfig.Disable_2000Limit_Unlock = ConfigManage.Configs.Disable_2000Limit_Unlock;
GPTConfig.Disable_Name_Cache = ConfigManage.Configs.Disable_Name_Cache;
GPTConfig.Disable_CozeBot_ReplyMsgCheck = ConfigManage.Configs.Disable_CozeBot_ReplyMsgCheck;
GPTConfig.Disable_2000Limit_Unlock = ConfigManage.configs.Disable_2000Limit_Unlock;
GPTConfig.Disable_Name_Cache = ConfigManage.configs.Disable_Name_Cache;
GPTConfig.Disable_CozeBot_ReplyMsgCheck = ConfigManage.configs.Disable_CozeBot_ReplyMsgCheck;

GPTConfig.Proxy = proxy;

Expand All @@ -75,7 +75,7 @@ public static void main(String[] args) {
System.exit(-1);
}
KeepaliveTimer Keepalive = new KeepaliveTimer();
if (ConfigManage.Configs.Keepalive_timer > 0) {
if (ConfigManage.configs.Keepalive_timer > 0) {
Keepalive.start();
}
// 程序退出前执行
Expand Down

0 comments on commit 095da0b

Please sign in to comment.