From 52bf297c5f0d5bea1e0e117a904bb5058abdd13c Mon Sep 17 00:00:00 2001 From: zchk0 Date: Sun, 10 Nov 2024 21:09:39 +0000 Subject: [PATCH 1/5] add coinmarketcap plugin --- bot/plugin_manager.py | 2 ++ bot/plugins/coinmarketcap.py | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 bot/plugins/coinmarketcap.py diff --git a/bot/plugin_manager.py b/bot/plugin_manager.py index 6cd62e80..91a76309 100644 --- a/bot/plugin_manager.py +++ b/bot/plugin_manager.py @@ -7,6 +7,7 @@ from plugins.ddg_image_search import DDGImageSearchPlugin from plugins.ddg_translate import DDGTranslatePlugin from plugins.spotify import SpotifyPlugin +from plugins.coinmarketcap import CoinMarketCap from plugins.crypto import CryptoPlugin from plugins.weather import WeatherPlugin from plugins.ddg_web_search import DDGWebSearchPlugin @@ -29,6 +30,7 @@ def __init__(self, config): 'wolfram': WolframAlphaPlugin, 'weather': WeatherPlugin, 'crypto': CryptoPlugin, + 'coinmarketcap': CoinMarketCap, 'ddg_web_search': DDGWebSearchPlugin, 'ddg_translate': DDGTranslatePlugin, 'ddg_image_search': DDGImageSearchPlugin, diff --git a/bot/plugins/coinmarketcap.py b/bot/plugins/coinmarketcap.py new file mode 100644 index 00000000..b7e26866 --- /dev/null +++ b/bot/plugins/coinmarketcap.py @@ -0,0 +1,54 @@ +import os +from typing import Dict + +import requests + +from .plugin import Plugin + + +# Author: https://github.com/zchk0 +class CoinMarketCap(Plugin): + """ + A plugin to fetch the current rate of various cryptocurrencies + """ + def get_source_name(self) -> str: + return "CoinMarketCap by zchk0" + + def get_spec(self) -> [Dict]: + return [{ + "name": "get_crypto_rate", + "description": "Get the current rate of various cryptocurrencies from coinmarketcap", + "parameters": { + "type": "object", + "properties": { + "asset": {"type": "string", "description": "Asset of the crypto"} + }, + "required": ["asset"], + }, + }] + + def get_crypto_price(self, asset): + headers = { + 'X-CMC_PRO_API_KEY': os.environ.get('COINMARKETCAP_KEY', '') + } + params = { + 'symbol': asset, + 'convert': 'USD' + } + try: + response = requests.get("https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest", headers=headers, params=params) + response.raise_for_status() + data = response.json().get('data', {}) + if asset in data: + price = data[asset]['quote']['USD']['price'] + return price + else: + return "Not found" + except requests.exceptions.RequestException as e: + print(f"An error occurred: {e}") + return None + + async def execute(self, function_name, helper, **kwargs) -> dict: + asset = kwargs.get('asset', '') + rate = self.get_crypto_price(asset) + return {"asset": asset, "rate": rate} From a6572ecb1bcec94e20ef88604ca076d45216d897 Mon Sep 17 00:00:00 2001 From: zchk0 Date: Sun, 10 Nov 2024 21:15:09 +0000 Subject: [PATCH 2/5] add coinmarketcap plugin 2 --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index d3d368d0..50790c07 100644 --- a/.env.example +++ b/.env.example @@ -54,4 +54,5 @@ ALLOWED_TELEGRAM_USER_IDS=USER_ID_1,USER_ID_2 # TTS_PRICES=0.015,0.030 # BOT_LANGUAGE=en # ENABLE_VISION_FOLLOW_UP_QUESTIONS="true" -# VISION_MODEL="gpt-4-vision-preview" \ No newline at end of file +# VISION_MODEL="gpt-4-vision-preview" +# COINMARKETCAP_KEY="YOUR-API-KEY" \ No newline at end of file From 8d04997a381a0e2a03f04c96612b6bf85a96ab36 Mon Sep 17 00:00:00 2001 From: zchk0 Date: Mon, 11 Nov 2024 16:46:48 +0000 Subject: [PATCH 3/5] bump version --- requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 520d28da..f0b5bb65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ python-dotenv~=1.0.0 pydub~=0.25.1 -tiktoken==0.7.0 -openai==1.29.0 -python-telegram-bot==21.1.1 +tiktoken==0.8.0 +openai==1.54.3 +python-telegram-bot==21.7 requests~=2.31.0 tenacity==8.3.0 wolframalpha~=5.0.0 From 257d5175fe1accac803408cfc3f800a72f5c98a6 Mon Sep 17 00:00:00 2001 From: Alexander <58878112+zchk0@users.noreply.github.com> Date: Tue, 12 Nov 2024 01:26:04 +0700 Subject: [PATCH 4/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 61b7a41a..bc091793 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Check out the [official API reference](https://platform.openai.com/docs/api-refe | `whois` | Query the whois domain database - by [@jnaskali](https://github.com/jnaskali) | - | `whois` | | `webshot` | Screenshot a website from a given url or domain name - by [@noriellecruz](https://github.com/noriellecruz) | - | | | `auto_tts` | Text to speech using OpenAI APIs - by [@Jipok](https://github.com/Jipok) | - | | +| `coinmarketcap` | The largest selection of current cryptocurrency rates - by [@zchk0](https://github.com/zchk0) | `COINMARKETCAP_KEY` | | #### Environment variables | Variable | Description | Default value | @@ -164,6 +165,7 @@ Check out the [official API reference](https://platform.openai.com/docs/api-refe | `WORLDTIME_DEFAULT_TIMEZONE` | Default timezone to use, i.e. `Europe/Rome` (required only for the `worldtimeapi` plugin, you can get TZ Identifiers from [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)) | - | | `DUCKDUCKGO_SAFESEARCH` | DuckDuckGo safe search (`on`, `off` or `moderate`) (optional, applies to `ddg_web_search` and `ddg_image_search`) | `moderate` | | `DEEPL_API_KEY` | DeepL API key (required for the `deepl` plugin, you can get one [here](https://www.deepl.com/pro-api?cta=header-pro-api)) | - | +| `COINMARKETCAP_KEY` | CoinMarketCap API key (required for the `coinmarketcap` plugin, you can get one [here](https://coinmarketcap.com/api/documentation/v1/)) | - | ### Installing Clone the repository and navigate to the project directory: From 18cad1f250e5963c85c97ab45cd7f5965a4873b0 Mon Sep 17 00:00:00 2001 From: Alexander <58878112+zchk0@users.noreply.github.com> Date: Sat, 7 Dec 2024 23:50:16 +0700 Subject: [PATCH 5/5] add coinmarketcap plugin 3 --- bot/plugins/coinmarketcap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/plugins/coinmarketcap.py b/bot/plugins/coinmarketcap.py index b7e26866..5ae742df 100644 --- a/bot/plugins/coinmarketcap.py +++ b/bot/plugins/coinmarketcap.py @@ -21,7 +21,7 @@ def get_spec(self) -> [Dict]: "parameters": { "type": "object", "properties": { - "asset": {"type": "string", "description": "Asset of the crypto"} + "asset": {"type": "string", "description": "Ticker of the cryptocurrency in uppercase (e.g., BTC, ETH, XRP)"} }, "required": ["asset"], },