mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-25 18:35:26 +00:00
💩 rate 顺序错误
This commit is contained in:
parent
fca2ec442c
commit
a0c6ae52bc
@ -92,7 +92,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "rate",
|
"name": "rate",
|
||||||
"version": "1.0",
|
"version": "1.1",
|
||||||
"section": "daily",
|
"section": "daily",
|
||||||
"maintainer": "fruitymelon",
|
"maintainer": "fruitymelon",
|
||||||
"size": "1.7 kb",
|
"size": "1.7 kb",
|
||||||
|
14
rate.py
14
rate.py
@ -3,8 +3,6 @@
|
|||||||
import asyncio, json
|
import asyncio, json
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
from pagermaid import bot, log
|
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
|
|
||||||
API = "https://api.exchangeratesapi.io/latest"
|
API = "https://api.exchangeratesapi.io/latest"
|
||||||
@ -13,6 +11,7 @@ data = {}
|
|||||||
|
|
||||||
inited = False
|
inited = False
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
with urllib.request.urlopen(API) as response:
|
with urllib.request.urlopen(API) as response:
|
||||||
result = response.read()
|
result = response.read()
|
||||||
@ -28,8 +27,10 @@ def init():
|
|||||||
global inited
|
global inited
|
||||||
inited = True
|
inited = True
|
||||||
|
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=True, outgoing=True, command="rate",
|
@listener(is_plugin=True, outgoing=True, command="rate",
|
||||||
description="Currency exchange rate plugin.",
|
description="Currency exchange rate plugin.",
|
||||||
parameters="<FROM> <TO>")
|
parameters="<FROM> <TO>")
|
||||||
@ -37,7 +38,8 @@ async def rate(context):
|
|||||||
while not inited:
|
while not inited:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
if not context.parameter:
|
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)}")
|
await context.edit(
|
||||||
|
f"This is the currency exchange rate plugin.\n\nUsage: `-rate <FROM> <TO>`\n\nAvailable currencies: {', '.join(currencies)}")
|
||||||
return
|
return
|
||||||
if len(context.parameter) != 2:
|
if len(context.parameter) != 2:
|
||||||
await context.edit(f"Usage: `-rate <FROM> <TO>`\n\n`{', '.join(currencies)}`")
|
await context.edit(f"Usage: `-rate <FROM> <TO>`\n\n`{', '.join(currencies)}`")
|
||||||
@ -45,10 +47,10 @@ async def rate(context):
|
|||||||
FROM = context.parameter[0].upper().strip()
|
FROM = context.parameter[0].upper().strip()
|
||||||
TO = context.parameter[1].upper().strip()
|
TO = context.parameter[1].upper().strip()
|
||||||
if currencies.count(FROM) == 0:
|
if currencies.count(FROM) == 0:
|
||||||
await context.edit(f"Currency type {FROM} is not supported. Choose one among `{', '.join(currencies)}` instead.")
|
await context.edit(
|
||||||
|
f"Currency type {FROM} is not supported. Choose one among `{', '.join(currencies)}` instead.")
|
||||||
return
|
return
|
||||||
if currencies.count(TO) == 0:
|
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"Currency type {TO} is not supported. Choose one among `{', '.join(currencies)}` instead.")
|
||||||
return
|
return
|
||||||
await context.edit(f'{FROM} : {TO} = 1 : {int(10000*data["rates"][FROM]/data["rates"][TO])/10000}')
|
await context.edit(f'{FROM} : {TO} = 1 : {int(10000*data["rates"][TO]/data["rates"][FROM])/10000}')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user