Archived
1
0
Fork 0
This commit is contained in:
多羅狼 2023-11-09 13:12:48 +08:00 committed by GitHub
parent d9918a3f81
commit 1e3cb3b89e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 45 deletions

View file

@ -72,5 +72,6 @@ dice_output_len = 200
dice_detail_cnt = 5 dice_detail_cnt = 5
dice_count_limit = 10 dice_count_limit = 10
api_port = 5000 api_port = 5000
enable_langsmith = false
langsmith_endpoint = "https://api.smith.langchain.com" langsmith_endpoint = "https://api.smith.langchain.com"
langsmith_project = langsmith_project =

View file

@ -20,21 +20,23 @@ PRICE_PER_1K_TOKEN = BASE_COST_GPT_3_5 * THIRD_PARTY_MULTIPLIER * PROFIT_MULTIPL
USD_TO_CNY = Decimal('7.3') # Assuming 1 USD = 7.3 CNY USD_TO_CNY = Decimal('7.3') # Assuming 1 USD = 7.3 CNY
CNY_TO_PETAL = 100 # 100 petal = 1 CNY CNY_TO_PETAL = 100 # 100 petal = 1 CNY
import json
from datetime import datetime, timedelta
async def get_petal_exchange_rate(): async def get_petal_exchange_rate():
api_key = Config('exchange_rate_api_key') api_key = Config('exchange_rate_api_key')
api_url = f'https://v6.exchangerate-api.com/v6/{api_key}/pair/USD/CNY' api_url = f'https://v6.exchangerate-api.com/v6/{api_key}/pair/USD/CNY'
data = await get_url(api_url, 200, fmt='json') try:
if data['result'] == "success": data = await get_url(api_url, 200, fmt='json')
exchange_rate = data['conversion_rate'] if data['result'] == "success":
petal_value = exchange_rate * CNY_TO_PETAL exchange_rate = data['conversion_rate']
return {"exchange_rate": exchange_rate, "exchanged_petal": petal_value} petal_value = exchange_rate * CNY_TO_PETAL
return None return {"exchange_rate": exchange_rate, "exchanged_petal": petal_value}
except:
return None
import json
from datetime import datetime, timedelta
async def load_or_refresh_cache(): async def load_or_refresh_cache():
cache_dir = Config('cache_path') cache_dir = Config('cache_path')
file_path = os.path.join(cache_dir, 'petal_exchange_rate_cache.json') file_path = os.path.join(cache_dir, 'petal_exchange_rate_cache.json')

View file

@ -11,11 +11,11 @@ from core.dirty_check import check_bool, rickroll
from core.petal import count_petal from core.petal import count_petal
from core.utils.cooldown import CoolDown from core.utils.cooldown import CoolDown
os.environ['LANGCHAIN_TRACING_V2'] = "true" os.environ['LANGCHAIN_TRACING_V2'] = str(Config('enable_langsmith'))
os.environ['LANGCHAIN_ENDPOINT'] = Config('langsmith_endpoint') if Config('langsmith_endpoint') is not None else os.environ.get('LANGCHAIN_ENDPOINT') if Config('enable_langsmith'):
os.environ['LANGCHAIN_PROJECT'] = Config('langsmith_project') if Config('langsmith_project') is not None else os.environ.get('LANGCHAIN_PROJECT') os.environ['LANGCHAIN_ENDPOINT'] = Config('langsmith_endpoint')
os.environ['LANGCHAIN_API_KEY'] = Config('langsmith_api_key') if Config('langsmith_api_key') is not None else os.environ.get('LANGCHAIN_API_KEY') os.environ['LANGCHAIN_PROJECT'] = Config('langsmith_project')
os.environ['LANGCHAIN_API_KEY'] = Config('langsmith_api_key')
from langchain.callbacks import get_openai_callback # noqa: E402 from langchain.callbacks import get_openai_callback # noqa: E402
from .agent import agent_executor # noqa: E402 from .agent import agent_executor # noqa: E402

View file

