mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Streams] Add toggleable button to stream alerts (#5856)
Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
parent
9b1171ea8c
commit
d3308af0e2
@ -338,6 +338,22 @@ To set the Twitch API tokens, follow these steps:
|
|||||||
.. attention:: These tokens are sensitive and should only be
|
.. attention:: These tokens are sensitive and should only be
|
||||||
used in a private channel or in DM with the bot.
|
used in a private channel or in DM with the bot.
|
||||||
|
|
||||||
|
.. _streams-command-streamset-usebuttons:
|
||||||
|
|
||||||
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
streamset usebuttons
|
||||||
|
^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
**Syntax**
|
||||||
|
|
||||||
|
.. code-block:: none
|
||||||
|
|
||||||
|
[p]streamset usebuttons
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
Toggle whether to use buttons for stream alerts.
|
||||||
|
|
||||||
.. _streams-command-picarto:
|
.. _streams-command-picarto:
|
||||||
|
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
|
|||||||
@ -61,6 +61,7 @@ class Streams(commands.Cog):
|
|||||||
"live_message_nomention": False,
|
"live_message_nomention": False,
|
||||||
"ignore_reruns": False,
|
"ignore_reruns": False,
|
||||||
"ignore_schedule": False,
|
"ignore_schedule": False,
|
||||||
|
"use_buttons": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
role_defaults = {"mention": False}
|
role_defaults = {"mention": False}
|
||||||
@ -289,7 +290,18 @@ class Streams(commands.Cog):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
embed = info
|
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.group()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -705,6 +717,19 @@ class Streams(commands.Cog):
|
|||||||
await self.config.guild(guild).ignore_schedule.set(True)
|
await self.config.guild(guild).ignore_schedule.set(True)
|
||||||
await ctx.send(_("Streams schedules will no longer send an alert."))
|
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):
|
async def add_or_remove(self, ctx: commands.Context, stream, discord_channel):
|
||||||
if discord_channel.id not in stream.channels:
|
if discord_channel.id not in stream.channels:
|
||||||
stream.channels.append(discord_channel.id)
|
stream.channels.append(discord_channel.id)
|
||||||
@ -773,10 +798,21 @@ class Streams(commands.Cog):
|
|||||||
*,
|
*,
|
||||||
is_schedule: bool = False,
|
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(
|
m = await channel.send(
|
||||||
content,
|
content,
|
||||||
embed=embed,
|
embed=embed,
|
||||||
allowed_mentions=discord.AllowedMentions(roles=True, everyone=True),
|
allowed_mentions=discord.AllowedMentions(roles=True, everyone=True),
|
||||||
|
view=view,
|
||||||
)
|
)
|
||||||
message_data = {"guild": m.guild.id, "channel": m.channel.id, "message": m.id}
|
message_data = {"guild": m.guild.id, "channel": m.channel.id, "message": m.id}
|
||||||
if is_schedule:
|
if is_schedule:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user