mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-05-12 06:55:49 +08:00
🎨 新增依赖和方法
This commit is contained in:
parent
ae8ab23650
commit
41e345621a
@ -40,35 +40,14 @@ class GsClient:
|
|||||||
async def send_msg(self):
|
async def send_msg(self):
|
||||||
while True:
|
while True:
|
||||||
intent = await self._input()
|
intent = await self._input()
|
||||||
for content in [
|
content = Message(type='text', data=intent)
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data='开始一场60秒的游戏'),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data='233'),
|
|
||||||
Message(type='text', data='233'),
|
|
||||||
Message(type='text', data='233'),
|
|
||||||
Message(type='text', data='233'),
|
|
||||||
Message(type='text', data='233'),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
Message(type='text', data=intent),
|
|
||||||
]:
|
|
||||||
user_type = random.choice(['direct', 'group'])
|
|
||||||
group_id = random.choice(['555', '666', '777'])
|
group_id = random.choice(['555', '666', '777'])
|
||||||
user_id = random.choice(['1', '2', '3', '4', '5'])
|
|
||||||
if content.data == '开始一场60秒的游戏':
|
|
||||||
user_type = 'group'
|
|
||||||
group_id = '555'
|
|
||||||
msg = MessageReceive(
|
msg = MessageReceive(
|
||||||
bot_id='console',
|
bot_id='console',
|
||||||
user_type=user_type, # type: ignore
|
user_type='group',
|
||||||
user_pm=1,
|
user_pm=0,
|
||||||
group_id=group_id,
|
group_id=group_id,
|
||||||
user_id=user_id,
|
user_id='511',
|
||||||
content=[content],
|
content=[content],
|
||||||
)
|
)
|
||||||
msg_send = msgjson.encode(msg)
|
msg_send = msgjson.encode(msg)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import json
|
||||||
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
|
import httpx
|
||||||
import aiofiles
|
import aiofiles
|
||||||
from aiohttp.client import ClientSession
|
from aiohttp.client import ClientSession
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
@ -26,3 +29,32 @@ async def download(
|
|||||||
logger.info(f'{tag} {name} 下载完成!')
|
logger.info(f'{tag} {name} 下载完成!')
|
||||||
except ClientConnectorError:
|
except ClientConnectorError:
|
||||||
logger.warning(f"{tag} {name} 下载失败!")
|
logger.warning(f"{tag} {name} 下载失败!")
|
||||||
|
|
||||||
|
|
||||||
|
async def get_data_from_url(
|
||||||
|
url: str, path: Path, expire_sec: Optional[float] = None
|
||||||
|
) -> Dict:
|
||||||
|
time_difference = 10
|
||||||
|
if path.exists() and expire_sec is not None:
|
||||||
|
modified_time = path.stat().st_mtime
|
||||||
|
modified_datetime = datetime.datetime.fromtimestamp(modified_time)
|
||||||
|
current_datetime = datetime.datetime.now()
|
||||||
|
|
||||||
|
time_difference = (
|
||||||
|
current_datetime - modified_datetime
|
||||||
|
).total_seconds()
|
||||||
|
|
||||||
|
if (
|
||||||
|
expire_sec is not None and time_difference >= expire_sec
|
||||||
|
) or not path.exists():
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
response = await client.get(url)
|
||||||
|
data = response.json()
|
||||||
|
async with aiofiles.open(path, 'w', encoding='UTF-8') as file:
|
||||||
|
await file.write(
|
||||||
|
json.dumps(data, indent=4, ensure_ascii=False)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
async with aiofiles.open(path, 'r', encoding='UTF-8') as file:
|
||||||
|
data = json.loads(await file.read())
|
||||||
|
return data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user