From 87db81c72b7260c30b42c6bd65cff84a240db759 Mon Sep 17 00:00:00 2001 From: TrustyJAID Date: Fri, 23 Aug 2024 11:23:12 -0600 Subject: [PATCH] [Weather] 1.5.1 Include wind gusts if available - Add all weather info to list markdown to include wind gusts underneath but part of the wind line. - Add support to run the commands in channels without embed links permission. - In cases where the bot cannot embed links the forecast options will only show 3 forecasts instead of 5 due to restrictions on characters the bot can send. --- README.md | 2 +- weather/api.py | 55 ++++++++++++++++++++++++++++++++++++---------- weather/menus.py | 6 +++-- weather/weather.py | 7 +----- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 3271672df1..81893fb81b 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ TrustyJAID's Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-Disc | Turbo | 1.0.0 |
Relive that 90's computer feel with turbo mode on any command!Add turbo mode to all your commands!
| TrustyJAID | | Tweets | 3.0.1 |
Cog for getting info from TwitterGets the latest Tweet from twitter accounts and posts them in the specified channels
| palmtree5 and TrustyJAID | | Twitch | 1.4.0 |
Get basic twitch account information.Get notified of new twitch followers and get basic profile info.
| TrustyJAID | -| Weather | 1.5.0 |
Show the current weather in specified locations!Check the current weather in many cities around the world including in Kelvin.
| TrustyJAID | +| Weather | 1.5.1 |
Show the current weather in specified locations!Check the current weather in many cities around the world including in Kelvin.
| TrustyJAID | | Welcome | 2.5.3 |
Welcome new users to the serverWelcome new users to the server or say goodbye when they leave.
| irdumb and TrustyJAID | Any questions you can find [TrustyBot](https://discordapp.com/api/oauth2/authorize?client_id=268562382173765643&permissions=2146958583&scope=bot) and myself over on [my server](https://discord.gg/wVVrqej) or on the [Redbot Cog Support server](https://discord.gg/GET4DVk). diff --git a/weather/api.py b/weather/api.py index 0c815f3fea..5f745cc937 100644 --- a/weather/api.py +++ b/weather/api.py @@ -344,22 +344,29 @@ def __str__(self): sunrise_ts = f"" if self.sunrise else _("No Data") sunset_ts = f"" if self.sunset else _("No Data") windspeed = str(self.wind_speed) + " " + self.units.get().speed + wind_gust = "" cloudiness_emoji = WEATHER_EMOJIS[get_cloud_num(self.clouds or 0)] + if self.wind_gust: + wind_gust = ( + _(" - \N{WIND BLOWING FACE}\N{VARIATION SELECTOR-16} **Wind Gusts**: ") + + f"{self.wind_gust} {self.units.get().speed}\n" + ) ret = _( - "{weather_emoji} **Weather**: {weather}\n" - "\N{FACE WITH COLD SWEAT} **Humidity**: {humidity}%\n" - "\N{DASH SYMBOL} **Wind Speed**: {wind_speed} {direction}\n" - "\N{THERMOMETER} **Temperature**: {temp}\n" - "{cloudiness_emoji} **Cloudiness**: {clouds}%\n" - "\N{SUNRISE OVER MOUNTAINS} **Sunrise**: {sunrise_ts}\n" - "\N{SUNSET OVER BUILDINGS} **Sunset**: {sunset_ts}\n" - "\N{BLACK SUN WITH RAYS}\N{VARIATION SELECTOR-16} **UV Index**: {uvi}\n" - "\N{BALLOON} **Atmospheric Pressure**: {pressure} hPa\n" + "- {weather_emoji} **Weather**: {weather}\n" + "- \N{FACE WITH COLD SWEAT} **Humidity**: {humidity}%\n" + "- \N{DASH SYMBOL} **Wind Speed**: {wind_speed} {direction}\n{wind_gust}" + "- \N{THERMOMETER} **Temperature**: {temp}\n" + "- {cloudiness_emoji} **Cloudiness**: {clouds}%\n" + "- \N{SUNRISE OVER MOUNTAINS} **Sunrise**: {sunrise_ts}\n" + "- \N{SUNSET OVER BUILDINGS} **Sunset**: {sunset_ts}\n" + "- \N{BLACK SUN WITH RAYS}\N{VARIATION SELECTOR-16} **UV Index**: {uvi}\n" + "- \N{BALLOON} **Atmospheric Pressure**: {pressure} hPa\n" ).format( weather_emoji="".join(i.emoji for i in self.weather), weather=humanize_list([i.description for i in self.weather]), humidity=self.humidity, wind_speed=windspeed, + wind_gust=wind_gust, direction=self.wind_dir, temp=self.temp, cloudiness_emoji=cloudiness_emoji, @@ -370,15 +377,15 @@ def __str__(self): pressure=self.pressure, ) if self.visibility: - ret += _("\N{EYEGLASSES} **Visibility**: {visibility} m\n").format( + ret += _("- \N{EYEGLASSES} **Visibility**: {visibility} m\n").format( visibility=self.visibility ) if self.rain: - ret += _("\N{CLOUD WITH RAIN}\N{VARIATION SELECTOR-16} **Rain**: {rain}\n").format( + ret += _("- \N{CLOUD WITH RAIN}\N{VARIATION SELECTOR-16} **Rain**: {rain}\n").format( rain=str(self.rain) ) if self.snow: - ret += _("\N{CLOUD WITH SNOW}\N{VARIATION SELECTOR-16} **Snow**: {snow}\n").format( + ret += _("- \N{CLOUD WITH SNOW}\N{VARIATION SELECTOR-16} **Snow**: {snow}\n").format( snow=str(self.snow) ) return ret @@ -617,6 +624,30 @@ async def get( raise APIError(data["message"]) return cls.from_json(data, units, name, state, country) + def text( + self, include_forecast: Optional[bool] = None, include_hourly: Optional[bool] = None + ) -> str: + if self.state: + location = f"{self.name}, {self.state}, {self.country}" + else: + location = f"{self.name}, {self.country}" + msg = _("Weather for {location}").format(location=location) + "\n" + if not include_forecast and not include_hourly: + if self.daily and self.daily[0].summary: + msg += self.daily[0].summary + "\n" + msg += _("Current Weather") + f" ()\n{self.current}\n" + elif include_forecast: + for day in self.daily[:3]: + msg += f"\n{day}\n" + if include_hourly: + for hour in self.hourly[:3]: + msg += f" ()\n{hour}\n" + alerts = "\n".join(str(a) for a in self.alerts) + if alerts: + msg += alerts + "\n" + msg += _("-# Powered by ") + return msg + def embed( self, include_forecast: Optional[bool] = None, include_hourly: Optional[bool] = None ) -> discord.Embed: diff --git a/weather/menus.py b/weather/menus.py index fbd9dab081..c4a68e80d8 100644 --- a/weather/menus.py +++ b/weather/menus.py @@ -62,8 +62,10 @@ async def format_page(self, view: BaseMenu, page: Geocoding): if self._last_coords is None: self._last_coords = page self._last_we = we - em = we.embed(include_forecast=self.forecast, include_hourly=self.hourly) - return em + if await view.ctx.embed_requested(): + return we.embed(include_forecast=self.forecast, include_hourly=self.hourly) + else: + return we.text(include_forecast=self.forecast, include_hourly=self.hourly) class StopButton(discord.ui.Button): diff --git a/weather/weather.py b/weather/weather.py index 1766444780..36cea2dc02 100644 --- a/weather/weather.py +++ b/weather/weather.py @@ -21,7 +21,7 @@ class Weather(commands.Cog): """Get weather data from https://openweathermap.org""" __author__ = ["TrustyJAID"] - __version__ = "1.5.0" + __version__ = "1.5.1" def __init__(self, bot): self.bot = bot @@ -94,7 +94,6 @@ async def get_appid(self, ctx: commands.Context) -> Optional[str]: forecast="Whether or not to include the 5 day forecast information", units="The units to display, standard is kelvin", ) - @commands.bot_has_permissions(embed_links=True) async def weather( self, ctx: commands.Context, @@ -132,13 +131,11 @@ async def weather( ).start(ctx=ctx) @weather.command(name="zip") - @commands.bot_has_permissions(embed_links=True) @discord.app_commands.describe( zipcode="zip/postal code, country code format", forecast="Whether or not to include the 5 day forecast information", units="The units to display, standard is kelvin", ) - @commands.bot_has_permissions(embed_links=True) async def weather_by_zip( self, ctx: commands.Context, @@ -173,14 +170,12 @@ async def weather_by_zip( ).start(ctx=ctx) @weather.command(name="coords", aliases=["co", "coordinates"]) - @commands.bot_has_permissions(embed_links=True) @discord.app_commands.describe( lat="The latitude", lon="The longitude", forecast="Whether or not to include the 5 day forecast information", units="The units to display, standard is kelvin", ) - @commands.bot_has_permissions(embed_links=True) async def weather_by_coordinates( self, ctx: commands.Context,