[Streams] Add toggleable button to stream alerts #5856

Merged
karlsbjorn merged 9 commits from streams-button into V3/develop 2022-12-29 20:18:26 +01:00
karlsbjorn commented 2022-10-01 17:26:59 +02:00 (Migrated from github.com)

Description of the changes

This PR adds a toggleable [p]streamset livebutton setting which creates a button under each stream alert (created either through [p]streamalert or [p]twitchstream/[p]youtubestream and the like) that will link to the relevant stream.
It is off by default.

image

Closes #5646

I'm also not sure if livebutton is the best name for this setting, I couldn't think of anything better. Maybe something like buttons or usebuttons looks better? Would love to hear feedback.

Have the changes in this PR been tested?

Yes

### Description of the changes This PR adds a toggleable `[p]streamset livebutton` setting which creates a button under each stream alert (created either through `[p]streamalert` or `[p]twitchstream`/`[p]youtubestream` and the like) that will link to the relevant stream. It is off by default. ![image](https://user-images.githubusercontent.com/40699625/193415576-a3b3f4b7-643a-43d6-92f9-eeea2e406d23.png) Closes #5646 I'm also not sure if `livebutton` is the best name for this setting, I couldn't think of anything better. Maybe something like `buttons` or `usebuttons` looks better? Would love to hear feedback. ### Have the changes in this PR been tested? <!-- Choose one (remove the line that doesn't apply): --> Yes <!-- If the question doesn't apply (for example, it's not a code change), choose Yes. Please respond to this question truthfully. We do not delay nor reject PRs based on the answer to this question but it allows to better review this PR. -->
karlsbjorn commented 2022-10-21 15:09:34 +02:00 (Migrated from github.com)

Since #5683 has now been merged, should the toggle for the button be taken from [p]set usebuttons instead of having it be a separate setting?

In case not, I've renamed the setting to [p]streamset usebuttons for consistency.

EDIT: After a short discussion on Discord, the setting should stay like it currently is since [p]set usebuttons is global, while [p]streamset usebuttons should be per-guild.

~~Since #5683 has now been merged, should the toggle for the button be taken from `[p]set usebuttons` instead of having it be a separate setting?~~ ~~In case not,~~ I've renamed the setting to `[p]streamset usebuttons` for consistency. EDIT: After a short discussion on Discord, the setting should stay like it currently is since `[p]set usebuttons` is global, while `[p]streamset usebuttons` should be per-guild.
Jackenmen (Migrated from github.com) requested changes 2022-12-29 06:33:56 +01:00
Jackenmen (Migrated from github.com) left a comment

Functionally works fine (aside from a small timeout issue which is mentioned in the review comment), I just have a couple of stylistic suggestions.

Functionally works fine (aside from a small timeout issue which is mentioned in the review comment), I just have a couple of stylistic suggestions.
Jackenmen (Migrated from github.com) commented 2022-12-29 06:02:47 +01:00

Code above is identical, this can be deduplicated by making this fragment not part of the if. To simplify this further, view can be set to None by default as then we don't have to do a ternary if inside ctx.send() call.

Also, the view needs to have a timeout set to None as the default is 3 minutes.

            view = None
            if use_buttons:
                stream_url = embed.url
                view = discord.ui.View(timeout=None)
                view.add_item(
                    discord.ui.Button(
                        label=_("Open Stream"), style=discord.ButtonStyle.link, url=stream_url
                    )
                )
            await ctx.send(embed=embed, view=view)
Code above is identical, this can be deduplicated by making this fragment not part of the `if`. To simplify this further, `view` can be set to `None` by default as then we don't have to do a ternary if inside `ctx.send()` call. Also, the view needs to have a timeout set to `None` as the default is 3 minutes. ```suggestion view = None if use_buttons: stream_url = embed.url view = discord.ui.View(timeout=None) view.add_item( discord.ui.Button( label=_("Open Stream"), style=discord.ButtonStyle.link, url=stream_url ) ) await ctx.send(embed=embed, view=view) ```
Jackenmen (Migrated from github.com) commented 2022-12-29 06:03:05 +01:00

Code below is identical, this can be deduplicated.

Code below is identical, this can be deduplicated. ```suggestion ```
@ -708,0 +720,4 @@
@streamset.command(name="usebuttons")
@commands.guild_only()
async def use_buttons(self, ctx: commands.Context):
"""Toggle whether to use buttons for stream alerts."""
Jackenmen (Migrated from github.com) commented 2022-12-29 06:06:22 +01:00
            await ctx.send(_("I will no longer use buttons in stream alerts."))
