From eeb4027714de570c70980766f186cd36e6aa22ae Mon Sep 17 00:00:00 2001 From: Pentacene Date: Tue, 11 May 2021 12:56:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=20bc=20v1.2=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=B2=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bc.py | 22 ++++++++++++---------- list.json | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bc.py b/bc.py index 5c25527..f3f08db 100644 --- a/bc.py +++ b/bc.py @@ -31,7 +31,7 @@ BINANCE_API_KEY = '8PDfQ2lSIyHPWdNAHNIaIoNy3MiiMuvgwYADbmtsKo867B0xnIhIGjPULsOtv BINANCE_API_SECRET = 'tbUiyZ94l0zpYOlKs3eO1dvLNMOSbOb2T1T0eT0I1eogH9Fh8Htvli05eZ1iDvra' -def init(): +def init() -> None: """ INIT """ with urllib.request.urlopen(API) as response: result = response.read() @@ -52,7 +52,7 @@ def init(): command="bc", description="coins", parameters=" ") -async def coin(context): +async def coin(context) -> None: """ coin change """ if not imported: await context.edit("支持库 `python-binance` `xmltodict` 未安装...\n正在尝试自动安装...") @@ -84,15 +84,18 @@ async def coin(context): price = 0.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: if CURRENCIES.count(_from) != 0: + # from virtual currency to real currency number = number * DATA["USD"] / DATA[_from] _from = 'USDT' front_text = f'{action[0]} {action[1]} = \n' if CURRENCIES.count(_to) != 0: + # from real currency to virtual currency _to_USD_rate = DATA[_to] / DATA["USD"] _to = 'USDT' @@ -101,18 +104,17 @@ async def coin(context): price = _a['price'] if _to == '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: - rear_text = f'\n= {round(number * float(price) * _to_USD_rate, 2)} {action[2]}' - _r = 2 + rear_text = f'\n= {number * float(price) * _to_USD_rate:.2f} {action[2].upper().strip()}' + if float(price) < 1: + text = f'{number} {_from} = {number * float(price):.8f} {_to}' else: - _r = 8 - text = f'{number} {_from} = {round(number * float(price), _r)} {_to}' + text = f'{number} {_from} = {number * float(price):.2f} {_to}' break elif _a['symbol'] == str(f'{_to}{_from}'): price = 1 / float(_a['price']) - _r = 8 - text = f'{number} {_from} = {round(number * float(price), _r)} {_to}' + text = f'{number} {_from} = {number * float(price):.8f} {_to}' break else: price = None diff --git a/list.json b/list.json index 45976f6..5c7a116 100644 --- a/list.json +++ b/list.json @@ -442,10 +442,10 @@ }, { "name": "bc", - "version": "1.1", + "version": "1.2", "section": "chat", "maintainer": "Pentacene", - "size": "4.4 kb", + "size": "8.0 kb", "supported": true, "des-short": "查询含虚拟货币在内的货币价格", "des": "命令:bc 数量 货币1 货币2" From 720a553a5060d81c487a090b7955717c02cb8994 Mon Sep 17 00:00:00 2001 From: Pentacene Date: Tue, 11 May 2021 12:58:44 +0800 Subject: [PATCH 2/2] --- bc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bc.py b/bc.py index f3f08db..c979bb7 100644 --- a/bc.py +++ b/bc.py @@ -13,6 +13,7 @@ from time import strftime import json import urllib.request import time +from telethon.tl.custom.message import Message from pagermaid import log from pagermaid.listener import listener from pagermaid.utils import execute @@ -52,7 +53,7 @@ def init() -> None: command="bc", description="coins", parameters=" ") -async def coin(context) -> None: +async def coin(context: Message) -> None: """ coin change """ if not imported: await context.edit("支持库 `python-binance` `xmltodict` 未安装...\n正在尝试自动安装...")