Archived
1
0
Fork 0

standardized naming

This commit is contained in:
多羅狼 2023-11-10 21:49:49 +08:00 committed by GitHub
parent 7da5f26c1d
commit 4ed9508172
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 53 additions and 61 deletions

View file

Before

Width:  |  Height:  |  Size: 7 KiB

After

Width:  |  Height:  |  Size: 7 KiB

View file

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View file

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 675 B

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 196 B

After

Width:  |  Height:  |  Size: 196 B

View file

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 752 B

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

View file

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View file

Before

Width:  |  Height:  |  Size: 490 KiB

After

Width:  |  Height:  |  Size: 490 KiB

View file

@ -51,12 +51,12 @@ allow_request_private_ip = false
allow_bot_auto_approve_group_invite = false allow_bot_auto_approve_group_invite = false
slower_schedule = false slower_schedule = false
enable_dirty_check = true enable_dirty_check = true
enable_rickroll = true
enable_urlmanager = true enable_urlmanager = true
enable_tos = false enable_tos = false
tos_waring_counts = 5 tos_waring_counts = 5
enable_analytics = true enable_analytics = true
enable_eval = true enable_eval = true
enable_rickroll = true
enable_get_petal = true enable_get_petal = true
gained_petal_limit = 10 gained_petal_limit = 10
lost_petal_limit = 5 lost_petal_limit = 5

View file

@ -20,9 +20,6 @@ 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')
@ -60,7 +57,6 @@ async def load_or_refresh_cache():
return None return None
async def count_petal(tokens): async def count_petal(tokens):
Logger.info(f'{tokens} tokens have been consumed while calling AI.') Logger.info(f'{tokens} tokens have been consumed while calling AI.')
petal_exchange_rate = await load_or_refresh_cache() petal_exchange_rate = await load_or_refresh_cache()

View file

@ -16,10 +16,10 @@ class WithErrCode(Exception):
pass pass
@arc.command('<sb616>') @arc.command('b30')
async def _(msg: Bot.MessageSession): async def _(msg: Bot.MessageSession):
await msg.send_message([Plain(msg.locale.t("arcaea.message.sb616")), await msg.send_message([Plain(msg.locale.t("arcaea.message.sb616")),
Image(os.path.abspath('./assets/noc.jpg'))]) Image(os.path.abspath('./assets/arcaea/noc.jpg'))])
@arc.command('download {{arcaea.help.download}}') @arc.command('download {{arcaea.help.download}}')

View file

@ -74,7 +74,7 @@ async def _(msg: Bot.MessageSession):
if await check_bool(res): if await check_bool(res):
if petal != 0: if petal != 0:
await msg.sendMessage(msg.locale.t('petal.message.cost', count=petal)) await msg.send_message(msg.locale.t('petal.message.cost', count=petal))
rickroll(msg) rickroll(msg)
if petal != 0: if petal != 0:
chain.append(Plain(msg.locale.t('petal.message.cost', count=petal))) chain.append(Plain(msg.locale.t('petal.message.cost', count=petal)))

View file