```suggestion await ctx.send(_("I will no longer use buttons in stream alerts.")) ```
@ -776,0 +801,4 @@
use_buttons: bool = await self.config.guild(channel.guild).use_buttons()
view = None
if use_buttons:
stream_url = embed.url
Jackenmen (Migrated from github.com) commented 2022-12-29 06:07:21 +01:00

Simplification by removal of the ternary if operator and replacing it with always setting initial value of view to None.

Also, the view needs to have a timeout set to None as the default is 3 minutes.

        use_buttons: bool = await self.config.guild(channel.guild).use_buttons()
        view = None
        if use_buttons:
            stream_url = embed.url
            view = discord.ui.View(timeout=None)
            view.add_item(
                discord.ui.Button(
                    label=_("Open 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,
Simplification by removal of the ternary if operator and replacing it with always setting initial value of `view` to `None`. Also, the view needs to have a timeout set to `None` as the default is 3 minutes. ```suggestion use_buttons: bool = await self.config.guild(channel.guild).use_buttons() view = None if use_buttons: stream_url = embed.url view = discord.ui.View(timeout=None) view.add_item( discord.ui.Button( label=_("Open 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, ```
karlsbjorn (Migrated from github.com) reviewed 2022-12-29 10:31:06 +01:00
karlsbjorn (Migrated from github.com) commented 2022-12-29 10:31:06 +01:00

From my testing I actually found that timeouts don't matter for discord.ButtonStyle.link style buttons, they're usable past the timeout which is why I didn't set one. You're right though that it's still better to set it explicitly.

From my testing I actually found that timeouts don't matter for `discord.ButtonStyle.link` style buttons, they're usable past the timeout which is why I didn't set one. You're right though that it's still better to set it explicitly.
Jackenmen (Migrated from github.com) reviewed 2022-12-29 17:01:03 +01:00
Jackenmen (Migrated from github.com) commented 2022-12-29 17:01:02 +01:00

Hmm, you're right, we actually shouldn't set a timeout to None because then it forever stays in the memory. We should just keep the default so that it's at least removed from the memory after 3 minutes.

The reason why I suggested this change was that the buttons disappeared from the message after a bit which I thought was related to the timeout (but it isn't because that would require you to explicitly edit the message in on_timeout())... I'm actually not sure why it happened and if it actually happened (maybe I confused messages?).

Would you mind removing the timeout= parameter?

Hmm, you're right, we actually shouldn't set a timeout to `None` because then it forever stays in the memory. We should just keep the default so that it's at least removed from the memory after 3 minutes. The reason why I suggested this change was that the buttons disappeared from the message after a bit which I thought was related to the timeout (but it isn't because that would require you to explicitly edit the message in `on_timeout()`)... I'm actually not sure why it happened *and if* it actually happened (maybe I confused messages?). Would you mind removing the `timeout=` parameter?
karlsbjorn (Migrated from github.com) reviewed 2022-12-29 17:20:19 +01:00
karlsbjorn (Migrated from github.com) commented 2022-12-29 17:20:19 +01:00

Done! You might've had [p]streamset autodelete toggled on and didn't notice the message getting deleted? Not sure

Done! You might've had `[p]streamset autodelete` toggled on and didn't notice the message getting deleted? Not sure
Jackenmen commented 2022-12-29 17:35:12 +01:00 (Migrated from github.com)

I think that "Watch the stream" might be a better button caption, what do you think?

image
image

I think that "Watch the stream" might be a better button caption, what do you think? ![image](https://user-images.githubusercontent.com/6032823/209982264-8bc99c63-45da-49b5-9a78-335b6ecda06d.png) ![image](https://user-images.githubusercontent.com/6032823/209982293-5a6ce0c5-056f-40ac-936e-15e47234a8b2.png)
karlsbjorn commented 2022-12-29 19:45:16 +01:00 (Migrated from github.com)

Sure, sounds more natural to me

Sure, sounds more natural to me
Jackenmen (Migrated from github.com) approved these changes 2022-12-29 20:18:18 +01:00
Jackenmen (Migrated from github.com) left a comment

Works as expected.

Works as expected. ![](https://i.fluffy.cc/b6wlBbdVkX83CHpLWxHZw74WJxHVQc9S.gif)
Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!5856
No description provided.