mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-02 21:37:24 +00:00
refactor(launch): 统一代理的使用.
之前的版本中, 如果未指定 Maven 仓库的独立代理配置, 同时 Bot 拥有独立代理配置的情况下, Aether 将不会使用 Bot 的独立代理配置, 这样弄比较乱, 因此统一代理配置的使用顺序: - 如果配置中包括了代理配置, 则优先使用独立代理配置; - 如果不包括独立代理配置, 则使用关联 Bot 的独立代理配置; - 如果关联 Bot 没有独立代理配置, 则使用 AppConfig 中的全局配置(如无配置则直连访问).
This commit is contained in:
@ -4,10 +4,7 @@ import com.google.gson.JsonParseException
|
||||
import io.prometheus.client.exporter.HTTPServer
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import mu.KotlinLogging
|
||||
import net.lamgc.scalabot.config.AppConfig
|
||||
import net.lamgc.scalabot.config.BotConfig
|
||||
import net.lamgc.scalabot.config.MetricsConfig
|
||||
import net.lamgc.scalabot.config.ProxyType
|
||||
import net.lamgc.scalabot.config.*
|
||||
import net.lamgc.scalabot.util.registerShutdownHook
|
||||
import org.eclipse.aether.repository.LocalRepository
|
||||
import org.telegram.telegrambots.bots.DefaultBotOptions
|
||||
@ -154,16 +151,20 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos
|
||||
return
|
||||
}
|
||||
log.info { "正在启动机器人 `${botConfig.account.name}`..." }
|
||||
val proxyConfig =
|
||||
if (botConfig.proxy.type != ProxyType.NO_PROXY) {
|
||||
log.debug { "[Bot ${botConfig.account.name}] 使用独立代理: ${botConfig.proxy.type}" }
|
||||
botConfig.proxy
|
||||
} else if (config.proxy.type != ProxyType.NO_PROXY) {
|
||||
log.debug { "[Bot ${botConfig.account.name}] 使用全局代理: ${botConfig.proxy.type}" }
|
||||
config.proxy
|
||||
} else {
|
||||
log.debug { "[Bot ${botConfig.account.name}] 不使用代理." }
|
||||
ProxyConfig(type = ProxyType.NO_PROXY)
|
||||
}
|
||||
|
||||
val botOption = DefaultBotOptions().apply {
|
||||
val proxyConfig =
|
||||
if (botConfig.proxy.type != ProxyType.NO_PROXY) {
|
||||
botConfig.proxy
|
||||
} else if (config.proxy.type != ProxyType.NO_PROXY) {
|
||||
config.proxy
|
||||
} else {
|
||||
null
|
||||
}
|
||||
if (proxyConfig != null) {
|
||||
if (proxyConfig.type != ProxyType.NO_PROXY) {
|
||||
proxyType = proxyConfig.type.toTelegramBotsType()
|
||||
proxyHost = config.proxy.host
|
||||
proxyPort = config.proxy.port
|
||||
@ -175,7 +176,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos
|
||||
val account = botConfig.account
|
||||
|
||||
val remoteRepositories = config.mavenRepositories
|
||||
.map { it.toRemoteRepository(config.proxy) }
|
||||
.map { it.toRemoteRepository(proxyConfig) }
|
||||
.toMutableList().apply {
|
||||
if (this.none {
|
||||
it.url == MavenRepositoryExtensionFinder.MAVEN_CENTRAL_URL
|
||||
|
Reference in New Issue
Block a user