@ -2,7 +2,7 @@
from core.utils.image import msgchain2image from core.utils.image import msgchain2image
from modules.maimai.libraries.maimai_best_50 import generate from modules.maimai.libraries.maimai_best_50 import generate
from modules.maimai.libraries.maimaidx_api_data import get_alias, get_cover, search_by_alias, update_assets from modules.maimai.libraries.maimaidx_api_data import get_alias, search_by_alias, update_assets
from modules.maimai.libraries.maimaidx_music import Music, TotalList from modules.maimai.libraries.maimaidx_music import Music, TotalList
from modules.maimai.libraries.maimaidx_project import get_level_process, get_plate_process, get_player_score, get_rank, \ from modules.maimai.libraries.maimaidx_project import get_level_process, get_plate_process, get_player_score, get_rank, \
get_score_list get_score_list
@ -21,7 +21,7 @@ diff_label_zht = ['綠', '黃', '紅']
def song_txt(music: Music): def song_txt(music: Music):
return [Plain(f"{music.id}\u200B. {music.title}{' (DX)' if music['type'] == 'DX' else ''}\n"), return [Plain(f"{music.id}\u200B. {music.title}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(get_cover(music.id), ), BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music.id)}.png"),
Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}")] Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}")]
@ -199,10 +199,9 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, username: str = None):
output = await get_player_score(msg, payload, sid) output = await get_player_score(msg, payload, sid)
file = get_cover(music['id'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), Plain(output)]) BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"), Plain(output)])
@mai.handle('plate <plate> [<username>] {{maimai.help.plate}}') @mai.handle('plate <plate> [<username>] {{maimai.help.plate}}')
@ -256,8 +255,8 @@ async def _(msg: Bot.MessageSession, level: str, goal: str, username: str = None
if level in level_list: if level in level_list:
level_num = int(level.split('+')[0]) level_num = int(level.split('+')[0])
if level_num < 8: # if level_num < 8:
await msg.finish(msg.locale.t("maimai.message.process.less_than_8")) # await msg.finish(msg.locale.t("maimai.message.process.less_than_8"))
else: else:
await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid")) await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid"))
@ -377,7 +376,6 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None):
chart = music['charts'][diff_index] chart = music['charts'][diff_index]
ds = music['ds'][diff_index] ds = music['ds'][diff_index]
level = music['level'][diff_index] level = music['level'][diff_index]
file = get_cover(music['id'])
if len(chart['notes']) == 4: if len(chart['notes']) == 4:
message = msg.locale.t( message = msg.locale.t(
"maimai.message.song.sd", "maimai.message.song.sd",
@ -403,12 +401,11 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None):
charter=chart['charter']) charter=chart['charter'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), Plain(message)]) BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"), Plain(message)])
else: else:
file = get_cover(music['id'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"),
Plain(msg.locale.t("maimai.message.song", Plain(msg.locale.t("maimai.message.song",
artist=music['basic_info']['artist'], genre=music['basic_info']['genre'], artist=music['basic_info']['artist'], genre=music['basic_info']['genre'],
bpm=music['basic_info']['bpm'], version=music['basic_info']['from'], bpm=music['basic_info']['bpm'], version=music['basic_info']['from'],

View file

@ -136,12 +136,3 @@ async def get_plate(msg, payload):
await msg.finish(msg.locale.t("maimai.message.forbidden")) await msg.finish(msg.locale.t("maimai.message.forbidden"))
return data return data
def get_cover(sid):
cover_url = f"https://www.diving-fish.com/covers/{get_cover_len5_id(sid)}.png"
cover_path = f"{cover_dir}/{get_cover_len5_id(sid)}.png"
if os.path.exists(os.path.abspath(cover_path)):
return os.path.abspath(cover_path)
else:
return cover_url

View file

@ -4,7 +4,7 @@ from core.builtins import Bot, Plain, Image as BImage
from core.component import module from core.component import module
from core.logger import Logger from core.logger import Logger
from core.utils.image import msgchain2image from core.utils.image import msgchain2image
from modules.maimai.libraries.maimaidx_api_data import get_alias, get_cover, search_by_alias from modules.maimai.libraries.maimaidx_api_data import get_alias, search_by_alias
from modules.maimai.libraries.maimaidx_music import Music, TotalList from modules.maimai.libraries.maimaidx_music import Music, TotalList
from modules.maimai.libraries.maimaidx_project import get_level_process, get_plate_process, get_player_score from modules.maimai.libraries.maimaidx_project import get_level_process, get_plate_process, get_player_score
@ -21,7 +21,7 @@ diff_label_zht = ['綠', '黃', '紅']
def song_txt(music: Music): def song_txt(music: Music):
return [Plain(f"{music.id}\u200B. {music.title}{' (DX)' if music['type'] == 'DX' else ''}\n"), return [Plain(f"{music.id}\u200B. {music.title}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(get_cover(music.id), ), BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music.id)}.png"),
Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}")] Plain(f"\n{'/'.join(str(ds) for ds in music.ds)}")]
@ -70,10 +70,9 @@ async def _(msg: Bot.MessageSession):
if not music: if not music:
await msg.finish(msg.locale.t("maimai.message.music_not_found")) await msg.finish(msg.locale.t("maimai.message.music_not_found"))
file = get_cover(music['id'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']} {' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']} {' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"),
Plain(msg.locale.t("maimai.message.song", Plain(msg.locale.t("maimai.message.song",
artist=music['basic_info']['artist'], genre=music['basic_info']['genre'], artist=music['basic_info']['artist'], genre=music['basic_info']['genre'],
bpm=music['basic_info']['bpm'], version=music['basic_info']['from'], bpm=music['basic_info']['bpm'], version=music['basic_info']['from'],
@ -111,11 +110,10 @@ async def _(msg: Bot.MessageSession):
payload = {'username': username} payload = {'username': username}
output = await get_player_score(msg, payload, sid) output = await get_player_score(msg, payload, sid)
file = get_cover(music['id'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']}{' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), Plain(output)]) BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"), Plain(output)])
@mai_regex.handle(re.compile(r"(?:id)?(\d+)\s?有什(么别|麼別)名", flags=re.I), desc='{maimai.help.maimai_regex.alias}') @mai_regex.handle(re.compile(r"(?:id)?(\d+)\s?有什(么别|麼別)名", flags=re.I), desc='{maimai.help.maimai_regex.alias}')
@ -133,10 +131,9 @@ async def _(msg: Bot.MessageSession):
result += "\n".join(alias) result += "\n".join(alias)
await msg.finish([Plain(result.strip())]) await msg.finish([Plain(result.strip())])
file = get_cover(music['id'])
await msg.finish( await msg.finish(
[Plain(f"{music['id']}\u200B. {music['title']} {' (DX)' if music['type'] == 'DX' else ''}\n"), [Plain(f"{music['id']}\u200B. {music['title']} {' (DX)' if music['type'] == 'DX' else ''}\n"),
BImage(f"{file}"), BImage(f"https://www.diving-fish.com/covers/{get_cover_len5_id(music['id'])}.png"),
Plain(msg.locale.t("maimai.message.song", Plain(msg.locale.t("maimai.message.song",
artist=music['basic_info']['artist'], genre=music['basic_info']['genre'], artist=music['basic_info']['artist'], genre=music['basic_info']['genre'],
bpm=music['basic_info']['bpm'], version=music['basic_info']['from'], bpm=music['basic_info']['bpm'], version=music['basic_info']['from'],
@ -228,8 +225,8 @@ async def _(msg: Bot.MessageSession):
if level in level_list: if level in level_list:
level_num = int(level.split('+')[0]) level_num = int(level.split('+')[0])
if level_num < 8: # if level_num < 8:
await msg.finish(msg.locale.t("maimai.message.process.less_than_8")) # await msg.finish(msg.locale.t("maimai.message.process.less_than_8"))
else: else:
await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid")) await msg.finish(msg.locale.t("maimai.message.process.error.goal_invalid"))