diff --git a/README.md b/README.md index 7e5d190..012ff69 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/di | `SPOTIFY_REDIRECT_URI` | Spotify app Redirect URI (required only for the `spotify` plugin, you can find it on the [dashboard](https://developer.spotify.com/dashboard/)) | - | | `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)) | `-` | +| `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)) | - | #### Available plugins | Name | Description | Required environment variable(s) | @@ -126,7 +126,7 @@ Check out the [Budget Manual](https://github.com/n3d1117/chatgpt-telegram-bot/di | `worldtimeapi` | Get latest world time (powered by [WorldTimeAPI](https://worldtimeapi.org/)) | `WORLDTIME_DEFAULT_TIMEZONE` | | `dice` | Send a dice in the chat! | - | | `youtube_audio_extractor` | Extract audio from YouTube videos | - | -| `deepl` | Translate text to any language (powered by [DeepL](https://deepl.com)) - by [@LedyBacer](https://github.com/LedyBacer) | `DEEPL_API_KEY` | +| `deepl_translate` | Translate text to any language (powered by [DeepL](https://deepl.com)) - by [@LedyBacer](https://github.com/LedyBacer) | `DEEPL_API_KEY` | Check out the [official API reference](https://platform.openai.com/docs/api-reference/chat) for more details. diff --git a/bot/plugin_manager.py b/bot/plugin_manager.py index 8b7d4a4..2d0ad3f 100644 --- a/bot/plugin_manager.py +++ b/bot/plugin_manager.py @@ -31,7 +31,7 @@ class PluginManager: 'worldtimeapi': WorldTimeApiPlugin, 'youtube_audio_extractor': YouTubeAudioExtractorPlugin, 'dice': DicePlugin, - 'deepl': DeeplTranslatePlugin + 'deepl_translate': DeeplTranslatePlugin } self.plugins = [plugin_mapping[plugin]() for plugin in enabled_plugins if plugin in plugin_mapping] diff --git a/bot/plugins/deepl.py b/bot/plugins/deepl.py index b58d271..a43a6f8 100644 --- a/bot/plugins/deepl.py +++ b/bot/plugins/deepl.py @@ -10,12 +10,11 @@ class DeeplTranslatePlugin(Plugin): """ A plugin to translate a given text from a language to another, using DeepL """ - def __init__(self): - deepl_api_key = os.getenv('DEEPL_API_KEY') - if not deepl_api_key: - raise ValueError('DEEPL_API_KEY environment variable must be set to use DeepL Plugin') - self.api_key = deepl_api_key + deepl_api_key = os.getenv('DEEPL_API_KEY') + if not deepl_api_key: + raise ValueError('DEEPL_API_KEY environment variable must be set to use DeepL Plugin') + self.api_key = deepl_api_key def get_source_name(self) -> str: return "DeepL Translate" @@ -42,13 +41,11 @@ class DeeplTranslatePlugin(Plugin): headers = { "Authorization": f"DeepL-Auth-Key {self.api_key}", - "User-Agent": "chatgpt-telegram-bot/0.2.7", + "User-Agent": "chatgpt-telegram-bot", "Content-Type": "application/x-www-form-urlencoded" } - data = { "text": kwargs['text'], "target_lang": kwargs['to_language'] } - return requests.post(url, headers=headers, data=data).json()["translations"][0]["text"]