Archived
1
0
Fork 0
This commit is contained in:
多羅狼 2023-12-07 20:35:07 +08:00 committed by GitHub
parent 4399f940c2
commit 4f8e8e2061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 56 deletions

4
bot.py
View file

@ -51,9 +51,7 @@ def run_bot():
cache_path = os.path.abspath(Config('cache_path'))
if os.path.exists(cache_path):
shutil.rmtree(cache_path)
os.mkdir(cache_path)
else:
os.mkdir(cache_path)
os.mkdir(cache_path)
pid_cache = os.path.abspath('.pid_last')
if os.path.exists(pid_cache):

View file

@ -39,7 +39,7 @@ async def _(msg: Bot.MessageSession, use_local=True):
use_local = False
resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' +
urllib.parse.quote('https://webapi.lowiro.com/webapi/serve/static/bin/arcaea/apk/'), 200,
fmt='json')
fmt='json', request_private_ip=True)
if resp:
await msg.finish([Plain(msg.locale.t("arcaea.message.download", version=resp["value"]["version"],
url=resp['value']['url']))])
@ -56,7 +56,7 @@ async def _(msg: Bot.MessageSession, use_local=True):
use_local = False
resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' +
urllib.parse.quote('https://webapi.lowiro.com/webapi/song/showcase/'),
200, fmt='json')
200, fmt='json', request_private_ip=True)
if resp:
value = resp["value"][0]
image = f'{assets_path}/jacket/{value["song_id"]}.jpg'
@ -68,7 +68,8 @@ async def _(msg: Bot.MessageSession, use_local=True):
await msg.finish(msg.locale.t("arcaea.message.get_failed"))
@arc.command('rank free {{arcaea.help.rank.free}}', 'rank paid {{arcaea.help.rank.paid}}')
@arc.command('rank free {{arcaea.help.rank.free}}',
'rank paid {{arcaea.help.rank.paid}}')
async def _(msg: Bot.MessageSession, use_local=True):
if not web_render_local:
if not web_render:
@ -78,10 +79,11 @@ async def _(msg: Bot.MessageSession, use_local=True):
if msg.parsed_msg.get('free', False):
resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' +
urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/free/'),
200, fmt='json')
200, fmt='json', request_private_ip=True)
else:
resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' +
urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/paid/'), 200, fmt='json')
urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/paid/'),
200, fmt='json', request_private_ip=True)
if resp:
r = []
rank = 0

View file

@ -169,9 +169,7 @@ async def _():
Logger.info('Start purging cache...')
if os.path.exists(cache_path):
shutil.rmtree(cache_path)
os.mkdir(cache_path)
else:
os.mkdir(cache_path)
os.mkdir(cache_path)
set_ = module('set', required_superuser=True, base=True)

View file

@ -408,7 +408,7 @@ async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]:
elif str(e).startswith('403'):
await msg.finish(msg.locale.t("maimai.message.forbidden"))
else:
await msg.finish(ErrorMessage(str(e)))
raise
sd_best = BestList(35)
dx_best = BestList(15)

View file

@ -15,51 +15,45 @@ cover_dir = f"{assets_path}/static/mai/cover"
async def update_alias():
try:
url = "https://download.fanyu.site/maimai/alias.json"
input_data = await get_url(url, 200, fmt='json')
url = "https://download.fanyu.site/maimai/alias.json"
input_data = await get_url(url, 200, fmt='json')
output_data = {}
for key, values in input_data.items():
for value in values:
if value == "未找到":
continue
if value not in output_data:
output_data[value] = []
output_data[value].append(key)
output_data = {}
for key, values in input_data.items():
for value in values:
if value == "未找到":
continue
if value not in output_data:
output_data[value] = []
output_data[value].append(key)
output_data = {k: output_data[k] for k in sorted(output_data)}
output_data = {k: output_data[k] for k in sorted(output_data)}
file_path = os.path.join(assets_path, "mai_alias.json")
with open(file_path, 'w') as file:
json.dump(output_data, file)
return True
except:
return False
file_path = os.path.join(assets_path, "mai_alias.json")
with open(file_path, 'w') as file:
json.dump(output_data, file)
return True
async def update_covers():
try:
url = f"https://www.diving-fish.com/maibot/static.zip"
download_file = await download_to_cache(url, timeout=60)
url = f"https://www.diving-fish.com/maibot/static.zip"
download_file = await download_to_cache(url, timeout=60)
Logger.info('Maimai covers download completed.')
ca = random_cache_path()
shutil.unpack_archive(download_file, ca)
Logger.info('Maimai covers download completed.')
ca = random_cache_path()
shutil.unpack_archive(download_file, ca)
if os.path.exists(cover_dir):
shutil.rmtree(cover_dir)
if os.path.exists(cover_dir):
shutil.rmtree(cover_dir)
static_cover_dir = os.path.join(ca, 'mai/cover')
if os.path.exists(static_cover_dir):
shutil.move(static_cover_dir, cover_dir)
static_cover_dir = os.path.join(ca, 'mai/cover')
if os.path.exists(static_cover_dir):
shutil.move(static_cover_dir, cover_dir)
os.remove(download_file)
return True
except:
return False
os.remove(download_file)
return True
async def get_alias(msg, input_):
@ -117,7 +111,7 @@ async def get_record(msg, payload):
elif str(e).startswith('403'):
await msg.finish(msg.locale.t("maimai.message.forbidden"))
else:
await msg.finish(ErrorMessage(str(e)))
raise
return data
@ -137,5 +131,5 @@ async def get_plate(msg, payload):
elif str(e).startswith('403'):
await msg.finish(msg.locale.t("maimai.message.forbidden"))
else:
await msg.finish(ErrorMessage(str(e)))
raise
return data

View file

@ -1,11 +1,15 @@
from config import Config
from core.builtins import Bot
from core.logger import Logger
from core.scheduler import CronTrigger
from core.scheduler import Scheduler
from core.scheduler import CronTrigger, Scheduler
from modules.maimai.libraries.maimaidx_api_data import update_alias
@Scheduler.scheduled_job(CronTrigger.from_crontab('0 0 * * *'))
async def maimai_alias():
Logger.info('Updating maimai alias...')
await update_alias()
try:
await update_alias()
except Exception:
if Config('debug'):
Logger.error(traceback.format_exc())

View file

@ -1,8 +1,7 @@
from core.builtins import Bot
from core.logger import Logger
from core.queue import JobQueue
from core.scheduler import CronTrigger
from core.scheduler import Scheduler
from core.scheduler import CronTrigger, Scheduler
from modules.weekly import get_weekly
from modules.weekly.teahouse import get_rss as get_teahouse_rss