mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-22 07:08:18 +00:00
update bc v1.2 更新查询精度
This commit is contained in:
parent
85b0f456ba
commit
eeb4027714
22
bc.py
22
bc.py
@ -31,7 +31,7 @@ BINANCE_API_KEY = '8PDfQ2lSIyHPWdNAHNIaIoNy3MiiMuvgwYADbmtsKo867B0xnIhIGjPULsOtv
|
|||||||
BINANCE_API_SECRET = 'tbUiyZ94l0zpYOlKs3eO1dvLNMOSbOb2T1T0eT0I1eogH9Fh8Htvli05eZ1iDvra'
|
BINANCE_API_SECRET = 'tbUiyZ94l0zpYOlKs3eO1dvLNMOSbOb2T1T0eT0I1eogH9Fh8Htvli05eZ1iDvra'
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init() -> None:
|
||||||
""" INIT """
|
""" INIT """
|
||||||
with urllib.request.urlopen(API) as response:
|
with urllib.request.urlopen(API) as response:
|
||||||
result = response.read()
|
result = response.read()
|
||||||
@ -52,7 +52,7 @@ def init():
|
|||||||
command="bc",
|
command="bc",
|
||||||
description="coins",
|
description="coins",
|
||||||
parameters="<num> <coin1> <coin2>")
|
parameters="<num> <coin1> <coin2>")
|
||||||
async def coin(context):
|
async def coin(context) -> None:
|
||||||
""" coin change """
|
""" coin change """
|
||||||
if not imported:
|
if not imported:
|
||||||
await context.edit("支持库 `python-binance` `xmltodict` 未安装...\n正在尝试自动安装...")
|
await context.edit("支持库 `python-binance` `xmltodict` 未安装...\n正在尝试自动安装...")
|
||||||
@ -84,15 +84,18 @@ async def coin(context):
|
|||||||
price = 0.0
|
price = 0.0
|
||||||
|
|
||||||
if ((CURRENCIES.count(_from) != 0) and (CURRENCIES.count(_to) != 0)):
|
if ((CURRENCIES.count(_from) != 0) and (CURRENCIES.count(_to) != 0)):
|
||||||
text = f'{action[0]} {action[1].upper().strip()} = {round(float(action[0])*DATA[_to]/DATA[_from], 2)} {action[2].upper().strip()}'
|
# both are real currency
|
||||||
|
text = f'{action[0]} {action[1].upper().strip()} = {float(action[0])*DATA[_to]/DATA[_from]:.2f} {action[2].upper().strip()}'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if CURRENCIES.count(_from) != 0:
|
if CURRENCIES.count(_from) != 0:
|
||||||
|
# from virtual currency to real currency
|
||||||
number = number * DATA["USD"] / DATA[_from]
|
number = number * DATA["USD"] / DATA[_from]
|
||||||
_from = 'USDT'
|
_from = 'USDT'
|
||||||
front_text = f'{action[0]} {action[1]} = \n'
|
front_text = f'{action[0]} {action[1]} = \n'
|
||||||
|
|
||||||
if CURRENCIES.count(_to) != 0:
|
if CURRENCIES.count(_to) != 0:
|
||||||
|
# from real currency to virtual currency
|
||||||
_to_USD_rate = DATA[_to] / DATA["USD"]
|
_to_USD_rate = DATA[_to] / DATA["USD"]
|
||||||
_to = 'USDT'
|
_to = 'USDT'
|
||||||
|
|
||||||
@ -101,18 +104,17 @@ async def coin(context):
|
|||||||
price = _a['price']
|
price = _a['price']
|
||||||
if _to == 'USDT':
|
if _to == 'USDT':
|
||||||
if action[2].upper().strip() == 'USDT':
|
if action[2].upper().strip() == 'USDT':
|
||||||
rear_text = f'\n= {round(number * float(price) * DATA["CNY"]/DATA["USD"], 2)} CNY'
|
rear_text = f'\n= {number * float(price) * DATA["CNY"]/DATA["USD"]:.2f} CNY'
|
||||||
else:
|
else:
|
||||||
rear_text = f'\n= {round(number * float(price) * _to_USD_rate, 2)} {action[2]}'
|
rear_text = f'\n= {number * float(price) * _to_USD_rate:.2f} {action[2].upper().strip()}'
|
||||||
_r = 2
|
if float(price) < 1:
|
||||||
|
text = f'{number} {_from} = {number * float(price):.8f} {_to}'
|
||||||
else:
|
else:
|
||||||
_r = 8
|
text = f'{number} {_from} = {number * float(price):.2f} {_to}'
|
||||||
text = f'{number} {_from} = {round(number * float(price), _r)} {_to}'
|
|
||||||
break
|
break
|
||||||
elif _a['symbol'] == str(f'{_to}{_from}'):
|
elif _a['symbol'] == str(f'{_to}{_from}'):
|
||||||
price = 1 / float(_a['price'])
|
price = 1 / float(_a['price'])
|
||||||
_r = 8
|
text = f'{number} {_from} = {number * float(price):.8f} {_to}'
|
||||||
text = f'{number} {_from} = {round(number * float(price), _r)} {_to}'
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
price = None
|
price = None
|
||||||
|
@ -442,10 +442,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bc",
|
"name": "bc",
|
||||||
"version": "1.1",
|
"version": "1.2",
|
||||||
"section": "chat",
|
"section": "chat",
|
||||||
"maintainer": "Pentacene",
|
"maintainer": "Pentacene",
|
||||||
"size": "4.4 kb",
|
"size": "8.0 kb",
|
||||||
"supported": true,
|
"supported": true,
|
||||||
"des-short": "查询含虚拟货币在内的货币价格",
|
"des-short": "查询含虚拟货币在内的货币价格",
|
||||||
"des": "命令:bc 数量 货币1 货币2"
|
"des": "命令:bc 数量 货币1 货币2"
|
||||||
|
Loading…
Reference in New Issue
Block a user