mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 20:38:51 +00:00
rate 支持简易计算 (#75)
This commit is contained in:
parent
ee8e52fb39
commit
c1791ad986
@ -92,10 +92,10 @@
|
||||
},
|
||||
{
|
||||
"name": "rate",
|
||||
"version": "1.1",
|
||||
"version": "1.2",
|
||||
"section": "daily",
|
||||
"maintainer": "fruitymelon",
|
||||
"size": "1.7 kb",
|
||||
"size": "1.8 kb",
|
||||
"supported": true,
|
||||
"des-short": "汇率转换。",
|
||||
"des": "这个人很懒,什么都没有留下。"
|
||||
|
20
rate.py
20
rate.py
@ -32,25 +32,29 @@ init()
|
||||
|
||||
|
||||
@listener(is_plugin=True, outgoing=True, command="rate",
|
||||
description="Currency exchange rate plugin.",
|
||||
parameters="<FROM> <TO>")
|
||||
description="货币汇率插件",
|
||||
parameters="<FROM> <TO> <NB>")
|
||||
async def rate(context):
|
||||
while not inited:
|
||||
await asyncio.sleep(1)
|
||||
if not context.parameter:
|
||||
await context.edit(
|
||||
f"This is the currency exchange rate plugin.\n\nUsage: `-rate <FROM> <TO>`\n\nAvailable currencies: {', '.join(currencies)}")
|
||||
f"这是货币汇率插件\n\n使用方法: `-rate <FROM> <TO> <NB>`\n\n支持货币: \n{', '.join(currencies)}")
|
||||
return
|
||||
if len(context.parameter) != 2:
|
||||
await context.edit(f"Usage: `-rate <FROM> <TO>`\n\n`{', '.join(currencies)}`")
|
||||
if len(context.parameter) != 3:
|
||||
await context.edit(f"使用方法: `-rate <FROM> <TO> <NB>`\n\n支持货币: \n{', '.join(currencies)}")
|
||||
return
|
||||
FROM = context.parameter[0].upper().strip()
|
||||
TO = context.parameter[1].upper().strip()
|
||||
try:
|
||||
NB = float(context.parameter[2].strip())
|
||||
except:
|
||||
NB = 1.0
|
||||
if currencies.count(FROM) == 0:
|
||||
await context.edit(
|
||||
f"Currency type {FROM} is not supported. Choose one among `{', '.join(currencies)}` instead.")
|
||||
f"{FROM}不是支持的货币. \n\n支持货币: \n{', '.join(currencies)}")
|
||||
return
|
||||
if currencies.count(TO) == 0:
|
||||
await context.edit(f"Currency type {TO} is not supported. Choose one among `{', '.join(currencies)}` instead.")
|
||||
await context.edit(f"{TO}不是支持的货币. \n\n支持货币: \n{', '.join(currencies)}")
|
||||
return
|
||||
await context.edit(f'{FROM} : {TO} = 1 : {int(10000*data["rates"][TO]/data["rates"][FROM])/10000}')
|
||||
await context.edit(f'{FROM} : {TO} = {NB} : {round(data["rates"][TO]/data["rates"][FROM]*NB,2)}')
|
||||
|
Loading…
Reference in New Issue
Block a user