mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-03 05:47:24 +00:00
feat: 将 TelegramBots 升级至 8.0.0, 并适配 TelegramBots 的新改动.
将 TelegramBots 升级至新版本, 以支持新的 API. 由于 TelegramBots 发生无法兼容旧版本的重大变更, 因此 ScalaBot 将随着此次更新一同进行重大更改. BREAKING CHANGE: ScalaBot 所依赖的 TelegramBots 发生重大更改, 所有扩展都需要进行适配. 有关 TelegramBots 的重大变更说明请参考官方文档. ScalaBot 的最低 Java 版本已全部升级至 Java 17 (这是 TelegramBots 的最低兼容性要求), 所有扩展都应该至少迁移至 Java 17 版本. ScalaBot 的重大更改: - scalabot-extension - `net.lamgc.scalabot.extension.util.AbilityBots.getBotAccountId(BaseAbilityBot): long` 已被移除, 由于 BaseAbilityBot 不再允许获取 botToken, 因此该方法被移除. 作为代替, 请通过 `net.lamgc.scalabot.extension.BotExtensionFactory.createExtensionInstance` 所得到的 `BotExtensionCreateOptions` 中获取 botAccountId. 另外, scalabot-extension 中的 `org.jetbrains.kotlinx.binary-compatibility-validator` 似乎不再对 Java 代码起作用, 因此移除该插件, 并在后续寻找替代品. TelegramBots 文档: https://rubenlagus.github.io/TelegramBotsDocumentation/how-to-update-7.html
This commit is contained in:
@ -10,9 +10,9 @@ import net.lamgc.scalabot.config.ProxyConfig
|
||||
import net.lamgc.scalabot.config.ProxyType
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.Proxy
|
||||
import java.net.URL
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
@ -23,7 +23,7 @@ internal class AppPathsTest {
|
||||
|
||||
@Test
|
||||
fun `Consistency check`() {
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertEquals(
|
||||
File(path.path).canonicalPath,
|
||||
path.file.canonicalPath,
|
||||
@ -226,17 +226,17 @@ internal class AppPathsTest {
|
||||
@Test
|
||||
fun `ProxyType_toTelegramBotsType test`() {
|
||||
val expectTypeMapping = mapOf(
|
||||
ProxyType.NO_PROXY to DefaultBotOptions.ProxyType.NO_PROXY,
|
||||
ProxyType.SOCKS5 to DefaultBotOptions.ProxyType.SOCKS5,
|
||||
ProxyType.SOCKS4 to DefaultBotOptions.ProxyType.SOCKS4,
|
||||
ProxyType.HTTP to DefaultBotOptions.ProxyType.HTTP,
|
||||
ProxyType.HTTPS to DefaultBotOptions.ProxyType.HTTP
|
||||
ProxyType.NO_PROXY to null,
|
||||
ProxyType.SOCKS5 to Proxy.Type.SOCKS,
|
||||
ProxyType.SOCKS4 to Proxy.Type.SOCKS,
|
||||
ProxyType.HTTP to Proxy.Type.HTTP,
|
||||
ProxyType.HTTPS to Proxy.Type.HTTP
|
||||
)
|
||||
|
||||
for (proxyType in ProxyType.values()) {
|
||||
for (proxyType in ProxyType.entries) {
|
||||
assertEquals(
|
||||
expectTypeMapping[proxyType],
|
||||
proxyType.toTelegramBotsType(),
|
||||
proxyType.toJavaProxyType(),
|
||||
"ProxyType 转换失败."
|
||||
)
|
||||
}
|
||||
@ -251,7 +251,7 @@ internal class AppPathsTest {
|
||||
ProxyType.HTTP,
|
||||
ProxyType.HTTPS
|
||||
)
|
||||
for (proxyType in ProxyType.values()) {
|
||||
for (proxyType in ProxyType.entries) {
|
||||
val proxyConfig = ProxyConfig(proxyType, host, port)
|
||||
val aetherProxy = proxyConfig.toAetherProxy()
|
||||
if (expectNotNullProxyType.contains(proxyType)) {
|
||||
@ -337,7 +337,7 @@ internal class AppPathsTest {
|
||||
|
||||
assertTrue(initialFiles(), "方法未能提醒用户编辑初始配置文件.")
|
||||
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertTrue(path.file.exists(), "文件未初始化成功: ${path.path}")
|
||||
if (path.file.isFile) {
|
||||
assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}")
|
||||
@ -347,7 +347,7 @@ internal class AppPathsTest {
|
||||
|
||||
assertFalse(initialFiles(), "方法试图在配置已初始化的情况下提醒用户编辑初始配置文件.")
|
||||
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertTrue(path.file.exists(), "文件未初始化成功: ${path.path}")
|
||||
if (path.file.isFile) {
|
||||
assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}")
|
||||
@ -358,7 +358,7 @@ internal class AppPathsTest {
|
||||
assertTrue(AppPaths.CONFIG_APPLICATION.file.delete(), "config.json 删除失败.")
|
||||
assertFalse(initialFiles(), "方法试图在部分配置已初始化的情况下提醒用户编辑初始配置文件.")
|
||||
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertTrue(path.file.exists(), "文件未初始化成功: ${path.path}")
|
||||
if (path.file.isFile) {
|
||||
assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}")
|
||||
@ -369,7 +369,7 @@ internal class AppPathsTest {
|
||||
assertTrue(AppPaths.CONFIG_BOT.file.delete(), "bot.json 删除失败.")
|
||||
assertFalse(initialFiles(), "方法试图在部分配置已初始化的情况下提醒用户编辑初始配置文件.")
|
||||
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertTrue(path.file.exists(), "文件未初始化成功: ${path.path}")
|
||||
if (path.file.isFile) {
|
||||
assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}")
|
||||
@ -384,7 +384,7 @@ internal class AppPathsTest {
|
||||
"在主要配置文件(config.json 和 bot.json)不存在的情况下初始化文件后, 方法未能提醒用户编辑初始配置文件."
|
||||
)
|
||||
|
||||
for (path in AppPaths.values()) {
|
||||
for (path in AppPaths.entries) {
|
||||
assertTrue(path.file.exists(), "文件未初始化成功: ${path.path}")
|
||||
if (path.file.isFile) {
|
||||
assertNotEquals(0, path.file.length(), "文件未初始化成功(大小为 0): ${path.path}")
|
||||
|
Reference in New Issue
Block a user