Repository: Cog-Creators/Red-DiscordBot

Issue:
[Streams] Togglable button for streamalerts
### Type of feature request

Cog, Command

### Description of the feature you're suggesting

With dpy2 coming with tons of nice features, i think a button for `open stream` could be nice to have a toggle under `[p]streamset` for those who wants a button to show on streamalerts.

Example:
![s2Mo8Kp](https://user-images.githubusercontent.com/63972751/161043777-04a42ddd-cdb4-4286-aee8-cdc348eb989e.png)


### Anything else?

_No response_


Discussion:

Resolving patch:
diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py
--- a/redbot/cogs/streams/streams.py
+++ b/redbot/cogs/streams/streams.py
@@ -61,6 +61,7 @@ class Streams(commands.Cog):
         "live_message_nomention": False,
         "ignore_reruns": False,
         "ignore_schedule": False,
+        "use_buttons": False,
     }
 
     role_defaults = {"mention": False}
@@ -289,7 +290,18 @@ async def check_online(
                     return
             else:
                 embed = info
-            await ctx.send(embed=embed)
+
+            use_buttons: bool = await self.config.guild(ctx.channel.guild).use_buttons()
+            view = None
+            if use_buttons:
+                stream_url = embed.url
+                view = discord.ui.View()
+                view.add_item(
+                    discord.ui.Button(
+                        label=_("Watch the stream"), style=discord.ButtonStyle.link, url=stream_url
+                    )
+                )
+            await ctx.send(embed=embed, view=view)
 
     @commands.group()
     @commands.guild_only()
@@ -705,6 +717,19 @@ async def ignore_schedule(self, ctx: commands.Context):
             await self.config.guild(guild).ignore_schedule.set(True)
             await ctx.send(_("Streams schedules will no longer send an alert."))
 
+    @streamset.command(name="usebuttons")
+    @commands.guild_only()
+    async def use_buttons(self, ctx: commands.Context):
+        """Toggle whether to use buttons for stream alerts."""
+        guild = ctx.guild
+        current_setting: bool = await self.config.guild(guild).use_buttons()
+        if current_setting:
+            await self.config.guild(guild).use_buttons.set(False)
+            await ctx.send(_("I will no longer use buttons in stream alerts."))
+        else:
+            await self.config.guild(guild).use_buttons.set(True)
+            await ctx.send(_("I will use buttons in stream alerts."))
+
     async def add_or_remove(self, ctx: commands.Context, stream, discord_channel):
         if discord_channel.id not in stream.channels:
             stream.channels.append(discord_channel.id)
@@ -773,10 +798,21 @@ async def _send_stream_alert(
         *,
         is_schedule: bool = False,
     ):
+        use_buttons: bool = await self.config.guild(channel.guild).use_buttons()
+        view = None
+        if use_buttons:
+            stream_url = embed.url
+            view = discord.ui.View()
+            view.add_item(
+                discord.ui.Button(
+                    label=_("Watch the stream"), style=discord.ButtonStyle.link, url=stream_url
+                )
+            )
         m = await channel.send(
             content,
             embed=embed,
             allowed_mentions=discord.AllowedMentions(roles=True, everyone=True),
+            view=view,
         )
         message_data = {"guild": m.guild.id, "channel": m.channel.id, "message": m.id}
         if is_schedule:


Test patch: