mirror of
https://github.com/ddaodan/minechatgpt.git
synced 2025-11-03 13:14:13 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b8aaaaf6a3 | |||
| 138b1337ac |
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'com'
|
group = 'com'
|
||||||
version = '2.0'
|
version = '2.2'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -16,18 +16,23 @@ repositories {
|
|||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = "https://oss.sonatype.org/content/groups/public/"
|
url = "https://oss.sonatype.org/content/groups/public/"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url = 'https://repo.codemc.io/repository/maven-public/'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT"
|
compileOnly "org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT"
|
||||||
|
implementation 'org.bstats:bstats-bukkit:3.0.2'
|
||||||
implementation 'org.jodd:jodd-http:6.3.0'
|
implementation 'org.jodd:jodd-http:6.3.0'
|
||||||
implementation 'org.json:json:20231013'
|
implementation 'org.json:json:20231013'
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName = "MineChatGPT-${project.version}.jar"
|
archiveFileName = "MineChatGPT-${project.version}.jar"
|
||||||
relocate 'org.apache.http', 'com.ddaodan.shaded.org.apache.http'
|
relocate 'jodd', 'com.ddaodan.shaded.jodd'
|
||||||
relocate 'org.json', 'com.ddaodan.minechatgpt.libs.org.json'
|
relocate 'org.json', 'com.ddaodan.minechatgpt.libs.org.json'
|
||||||
|
relocate 'org.bstats', 'com.ddaodan.minechatgpt.libs.org.bstats'
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
def targetJavaVersion = 8
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
## 2.2
|
||||||
|
- 修复插件无法加载
|
||||||
|
- 修复 #2:模型切换实际并不生效
|
||||||
|
## 2.1
|
||||||
|
- 接入bStats
|
||||||
|
- 调整配置文件,添加更新功能,现在更新插件应该不用再备份配置文件了
|
||||||
|
- 修改了gradle中错误的依赖
|
||||||
## 2.0
|
## 2.0
|
||||||
- 更换为jodd-http库,减少插件大小
|
- 更换为jodd-http库,减少插件大小
|
||||||
- 支持指令补全
|
- 支持指令补全
|
||||||
|
|||||||
27
readme.md
27
readme.md
@@ -1,5 +1,6 @@
|
|||||||
# MineChatGPT
|
# MineChatGPT
|
||||||
在Minecraft中与ChatGPT交流
|
在Minecraft中与ChatGPT交流
|
||||||
|
理论支持全版本,欢迎测试
|
||||||
|
|
||||||
所有的代码都是ChatGPT写的哦
|
所有的代码都是ChatGPT写的哦
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
# API 相关设置
|
# API 相关设置
|
||||||
api:
|
api:
|
||||||
# 你的 OpenAI API key,用于身份验证
|
# 你的 OpenAI API key,用于身份验证
|
||||||
# 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key
|
# 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key
|
||||||
key: "sk-your_openai_api_key"
|
key: "sk-your_openai_api_key"
|
||||||
# OpenAI API 的基础 URL,用于构建请求
|
# OpenAI API 的基础 URL,用于构建请求
|
||||||
base_url: "https://api.openai.com/v1"
|
base_url: "https://api.openai.com/v1"
|
||||||
@@ -62,7 +63,7 @@ messages:
|
|||||||
help_reload: "&e/chatgpt reload - 重新加载配置文件"
|
help_reload: "&e/chatgpt reload - 重新加载配置文件"
|
||||||
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
|
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
|
||||||
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
|
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
|
||||||
usage: "&c输入: /chatgpt model <model_name>"
|
current_model_info: "&e当前模型:%s,输入 /chatgpt model <model_name> 来切换模型。"
|
||||||
model_switch: "&a已切换至模型 %s"
|
model_switch: "&a已切换至模型 %s"
|
||||||
chatgpt_error: "&c无法联系ChatGPT。"
|
chatgpt_error: "&c无法联系ChatGPT。"
|
||||||
chatgpt_response: "&bChatGPT: %s"
|
chatgpt_response: "&bChatGPT: %s"
|
||||||
@@ -70,12 +71,25 @@ messages:
|
|||||||
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
|
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
|
||||||
available_models: "&e可用模型列表:"
|
available_models: "&e可用模型列表:"
|
||||||
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
|
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
|
||||||
|
# 不要动!!!!!
|
||||||
|
version: 2.1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 指令与权限
|
||||||
|
|指令|权限|描述|
|
||||||
|
|-|-|-|
|
||||||
|
|`/chatgpt`|chatgpt.use|查看插件帮助|
|
||||||
|
|`/chatgpt <text>`|chatgpt.use|向ChatGPT提问|
|
||||||
|
|`/chatgpt reload`|chatgpt.reload|重新加载配置文件|
|
||||||
|
|`/chatgpt model <model_name>`|chatgpt.model|切换至其他模型|
|
||||||
|
|`/chatgpt modellist`|chatgpt.modellist|查看可用的模型列表|
|
||||||
|
|
||||||
## 兼容的版本
|
## 兼容的版本
|
||||||
✔ = 完全支持
|
✔ = 完全支持
|
||||||
? = 部分支持
|
? = 部分支持
|
||||||
× = 不支持
|
× = 不支持
|
||||||
只列出经过测试的版本
|
只列出经过测试的版本
|
||||||
|
|
||||||
|服务端|支持情况|
|
|服务端|支持情况|
|
||||||
|-|-|
|
|-|-|
|
||||||
|Mohist 1.20.1|✔|
|
|Mohist 1.20.1|✔|
|
||||||
@@ -87,6 +101,11 @@ messages:
|
|||||||
检查控制台输出的错误内容。
|
检查控制台输出的错误内容。
|
||||||
### `connect timeout` `connect reset`
|
### `connect timeout` `connect reset`
|
||||||
检查`config.yml`中的`base_url`能否正常访问。如果你无法连接到OpenAI官方的API地址,可以考虑使用其他反代。
|
检查`config.yml`中的`base_url`能否正常访问。如果你无法连接到OpenAI官方的API地址,可以考虑使用其他反代。
|
||||||
|
### 我可以添加其他模型吗?
|
||||||
|
可以,只要模型支持OpenAI的API,就可以使用。
|
||||||
|
## 我没有ChatGPT的账号,可以用吗?
|
||||||
|
可以,目前有很多代理网站,可以很轻松地使用,而且还支持其他模型,费用通常来说也会比官方便宜。如果你愿意,也可以使用我的代理,目前仅在我的QQ群:226385797中提供。
|
||||||
|
### 是否会支持Folia
|
||||||
|
不会。Folia仍然在开发中,短期内不会支持。
|
||||||
## 赞助
|
## 赞助
|
||||||

|

|
||||||
@@ -45,13 +45,15 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sender.sendMessage(configManager.getUsageMessage());
|
String currentModel = configManager.getCurrentModel();
|
||||||
|
sender.sendMessage(configManager.getCurrentModelInfoMessage().replace("%s", currentModel));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String model = args[1];
|
String model = args[1];
|
||||||
List<String> models = configManager.getModels();
|
List<String> models = configManager.getModels();
|
||||||
if (models.contains(model)) {
|
if (models.contains(model)) {
|
||||||
// Logic to switch model
|
// Logic to switch model
|
||||||
|
configManager.setCurrentModel(model);
|
||||||
sender.sendMessage(configManager.getModelSwitchMessage().replace("%s", model));
|
sender.sendMessage(configManager.getModelSwitchMessage().replace("%s", model));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(configManager.getInvalidModelMessage());
|
sender.sendMessage(configManager.getInvalidModelMessage());
|
||||||
@@ -92,6 +94,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
message.put("content", question);
|
message.put("content", question);
|
||||||
messages.put(message);
|
messages.put(message);
|
||||||
json.put("messages", messages);
|
json.put("messages", messages);
|
||||||
|
json.put("model", configManager.getCurrentModel());
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.post(configManager.getBaseUrl() + "/chat/completions")
|
HttpRequest request = HttpRequest.post(configManager.getBaseUrl() + "/chat/completions")
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final Main plugin;
|
private final Main plugin;
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
|
private String currentModel;
|
||||||
|
|
||||||
public ConfigManager(Main plugin) {
|
public ConfigManager(Main plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -16,11 +17,23 @@ public class ConfigManager {
|
|||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
plugin.reloadConfig();
|
plugin.reloadConfig();
|
||||||
config = plugin.getConfig();
|
config = plugin.getConfig();
|
||||||
|
currentModel = config.getString("default_model");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String translateColorCodes(String message) {
|
private String translateColorCodes(String message) {
|
||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
return ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCurrentModel() {
|
||||||
|
return currentModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentModel(String model) {
|
||||||
|
currentModel = model;
|
||||||
|
}
|
||||||
|
public String getConfigVersion() {
|
||||||
|
return config.getString("version", "1.0");
|
||||||
|
}
|
||||||
public String getApiKey() {
|
public String getApiKey() {
|
||||||
return config.getString("api.key");
|
return config.getString("api.key");
|
||||||
}
|
}
|
||||||
@@ -61,10 +74,6 @@ public class ConfigManager {
|
|||||||
return translateColorCodes(config.getString("messages.help_modellist"));
|
return translateColorCodes(config.getString("messages.help_modellist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsageMessage() {
|
|
||||||
return translateColorCodes(config.getString("messages.usage"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getModelSwitchMessage() {
|
public String getModelSwitchMessage() {
|
||||||
return translateColorCodes(config.getString("messages.model_switch"));
|
return translateColorCodes(config.getString("messages.model_switch"));
|
||||||
}
|
}
|
||||||
@@ -92,4 +101,8 @@ public class ConfigManager {
|
|||||||
public String getNoPermissionMessage() {
|
public String getNoPermissionMessage() {
|
||||||
return translateColorCodes(config.getString("messages.no_permission"));
|
return translateColorCodes(config.getString("messages.no_permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCurrentModelInfoMessage() {
|
||||||
|
return translateColorCodes(config.getString("messages.current_model_info"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.ddaodan.MineChatGPT;
|
package com.ddaodan.MineChatGPT;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -17,10 +19,37 @@ public final class Main extends JavaPlugin {
|
|||||||
tabCompleter = new MineChatGPTTabCompleter(configManager);
|
tabCompleter = new MineChatGPTTabCompleter(configManager);
|
||||||
Objects.requireNonNull(getCommand("chatgpt")).setExecutor(commandHandler);
|
Objects.requireNonNull(getCommand("chatgpt")).setExecutor(commandHandler);
|
||||||
Objects.requireNonNull(getCommand("chatgpt")).setTabCompleter(tabCompleter);
|
Objects.requireNonNull(getCommand("chatgpt")).setTabCompleter(tabCompleter);
|
||||||
|
checkAndUpdateConfig();
|
||||||
|
// Initialize bStats
|
||||||
|
int pluginId = 22635;
|
||||||
|
new Metrics(this, pluginId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void checkAndUpdateConfig() {
|
||||||
|
String currentVersion = getConfig().getString("version", "1.0");
|
||||||
|
String pluginVersion = getDescription().getVersion();
|
||||||
|
|
||||||
|
if (!currentVersion.equals(pluginVersion)) {
|
||||||
|
// 加载默认配置文件
|
||||||
|
FileConfiguration defaultConfig = getConfig();
|
||||||
|
reloadConfig();
|
||||||
|
FileConfiguration newConfig = getConfig();
|
||||||
|
|
||||||
|
// 合并配置文件
|
||||||
|
for (String key : defaultConfig.getKeys(true)) {
|
||||||
|
if (!newConfig.contains(key)) {
|
||||||
|
newConfig.set(key, defaultConfig.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新版本号
|
||||||
|
newConfig.set("version", pluginVersion);
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,11 +31,13 @@ messages:
|
|||||||
help_reload: "&e/chatgpt reload - Reload the configuration file."
|
help_reload: "&e/chatgpt reload - Reload the configuration file."
|
||||||
help_model: "&e/chatgpt model <model_name> - Switch to a different model."
|
help_model: "&e/chatgpt model <model_name> - Switch to a different model."
|
||||||
help_modellist: "&e/chatgpt modellist - List available models."
|
help_modellist: "&e/chatgpt modellist - List available models."
|
||||||
usage: "&cUsage: /chatgpt model <model_name>"
|
current_model_info: "&eCurrent model: %s. Use /chatgpt model <model_name> to switch models."
|
||||||
model_switch: "&aModel switched to %s"
|
model_switch: "&aModel switched to %s"
|
||||||
chatgpt_error: "&cFailed to contact ChatGPT."
|
chatgpt_error: "&cFailed to contact ChatGPT."
|
||||||
chatgpt_response: "&bChatGPT: %s"
|
chatgpt_response: "&bChatGPT: %s"
|
||||||
question: "&bYou: %s"
|
question: "&bYou: %s"
|
||||||
invalid_model: "&cInvalid model. Use /chatgpt modellist to see available models."
|
invalid_model: "&cInvalid model. Use /chatgpt modellist to see available models."
|
||||||
available_models: "&eAvailable models:"
|
available_models: "&eAvailable models:"
|
||||||
no_permission: "&cYou do not have permission to use this command. Required permission: %s"
|
no_permission: "&cYou do not have permission to use this command. Required permission: %s"
|
||||||
|
# DO NOT EDIT!!!!!
|
||||||
|
version: 2.2
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# API 相关设置
|
# API 相关设置
|
||||||
api:
|
api:
|
||||||
# 你的 OpenAI API key,用于身份验证
|
# 你的 OpenAI API key,用于身份验证
|
||||||
# 获取 API key 的方法:访问 //platform.openai.com/account/api-keys 并创建一个新的 API key
|
# 获取 API key 的方法:访问 https://platform.openai.com/account/api-keys 并创建一个新的 API key
|
||||||
key: "sk-your_openai_api_key"
|
key: "sk-your_openai_api_key"
|
||||||
# OpenAI API 的基础 URL,用于构建请求
|
# OpenAI API 的基础 URL,用于构建请求
|
||||||
base_url: "https://api.openai.com/v1"
|
base_url: "https://api.openai.com/v1"
|
||||||
@@ -31,11 +31,13 @@ messages:
|
|||||||
help_reload: "&e/chatgpt reload - 重新加载配置文件"
|
help_reload: "&e/chatgpt reload - 重新加载配置文件"
|
||||||
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
|
help_model: "&e/chatgpt model <model_name> - 切换至其他模型"
|
||||||
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
|
help_modellist: "&e/chatgpt modellist - 可用的模型列表"
|
||||||
usage: "&c输入: /chatgpt model <model_name>"
|
current_model_info: "&e当前模型:%s,输入 /chatgpt model <model_name> 来切换模型。"
|
||||||
model_switch: "&a已切换至模型 %s"
|
model_switch: "&a已切换至模型 %s"
|
||||||
chatgpt_error: "&c无法联系ChatGPT。"
|
chatgpt_error: "&c无法联系ChatGPT。"
|
||||||
chatgpt_response: "&bChatGPT: %s"
|
chatgpt_response: "&bChatGPT: %s"
|
||||||
question: "&b你: %s"
|
question: "&b你: %s"
|
||||||
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
|
invalid_model: "&c模型无效。使用 /chatgpt modellist 查看可用模型。"
|
||||||
available_models: "&e可用模型列表:"
|
available_models: "&e可用模型列表:"
|
||||||
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
|
no_permission: "&c你没有权限使用这个指令。需要的权限:%s"
|
||||||
|
# 不要动!!!!!
|
||||||
|
version: 2.2
|
||||||
Reference in New Issue
Block a user