@ -18,12 +18,10 @@ from core.utils.cache import random_cache_path
from core.utils.http import get_url, download_to_cache from core.utils.http import get_url, download_to_cache
from core.utils.text import remove_prefix from core.utils.text import remove_prefix
csr_link = 'https://www.chemspider.com' # ChemSpider 的链接 csr_link = 'https://www.chemspider.com'
special_id = ["22398", "140526", "4509317", "4509318", "4510681", "4510778", "4512975", "4514248", "4514266", "4514293",
"4514330", "4514408", "4514534", "4514586", "4514603", "4515054", "4573995", "4574465", "4575369", special_id_path = os.path.abspath(f'./assets/chemical_code/special_id') # 去掉文件扩展名并存储在special_id列表中
"4575370", special_id = [os.path.splitext(csid)[0] for csid in os.listdir(special_id_path)] # 可能会导致识别问题的物质如部分单质ID这些 ID 的图片将会在本地调用
"4575371", "4885606", "4885717", "4886482", "4886484", "20473555", "21865276",
"21865280"] # 可能会导致识别问题的物质如部分单质ID这些 ID 的图片将会在本地调用
element_lists = ['He', 'Li', 'Be', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'Cl', element_lists = ['He', 'Li', 'Be', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'Cl',
'Ar', 'Ca', 'Sc', 'Ti', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Ar', 'Ca', 'Sc', 'Ti', 'Cr', 'Mn', 'Fe', 'Co', 'Ni',
@ -98,9 +96,9 @@ ccode = module('chemical_code', alias={'cc': 'chemical_code',
play_state = {} # 创建一个空字典用于存放游戏状态 play_state = {} # 创建一个空字典用于存放游戏状态
@ccode.command('{{chemical_code.help}}') # 直接使用 ccode 命令将触发此装饰器 @ccode.command('{{chemical_code.help}}')
async def chemical_code_by_random(msg: Bot.MessageSession): async def chemical_code_by_random(msg: Bot.MessageSession):
await chemical_code(msg) # 将消息会话传入 chemical_code 函数 await chemical_code(msg)
@ccode.command('captcha {{chemical_code.help.captcha}}') @ccode.command('captcha {{chemical_code.help.captcha}}')
@ -111,12 +109,12 @@ async def _(msg: Bot.MessageSession):
@ccode.command('stop {{game.help.stop}}') @ccode.command('stop {{game.help.stop}}')
async def s(msg: Bot.MessageSession): async def s(msg: Bot.MessageSession):
state = play_state.get(msg.target.target_id, {}) # 尝试获取 play_state 中是否有此对象的游戏状态 state = play_state.get(msg.target.target_id, {}) # 尝试获取 play_state 中是否有此对象的游戏状态
if state: # 若有 if state:
if state['active']: # 检查是否为活跃状态 if state['active']:
play_state[msg.target.target_id]['active'] = False # 标记为非活跃状态 play_state[msg.target.target_id]['active'] = False
await msg.finish( await msg.finish(
msg.locale.t('chemical_code.stop.message', answer=play_state[msg.target.target_id]["answer"]), msg.locale.t('chemical_code.stop.message', answer=play_state[msg.target.target_id]["answer"]),
quote=False) # 发送存储于 play_state 中的答案 quote=False)
else: else:
await msg.finish(msg.locale.t('game.message.stop.none')) await msg.finish(msg.locale.t('game.message.stop.none'))
else: else:
@ -125,8 +123,8 @@ async def s(msg: Bot.MessageSession):
@ccode.command('<csid> {{chemical_code.help.csid}}') @ccode.command('<csid> {{chemical_code.help.csid}}')
async def chemical_code_by_id(msg: Bot.MessageSession): async def chemical_code_by_id(msg: Bot.MessageSession):
id = msg.parsed_msg['<csid>'] # 从已解析的消息中获取 ChemSpider ID id = msg.parsed_msg['<csid>']
if id.isdigit(): # 如果 ID 为纯数字 if id.isdigit():
if int(id) == 0: if int(id) == 0:
await chemical_code(msg) await chemical_code(msg)
else: else:
@ -136,46 +134,44 @@ async def chemical_code_by_id(msg: Bot.MessageSession):
async def chemical_code(msg: Bot.MessageSession, id=None, random_mode=True, captcha_mode=False): async def chemical_code(msg: Bot.MessageSession, id=None, random_mode=True, captcha_mode=False):
# 要求传入消息会话和 ChemSpider IDID 留空将会使用缺省值 None
# 检查对象(群组或私聊)是否在 play_state 中有记录及是否为活跃状态
if msg.target.target_id in play_state and play_state[msg.target.target_id]['active']: if msg.target.target_id in play_state and play_state[msg.target.target_id]['active']:
await msg.finish(msg.locale.t('game.message.running')) await msg.finish(msg.locale.t('game.message.running'))
play_state.update({msg.target.target_id: {'active': True}}) # 若无,则创建一个新的记录并标记为活跃状态 play_state.update({msg.target.target_id: {'active': True}})
try: try:
csr = await search_csr(id) # 尝试获取 ChemSpider ID 对应的化学式列表 csr = await search_csr(id)
except Exception as e: # 意外情况 except Exception as e:
traceback.print_exc() # 打印错误信息 traceback.print_exc()
play_state[msg.target.target_id]['active'] = False # 将对象标记为非活跃状态 play_state[msg.target.target_id]['active'] = False
return await msg.finish(msg.locale.t('chemical_code.message.error')) return await msg.finish(msg.locale.t('chemical_code.message.error'))
# print(csr) # print(csr)
play_state[msg.target.target_id]['answer'] = csr['name'] # 将正确答案标记于 play_state 中存储的对象中 play_state[msg.target.target_id]['answer'] = csr['name'] # 将正确答案标记于 play_state 中存储的对象中
Logger.info(f'Answer: {csr["name"]}') # 在日志中输出正确答案 Logger.info(f'Answer: {csr["name"]}')
Logger.info(f'Image: {csr["image"]}') # 在日志中输出图片链接 Logger.info(f'Image: {csr["image"]}')
download = False download = False
if csr["id"] in special_id: # 如果正确答案在 special_id 中 if csr["id"] in special_id: # 如果正确答案在 special_id 中
file_path = os.path.abspath(f'./assets/chemicalcode/special_id/{csr["id"]}.png') file_path = os.path.abspath(f'./assets/chemicalcode/special_id/{csr["id"]}.png')
Logger.info(f'File path: {file_path}') # 在日志中输出文件路径 Logger.info(f'File path: {file_path}')
exists_file = os.path.exists(file_path) # 尝试获取图片文件是否存在 exists_file = os.path.exists(file_path)
if exists_file: if exists_file:
download = file_path download = file_path
if not download: if not download:
download = await download_to_cache(csr['image']) # 从结果中获取链接并下载图片 download = await download_to_cache(csr['image'])
with PILImage.open(download) as im: # 打开下载的图片 with PILImage.open(download) as im:
im = im.convert("RGBA") # 转换为 RGBA 格式 im = im.convert("RGBA")
image = PILImage.new("RGBA", im.size, 'white') # 创建新图片 image = PILImage.new("RGBA", im.size, 'white')
image.alpha_composite(im, (0, 0)) # 将图片合并到新图片中 image.alpha_composite(im, (0, 0))
newpath = random_cache_path() + '.png' # 创建新文件名 newpath = random_cache_path() + '.png'
image.save(newpath) # 保存新图片 image.save(newpath)
set_timeout = csr['length'] // 30 set_timeout = csr['length'] // 30
if set_timeout < 2: if set_timeout < 2:
set_timeout = 2 set_timeout = 2
async def ans(msg: Bot.MessageSession, answer, random_mode): # 定义回答函数的功能 async def ans(msg: Bot.MessageSession, answer, random_mode):
wait = await msg.wait_anyone() # 等待对象内的任意人回答 wait = await msg.wait_anyone()
if play_state[msg.target.target_id]['active']: # 检查对象是否为活跃状态 if play_state[msg.target.target_id]['active']:
if (wait_text := wait.as_display(text_only=True)) != answer: # 如果回答不正确 if (wait_text := wait.as_display(text_only=True)) != answer:
if re.match(r'^[A-Za-z0-9]+$', wait_text): if re.match(r'^[A-Za-z0-9]+$', wait_text):
try: try:
parse_ = parse_elements(wait_text) # 解析消息中的化学元素 parse_ = parse_elements(wait_text) # 解析消息中的化学元素
@ -220,8 +216,8 @@ async def chemical_code(msg: Bot.MessageSession, id=None, random_mode=True, capt
except ValueError: except ValueError:
traceback.print_exc() traceback.print_exc()
Logger.info(f'{wait_text} != {answer}') # 输出日志 Logger.info(f'{wait_text} != {answer}')
return await ans(wait, answer, random_mode) # 进行下一轮检查 return await ans(wait, answer, random_mode)
else: else:
send_ = wait.locale.t('chemical_code.message.correct') send_ = wait.locale.t('chemical_code.message.correct')
if random_mode: if random_mode:
@ -230,27 +226,27 @@ async def chemical_code(msg: Bot.MessageSession, id=None, random_mode=True, capt
await wait.send_message(send_) await wait.send_message(send_)
play_state[msg.target.target_id]['active'] = False # 将对象标记为非活跃状态 play_state[msg.target.target_id]['active'] = False # 将对象标记为非活跃状态
async def timer(start): # 计时器函数 async def timer(start):
if play_state[msg.target.target_id]['active']: # 检查对象是否为活跃状态 if play_state[msg.target.target_id]['active']:
if datetime.now().timestamp() - start > 60 * set_timeout: # 如果超过2分钟 if datetime.now().timestamp() - start > 60 * set_timeout:
await msg.send_message( await msg.send_message(
msg.locale.t('chemical_code.message.timeup', answer=play_state[msg.target.target_id]["answer"])) msg.locale.t('chemical_code.message.timeup', answer=play_state[msg.target.target_id]["answer"]))
play_state[msg.target.target_id]['active'] = False play_state[msg.target.target_id]['active'] = False
else: # 如果未超时 else:
await asyncio.sleep(1) # 等待1秒 await asyncio.sleep(1) # 防冲突
await timer(start) # 重新调用计时器函数 await timer(start)
if not captcha_mode: if not captcha_mode:
await msg.send_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])), Image(newpath), await msg.send_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])), Image(newpath),
Plain(msg.locale.t('chemical_code.message', times=set_timeout))]) Plain(msg.locale.t('chemical_code.message', times=set_timeout))])
time_start = datetime.now().timestamp() # 记录开始时间 time_start = datetime.now().timestamp()
await asyncio.gather(ans(msg, csr['name'], random_mode), timer(time_start)) # 同时启动回答函数和计时器函数 await asyncio.gather(ans(msg, csr['name'], random_mode), timer(time_start))
else: else:
result = await msg.wait_next_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])), result = await msg.wait_next_message([Plain(msg.locale.t('chemical_code.message.showid', id=csr["id"])),
Image(newpath), Plain(msg.locale.t('chemical_code.message.captcha', Image(newpath), Plain(msg.locale.t('chemical_code.message.captcha',
times=set_timeout))]) times=set_timeout))])
if play_state[msg.target.target_id]['active']: # 检查对象是否为活跃状态 if play_state[msg.target.target_id]['active']:
if result.as_display(text_only=True) == csr['name']: if result.as_display(text_only=True) == csr['name']:
send_ = msg.locale.t('chemical_code.message.correct') send_ = msg.locale.t('chemical_code.message.correct')
if (g_msg := await gained_petal(wait, 1)): if (g_msg := await gained_petal(wait, 1)):

