mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-03 02:30:01 +08:00
update
This commit is contained in:
@@ -10,7 +10,6 @@ from configs.config import UPDATE_GOCQ_GROUP
|
||||
from pathlib import Path
|
||||
|
||||
path = str((Path() / "resources" / "gocqhttp_file").absolute()) + '/'
|
||||
print(path)
|
||||
|
||||
lasted_gocqhttp = on_command("更新gocq", permission=GROUP, priority=5, block=True)
|
||||
|
||||
@@ -23,7 +22,7 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
# try:
|
||||
if event.group_id in UPDATE_GOCQ_GROUP:
|
||||
await lasted_gocqhttp.send('检测中...')
|
||||
info = await download_gocq_lasted()
|
||||
info = await download_gocq_lasted(path)
|
||||
if info == 'gocqhttp没有更新!':
|
||||
await lasted_gocqhttp.finish('gocqhttp没有更新!')
|
||||
if _ulmt.check(event.group_id):
|
||||
@@ -31,7 +30,7 @@ async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
_ulmt.set_True(event.group_id)
|
||||
try:
|
||||
for file in os.listdir(path):
|
||||
await upload_gocq_lasted(file, event.group_id)
|
||||
await upload_gocq_lasted(path, file, event.group_id)
|
||||
logger.info(f'更新了cqhttp...{file}')
|
||||
await lasted_gocqhttp.send(f'gocqhttp更新了,已上传成功!\n更新内容:\n{info}')
|
||||
except Exception as e:
|
||||
@@ -49,13 +48,13 @@ async def _():
|
||||
if UPDATE_GOCQ_GROUP:
|
||||
bot = get_bot()
|
||||
try:
|
||||
info = await download_gocq_lasted()
|
||||
info = await download_gocq_lasted(path)
|
||||
if info == 'gocqhttp没有更新!':
|
||||
logger.info('gocqhttp没有更新!')
|
||||
return
|
||||
for group in UPDATE_GOCQ_GROUP:
|
||||
for file in os.listdir(path):
|
||||
await upload_gocq_lasted(file, group)
|
||||
await upload_gocq_lasted(path, file, group)
|
||||
await bot.send_group_msg(group_id=group, message=f"gocqhttp更新了,已上传成功!\n更新内容:\n{info}")
|
||||
except Exception as e:
|
||||
logger.error(f'自动更新gocq出错 e:{e}')
|
||||
|
||||
@@ -7,16 +7,13 @@ import aiofiles
|
||||
from bs4 import BeautifulSoup
|
||||
import os
|
||||
if platform.system() == 'Windows':
|
||||
path = os.getcwd() + '/resources/gocqhttp_file/'
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
else:
|
||||
path = r'/home/hibiki/hibikibot/resources/gocqhttp_file/'
|
||||
|
||||
|
||||
url = 'https://github.com/Mrs4s/go-cqhttp/releases'
|
||||
|
||||
|
||||
async def download_gocq_lasted():
|
||||
async def download_gocq_lasted(path: str):
|
||||
async with aiohttp.ClientSession(headers=get_user_agent()) as session:
|
||||
async with session.get(url, proxy=get_local_proxy()) as response:
|
||||
soup = BeautifulSoup(await response.text(), 'lxml')
|
||||
@@ -52,7 +49,7 @@ async def download_gocq_lasted():
|
||||
return update_info
|
||||
|
||||
|
||||
async def upload_gocq_lasted(name, group_id):
|
||||
async def upload_gocq_lasted(path, name, group_id):
|
||||
bot = get_bot()
|
||||
folder_id = 0
|
||||
for folder in (await bot.get_group_root_files(group_id=group_id))['folders']:
|
||||
|
||||
Reference in New Issue
Block a user