update: Questions.md 23-07-03 (#2721)

* update: Questions.md

* update: Questions.md

* update: Questions.md

* add: tips
This commit is contained in:
cssxsh 2023-07-05 22:51:32 +08:00 committed by GitHub
parent 685fb2d3d9
commit eecff3bc4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,11 +59,19 @@ Mirai Console 的组件在 `libs` 文件夹下, 文件名包含 `版本信息`
Linux 和 macOS 的启动脚本是 `mcl` (没有后缀的那个文件)。
> MCL 不能更新到最新版 Mirai
编辑 `config.json`
修改 `maven_repo``https://repo.huaweicloud.com/repository/maven` (默认是阿里云,更新很不及时)
`packages``net.mamoe:` 开头的项的 `channel` 改为 `maven` (最新版) 或 `maven-stable` (最新稳定版)
## 开发者常见问题
> 如何自定义登录验证处理
[覆盖登录解决器](https://github.com/mamoe/mirai/blob/dev/docs/Bots.md#%E8%A6%86%E7%9B%96%E7%99%BB%E5%BD%95%E8%A7%A3%E5%86%B3%E5%99%A8)
扫码登陆,滑块处理等
[覆盖登录解决器](Bots.md#覆盖登录解决器)
> IDEA 下 `import` 爆红mirai 相关依赖全部无法解析
@ -84,3 +92,60 @@ IDEA 版本过于老旧,无法分析新版本的 Kotlin 依赖,请尝试升
> 发送语音之后播放没有声音
你可能需要安装插件或引入依赖 <https://github.com/project-mirai/mirai-silk-converter>
> Mirai Console 插件找不到类
1. 使用了私有的第三方库
你需要使用 `shadowLink`
参照 [打包依赖](../mirai-console/tools/gradle-plugin/README.md#打包依赖)
2. 使用 数据库框架/反射框架 但找不到 驱动类/实体类
你需要将**上下文**切换到插件中,或者指定 `ClassLoader`
相关内容请参考 [JVM Plugins - Debug](../mirai-console/docs/plugin/JVMPlugin-Debug.md)
下面只列出部分例子,请根据你所使用的框架的文档进行修整。
切换上下文:
```java
import java.util.ServiceLoader;
public class SQL {
void load() {
Thread current = Thread.currentThread();
ClassLoader context = current.getContextClassLoader();
ClassLoader plugin = this.getClass().getClassLoader();
try {
current.setContextClassLoader(plugin);
ServiceLoader.load(java.sql.Driver.class).reload();
// database load ...
} finally {
current.setContextClassLoader(context);
}
}
}
```
指定 `ClassLoader`
```java
import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.MappedSuperclass;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import java.util.Set;
public class SQL {
Set<Class<?>> load() {
ClassLoader plugin = this.getClass().getClassLoader();
ConfigurationBuilder builder = new ConfigurationBuilder()
.forPackage("org.example", plugin)
.addClassLoaders(plugin); // 指定从插件的类加载器中检索类
Reflections reflections = new Reflections(builder);
Set<Class<?>> query = org.reflections.scanners.Scanners.TypesAnnotated
.of(Entity.class, Embeddable.class, MappedSuperclass.class)
.asClass(plugin) // 指定从插件的类加载器中提取类
.apply(reflections.getStore());
return query;
}
}
```