View file

@ -432,7 +432,7 @@ async def _(msg: Bot.MessageSession):
raise NoReportException(e) raise NoReportException(e)
if not e: if not e:
e = msg.locale.t("core.message.raise") e = msg.locale.t("core.message.raise")
raise Exception(e) raise TestException(e)
if Config('enable_eval'): if Config('enable_eval'):

View file

@ -140,7 +140,7 @@ async def _(msg: Bot.MessageSession):
async def config_gu(msg: Bot.MessageSession): async def config_gu(msg: Bot.MessageSession):
lang = msg.parsed_msg['<lang>'] lang = msg.parsed_msg['<lang>']
if lang in get_available_locales() and BotDBUtil.TargetInfo(msg.target.target_id).edit('locale', lang): if lang in get_available_locales() and BotDBUtil.TargetInfo(msg.target.target_id).edit('locale', lang):
await msg.sendMessage(Locale(lang).t('success')) await msg.send_message(Locale(lang).t('success'))
if lang not in completed_locales: if lang not in completed_locales:
await msg.finish(f"{Locale(lang).t('language')} {Locale(lang).t('core.message.locale.contribution')}") await msg.finish(f"{Locale(lang).t('language')} {Locale(lang).t('core.message.locale.contribution')}")
else: else:

View file

