Archived
1
0
Fork 0

Add filter and perf timer

This commit is contained in:
Dianliang233 2023-06-16 16:10:54 +08:00
parent 6e8dc00686
commit 2f1af74236
3 changed files with 18 additions and 7 deletions

View file

@ -59,9 +59,9 @@ async def _(msg: Bot.MessageSession):
await msg.finish(msg.locale.t("calc.message.calc.invalid", expr={res[7:]}))
func = module('func',
developers=['DoroWolf'],
recommend_modules=['calc'], required_superuser=True)
func = module('func',
developers=['DoroWolf'],
recommend_modules=['calc'], required_superuser=True)
@func.handle('<math_expression> {{calc.help.func}}')

View file

@ -1,8 +1,12 @@
from core.builtins import Bot
from core.component import module
import time
from langconv.converter import LanguageConverter
from langconv.language.zh import zh_cn, zh_hk, zh_tw
from core.builtins import Bot
from core.component import module
from core.dirty_check import check_bool
from core.exceptions import NoReportException
l = module('langconv', developers=['Dianliang233'], alias={'lc': 'langconv'}, desc='{langconv.help}')
lc_zh_cn = LanguageConverter.from_language(zh_cn)
@ -16,4 +20,10 @@ async def _(msg: Bot.MessageSession, language: str, content: str):
if language not in ('zh-cn', 'zh-hk', 'zh-tw'):
await msg.finish(msg.locale.t('langconv.message.unsupported_language'))
lc = {'zh-cn': lc_zh_cn, 'zh-hk': lc_zh_hk, 'zh-tw': lc_zh_tw}[language]
await msg.finish(lc.convert(content))
start = time.perf_counter_ns()
res = lc.convert(content)
stop = time.perf_counter_ns()
delta = (stop - start) / 1000000
if await check_bool(res):
raise NoReportException('https://wdf.ink/6OUp')
await msg.finish(res + '\n' + msg.locale.t('langconv.message.running_time', time=delta))

View file

@ -1,4 +1,5 @@
{
"langconv.help": "简繁转换。支持的语言zh_cn、zh_tw、zh_hk",
"langconv.message.unsupported_language": "不支持此语言。支持的语言zh_cn、zh_tw、zh_hk"
"langconv.message.unsupported_language": "不支持此语言。支持的语言zh_cn、zh_tw、zh_hk",
"langconv.message.running_time": "计算花费时间:${time} ms。"
}