From 0b0771aaa4ce66acb666de1bc85bd4b3adfe8f33 Mon Sep 17 00:00:00 2001 From: ned Date: Thu, 22 Jun 2023 20:13:02 +0200 Subject: [PATCH] small improvements --- bot/plugins/spotify.py | 20 +++++++++++--------- bot/plugins/weather.py | 27 +++++++++++++-------------- bot/plugins/web_search.py | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/bot/plugins/spotify.py b/bot/plugins/spotify.py index b42b004..3c0db65 100644 --- a/bot/plugins/spotify.py +++ b/bot/plugins/spotify.py @@ -36,13 +36,12 @@ class SpotifyPlugin(Plugin): "type": "string", "enum": ["short_term", "medium_term", "long_term"], "description": "The time range of the data to be returned. Short term is the last 4 weeks, " - "medium term is last 6 months, long term is last several years. " - "Ignore if action is currently_playing", + "medium term is last 6 months, long term is last several years. Default to " + "short_term if not specified." } limit_param = { "type": "integer", - "description": "The number of results to return. Max is 50. Default to 5 if not specified." - "Ignore if action is currently_playing", + "description": "The number of results to return. Max is 50. Default to 5 if not specified.", } type_param = { "type": "string", @@ -60,7 +59,7 @@ class SpotifyPlugin(Plugin): }, { "name": "spotify_get_users_top_artists", - "description": "Get the user's top artists", + "description": "Get the user's top listened artists", "parameters": { "type": "object", "properties": { @@ -71,7 +70,7 @@ class SpotifyPlugin(Plugin): }, { "name": "spotify_get_users_top_tracks", - "description": "Get the user's top tracks", + "description": "Get the user's top listened tracks", "parameters": { "type": "object", "properties": { @@ -262,7 +261,8 @@ class SpotifyPlugin(Plugin): else: return {'error': 'Invalid search type. Must be track, artist or album'} - def _get_artist(self, response, albums): + @staticmethod + def _get_artist(response, albums): return { 'name': response['name'], 'url': response['external_urls']['spotify'], @@ -281,7 +281,8 @@ class SpotifyPlugin(Plugin): ], } - def _get_track(self, response): + @staticmethod + def _get_track(response): return { 'name': response['name'], 'artist': response['artists'][0]['name'], @@ -295,7 +296,8 @@ class SpotifyPlugin(Plugin): 'explicit': response['explicit'], } - def _get_album(self, response): + @staticmethod + def _get_album(response): return { 'name': response['name'], 'artist': response['artists'][0]['name'], diff --git a/bot/plugins/weather.py b/bot/plugins/weather.py index ad783a3..abfce45 100644 --- a/bot/plugins/weather.py +++ b/bot/plugins/weather.py @@ -15,6 +15,13 @@ class WeatherPlugin(Plugin): return "OpenMeteo" def get_spec(self) -> [Dict]: + latitude_param = {"type": "string", "description": "Latitude of the location"} + longitude_param = {"type": "string", "description": "Longitude of the location"} + unit_param = { + "type": "string", + "enum": ["celsius", "fahrenheit"], + "description": "The temperature unit to use. Infer this from the provided location.", + } return [ { "name": "get_current_weather", @@ -22,13 +29,9 @@ class WeatherPlugin(Plugin): "parameters": { "type": "object", "properties": { - "latitude": {"type": "string", "description": "Latitude of the location"}, - "longitude": {"type": "string", "description": "Longitude of the location"}, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"], - "description": "The temperature unit to use. Infer this from the provided location.", - }, + "latitude": latitude_param, + "longitude": longitude_param, + "unit": unit_param, }, "required": ["latitude", "longitude", "unit"], }, @@ -40,13 +43,9 @@ class WeatherPlugin(Plugin): "parameters": { "type": "object", "properties": { - "latitude": {"type": "string", "description": "Latitude of the location"}, - "longitude": {"type": "string", "description": "Longitude of the location"}, - "unit": { - "type": "string", - "enum": ["celsius", "fahrenheit"], - "description": "The temperature unit to use. Infer this from the provided location.", - }, + "latitude": latitude_param, + "longitude": longitude_param, + "unit": unit_param, "forecast_days": { "type": "integer", "description": "The number of days to forecast, including today. Default is 7. Max 14. " diff --git a/bot/plugins/web_search.py b/bot/plugins/web_search.py index 7594d61..0c8bff9 100644 --- a/bot/plugins/web_search.py +++ b/bot/plugins/web_search.py @@ -37,7 +37,7 @@ class WebSearchPlugin(Plugin): region='wt-wt', safesearch='off' ) - results = list(islice(ddgs_gen, 8)) + results = list(islice(ddgs_gen, 3)) if results is None or len(results) == 0: return {"Result": "No good DuckDuckGo Search Result was found"}