@ -81,7 +81,7 @@ async def _(msg: Bot.MessageSession):
await wait_msg.delete() await wait_msg.delete()
if await check_bool(output): if await check_bool(output):
if petal != 0: if petal != 0:
await msg.sendMessage(msg.locale.t('petal.message.cost', count=petal)) await msg.send_message(msg.locale.t('petal.message.cost', count=petal))
rickroll(msg) rickroll(msg)
if msg.target.target_from != 'TEST|Console' and not is_superuser: if msg.target.target_from != 'TEST|Console' and not is_superuser:
qc.reset() qc.reset()

View file

@ -13,9 +13,9 @@ def tpg(msg, favicon, wikiname, username, gender, registertime, contributionwiki
font = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 40) font = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 40)
font1 = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 70) font1 = ImageFont.truetype(abspath('./assets/SourceHanSansCN-Normal.ttf'), 70)
if bantype is None: if bantype is None:
img = Image.open(abspath('./assets/base.png')) img = Image.open(abspath('./assets/user/base.png'))
elif bantype == 'Y' or bantype == 'YN': elif bantype == 'Y' or bantype == 'YN':
img = Image.open(abspath('./assets/ban.png')) img = Image.open(abspath('./assets/user/ban.png'))
if favicon: if favicon:
img2 = Image.open(favicon) img2 = Image.open(favicon)
else: else:
@ -89,7 +89,7 @@ def tpg(msg, favicon, wikiname, username, gender, registertime, contributionwiki
img3.alpha_composite(img7, (655, 960)) img3.alpha_composite(img7, (655, 960))
if bantype == 'Y' or bantype == 'YN': if bantype == 'Y' or bantype == 'YN':
img8 = Image.open(abspath('./assets/Blocked.png')) img8 = Image.open(abspath('./assets/user/Blocked.png'))
w, h = img8.size w, h = img8.size
w = int(w) w = int(w)
h = int(h) h = int(h)