Add filter and perf timer
This commit is contained in:
parent
6e8dc00686
commit
2f1af74236
3 changed files with 18 additions and 7 deletions
|
@ -59,9 +59,9 @@ async def _(msg: Bot.MessageSession):
|
||||||
await msg.finish(msg.locale.t("calc.message.calc.invalid", expr={res[7:]}))
|
await msg.finish(msg.locale.t("calc.message.calc.invalid", expr={res[7:]}))
|
||||||
|
|
||||||
|
|
||||||
func = module('func',
|
func = module('func',
|
||||||
developers=['DoroWolf'],
|
developers=['DoroWolf'],
|
||||||
recommend_modules=['calc'], required_superuser=True)
|
recommend_modules=['calc'], required_superuser=True)
|
||||||
|
|
||||||
|
|
||||||
@func.handle('<math_expression> {{calc.help.func}}')
|
@func.handle('<math_expression> {{calc.help.func}}')
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
from core.builtins import Bot
|
import time
|
||||||
from core.component import module
|
|
||||||
from langconv.converter import LanguageConverter
|
from langconv.converter import LanguageConverter
|
||||||
from langconv.language.zh import zh_cn, zh_hk, zh_tw
|
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}')
|
l = module('langconv', developers=['Dianliang233'], alias={'lc': 'langconv'}, desc='{langconv.help}')
|
||||||
|
|
||||||
lc_zh_cn = LanguageConverter.from_language(zh_cn)
|
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'):
|
if language not in ('zh-cn', 'zh-hk', 'zh-tw'):
|
||||||
await msg.finish(msg.locale.t('langconv.message.unsupported_language'))
|
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]
|
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))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
"langconv.help": "简繁转换。支持的语言:zh_cn、zh_tw、zh_hk",
|
"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。"
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue