Files
chatgpt-telegram-bot/bot/plugins/crypto.py
2023-06-17 23:39:12 +02:00

31 lines
863 B
Python

from typing import Dict
import requests
from bot.plugins.plugin import Plugin
# Author: https://github.com/stumpyfr
class CryptoPlugin(Plugin):
"""
A plugin to fetch the current rate of various cryptocurrencies
"""
def get_source_name(self) -> str:
return "CoinCap"
def get_spec(self) -> Dict:
return {
"name": "get_crypto_rate",
"description": "Get the current rate of various crypto currencies",
"parameters": {
"type": "object",
"properties": {
"asset": {"type": "string", "description": "Asset of the crypto"}
},
"required": ["asset"],
},
}
async def execute(self, **kwargs) -> Dict:
return requests.get(f"https://api.coincap.io/v2/rates/{kwargs['asset']}").json()