mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
💥 将core_config中的proxy
分离成Gproxy
和Nproxy
, 并添加配置自动排序
This commit is contained in:
parent
f9336656ea
commit
80ada522e4
@ -67,7 +67,8 @@ from .models import (
|
||||
LoginTicketInfo,
|
||||
)
|
||||
|
||||
proxy_url = core_plugins_config.get_config('proxy').data
|
||||
Gproxy = core_plugins_config.get_config('Gproxy').data
|
||||
Nproxy = core_plugins_config.get_config('Nproxy').data
|
||||
ssl_verify = core_plugins_config.get_config('MhySSLVerify').data
|
||||
RECOGNIZE_SERVER = {
|
||||
'1': 'cn_gf01',
|
||||
@ -81,7 +82,8 @@ RECOGNIZE_SERVER = {
|
||||
|
||||
|
||||
class BaseMysApi:
|
||||
proxy_url: Optional[str] = proxy_url if proxy_url else None
|
||||
Gproxy: Optional[str] = Gproxy if Gproxy else None
|
||||
Nproxy: Optional[str] = Nproxy if Nproxy else None
|
||||
mysVersion = mys_version
|
||||
_HEADER = {
|
||||
'x-rpc-app_version': mysVersion,
|
||||
@ -378,6 +380,13 @@ class BaseMysApi:
|
||||
data: Optional[Dict[str, Any]] = None,
|
||||
use_proxy: Optional[bool] = False,
|
||||
) -> Union[Dict, int]:
|
||||
if use_proxy and self.Gproxy:
|
||||
proxy = self.Gproxy
|
||||
elif self.Nproxy and not use_proxy:
|
||||
proxy = self.Nproxy
|
||||
else:
|
||||
proxy = None
|
||||
|
||||
async with ClientSession(
|
||||
connector=TCPConnector(verify_ssl=ssl_verify)
|
||||
) as client:
|
||||
@ -414,7 +423,7 @@ class BaseMysApi:
|
||||
headers=header,
|
||||
params=params,
|
||||
json=data,
|
||||
proxy=self.proxy_url if use_proxy else None,
|
||||
proxy=proxy,
|
||||
timeout=300,
|
||||
) as resp:
|
||||
try:
|
||||
@ -1159,13 +1168,20 @@ class MysApi(BaseMysApi):
|
||||
data['game_biz'] = 'hk4e_global'
|
||||
use_proxy = True
|
||||
|
||||
if use_proxy and self.Gproxy:
|
||||
proxy = self.Gproxy
|
||||
elif self.Nproxy and not use_proxy:
|
||||
proxy = self.Nproxy
|
||||
else:
|
||||
proxy = None
|
||||
|
||||
async with ClientSession() as client:
|
||||
async with client.request(
|
||||
method='POST',
|
||||
url=url,
|
||||
headers=header,
|
||||
json=data,
|
||||
proxy=self.proxy_url if use_proxy else None,
|
||||
proxy=proxy,
|
||||
timeout=300,
|
||||
) as resp:
|
||||
raw_data = await resp.json()
|
||||
|
@ -3,7 +3,8 @@ from typing import Dict
|
||||
from .models import GSC, GsStrConfig, GsBoolConfig, GsListStrConfig
|
||||
|
||||
CONIFG_DEFAULT: Dict[str, GSC] = {
|
||||
'proxy': GsStrConfig('设置代理', '设置国际服的代理地址', ''),
|
||||
'Gproxy': GsStrConfig('设置米游社国际代理', '设置国际服的代理地址', ''),
|
||||
'Nproxy': GsStrConfig('设置米游社常规代理', '设置常规的代理地址', ''),
|
||||
'_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''),
|
||||
'restart_command': GsStrConfig(
|
||||
'重启命令',
|
||||
|
@ -53,6 +53,13 @@ class StringConfig:
|
||||
def __getitem__(self, key) -> GSC:
|
||||
return self.config[key]
|
||||
|
||||
def sort_config(self):
|
||||
_config = {}
|
||||
for i in self.config_list:
|
||||
_config[i] = self.config[i]
|
||||
self.config = _config
|
||||
self.write_config()
|
||||
|
||||
def write_config(self):
|
||||
with open(self.CONFIG_PATH, 'wb') as file:
|
||||
file.write(msgjson.format(msgjson.encode(self.config), indent=4))
|
||||
@ -78,7 +85,7 @@ class StringConfig:
|
||||
self.config.pop(key)
|
||||
|
||||
# 重新写回
|
||||
self.write_config()
|
||||
self.sort_config()
|
||||
|
||||
def get_config(self, key: str) -> Any:
|
||||
if key in self.config:
|
||||
|
Loading…
x
Reference in New Issue
Block a user