From f28d6dff32740a053c5d038033009fa17a24dbac Mon Sep 17 00:00:00 2001 From: Tyler Adam Date: Thu, 25 Apr 2019 11:58:58 -0400 Subject: [PATCH] [Streams] Add ability to exclude rerun streams from alerts (#2620) * [Streams] Add ability to exclude rerun streams from alerts * [Docs] Changelog entries for contributions by EgonSpengler * Changelog entry for #2620 [Streams] Ignore Reruns In Alerts --- docs/changelog_3_1_0.rst | 11 +++++++++++ redbot/cogs/streams/streams.py | 19 ++++++++++++++++++- redbot/cogs/streams/streamtypes.py | 6 +++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/changelog_3_1_0.rst b/docs/changelog_3_1_0.rst index a5fda5c34..ebe1824ab 100644 --- a/docs/changelog_3_1_0.rst +++ b/docs/changelog_3_1_0.rst @@ -63,6 +63,7 @@ Mod --- * Admins can now decide how many times message has to be repeated before ``deleterepeats`` removes it (`#2437`_) + * Fix: make ``[p]ban [days]`` optional as per the doc (`#2602`_) ------------- Setup Scripts @@ -72,6 +73,13 @@ Setup Scripts * ``redbot-setup convert`` now used to convert between libraries (`#2579`_) * Backup support for Mongo is currently broken (`#2579`_) +------- +Streams +------- + + * Add support for custom stream alert messages per guild (`#2600`_) + * Add ability to exclude rerun Twitch streams, and note rerun streams in embed status (`#2620`_) + ----- Tests ----- @@ -125,5 +133,8 @@ Utility Functions .. _#2591: https://github.com/Cog-Creators/Red-DiscordBot/pull/2591 .. _#2592: https://github.com/Cog-Creators/Red-DiscordBot/pull/2592 .. _#2595: https://github.com/Cog-Creators/Red-DiscordBot/pull/2595 +.. _#2600: https://github.com/Cog-Creators/Red-DiscordBot/pull/2600 +.. _#2602: https://github.com/Cog-Creators/Red-DiscordBot/pull/2602 .. _#2604: https://github.com/Cog-Creators/Red-DiscordBot/pull/2604 .. _#2606: https://github.com/Cog-Creators/Red-DiscordBot/pull/2606 +.. _#2620: https://github.com/Cog-Creators/Red-DiscordBot/pull/2620 diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index a1a6a5f71..9ba5c398e 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -44,6 +44,7 @@ class Streams(commands.Cog): "mention_here": False, "live_message_mention": False, "live_message_nomention": False, + "ignore_reruns": False, } role_defaults = {"mention": False} @@ -461,6 +462,19 @@ class Streams(commands.Cog): else: await ctx.send(_("Notifications will no longer be deleted.")) + @streamset.command(name="ignorereruns") + @commands.guild_only() + async def ignore_reruns(self, ctx: commands.Context): + """Toggle excluding rerun streams from alerts.""" + guild = ctx.guild + current_setting = await self.db.guild(guild).ignore_reruns() + if current_setting: + await self.db.guild(guild).ignore_reruns.set(False) + await ctx.send(_("Streams of type 'rerun' will be included in alerts.")) + else: + await self.db.guild(guild).ignore_reruns.set(True) + await ctx.send(_("Streams of type 'rerun' will no longer send an alert.")) + async def add_or_remove(self, ctx: commands.Context, stream): if ctx.channel.id not in stream.channels: stream.channels.append(ctx.channel.id) @@ -524,7 +538,7 @@ class Streams(commands.Cog): for stream in self.streams: with contextlib.suppress(Exception): try: - embed = await stream.is_online() + embed, is_rerun = await stream.is_online() except OfflineStream: if not stream._messages_cache: continue @@ -540,6 +554,9 @@ class Streams(commands.Cog): continue for channel_id in stream.channels: channel = self.bot.get_channel(channel_id) + ignore_reruns = await self.db.guild(channel.guild).ignore_reruns() + if ignore_reruns and is_rerun: + continue mention_str, edited_roles = await self._get_mention_str(channel.guild) if mention_str: diff --git a/redbot/cogs/streams/streamtypes.py b/redbot/cogs/streams/streamtypes.py index b4d2a3cd4..d0ce0e462 100644 --- a/redbot/cogs/streams/streamtypes.py +++ b/redbot/cogs/streams/streamtypes.py @@ -174,7 +174,8 @@ class TwitchStream(Stream): # self.already_online = True # In case of rename self.name = data["stream"]["channel"]["name"] - return self.make_embed(data) + is_rerun = True if data["stream"]["stream_type"] == "rerun" else False + return self.make_embed(data), is_rerun elif r.status == 400: raise InvalidTwitchCredentials() elif r.status == 404: @@ -204,6 +205,7 @@ class TwitchStream(Stream): def make_embed(self, data): channel = data["stream"]["channel"] + is_rerun = data["stream"]["stream_type"] == "rerun" url = channel["url"] logo = channel["logo"] if logo is None: @@ -211,6 +213,8 @@ class TwitchStream(Stream): status = channel["status"] if not status: status = "Untitled broadcast" + if is_rerun: + status += " - Rerun" embed = discord.Embed(title=status, url=url) embed.set_author(name=channel["display_name"]) embed.add_field(name="Followers", value=channel["followers"])