From a1b03be27e987592e7ad50983abe761fe729fd07 Mon Sep 17 00:00:00 2001 From: Tyler Adam Date: Tue, 23 Apr 2019 06:57:46 -0400 Subject: [PATCH] Add support for custom stream alert messages per guild (#2600) --- redbot/cogs/streams/streams.py | 73 +++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/redbot/cogs/streams/streams.py b/redbot/cogs/streams/streams.py index 1189af610..6fe43165f 100644 --- a/redbot/cogs/streams/streams.py +++ b/redbot/cogs/streams/streams.py @@ -38,7 +38,13 @@ class Streams(commands.Cog): global_defaults = {"tokens": {}, "streams": []} - guild_defaults = {"autodelete": False, "mention_everyone": False, "mention_here": False} + guild_defaults = { + "autodelete": False, + "mention_everyone": False, + "mention_here": False, + "live_message_mention": False, + "live_message_nomention": False, + } role_defaults = {"mention": False} @@ -338,6 +344,55 @@ class Streams(commands.Cog): await ctx.maybe_send_embed(message) + @streamset.group() + @commands.guild_only() + async def message(self, ctx: commands.Context): + """Manage custom message for stream alerts.""" + pass + + @message.command(name="mention") + @commands.guild_only() + async def with_mention(self, ctx: commands.Context, message: str = None): + """Set stream alert message when mentions are enabled. + + Use `{mention}` in the message to insert the selected mentions. + + Use `{stream.name}` in the message to insert the channel or user name. + + For example: `[p]streamset message mention "{mention}, {stream.name} is live!"` + """ + if message is not None: + guild = ctx.guild + await self.db.guild(guild).live_message_mention.set(message) + await ctx.send(_("stream alert message set!")) + else: + await ctx.send_help() + + @message.command(name="nomention") + @commands.guild_only() + async def without_mention(self, ctx: commands.Context, message: str = None): + """Set stream alert message when mentions are disabled. + + Use `{stream.name}` in the message to insert the channel or user name. + + For example: `[p]streamset message nomention "{stream.name} is live!"` + """ + if message is not None: + guild = ctx.guild + await self.db.guild(guild).live_message_nomention.set(message) + await ctx.send(_("stream alert message set!")) + else: + await ctx.send_help() + + @message.command(name="clear") + @commands.guild_only() + async def clear_message(self, ctx: commands.Context): + """Reset the stream alert messages in this server.""" + guild = ctx.guild + await self.db.guild(guild).live_message_mention.set(False) + await self.db.guild(guild).live_message_nomention.set(False) + await ctx.send(_("Stream alerts in this server will now use the default alert message.")) + @streamset.group() @commands.guild_only() async def mention(self, ctx: commands.Context): @@ -488,11 +543,19 @@ class Streams(commands.Cog): mention_str, edited_roles = await self._get_mention_str(channel.guild) if mention_str: - content = _("{mention}, {stream.name} is live!").format( - mention=mention_str, stream=stream - ) + alert_msg = await self.db.guild(channel.guild).live_message_mention() + if alert_msg: + content = alert_msg.format(mention=mention_str, stream=stream) + else: + content = _("{mention}, {stream.name} is live!").format( + mention=mention_str, stream=stream + ) else: - content = _("{stream.name} is live!").format(stream=stream) + alert_msg = await self.db.guild(channel.guild).live_message_nomention() + if alert_msg: + content = alert_msg.format(stream=stream) + else: + content = _("{stream.name} is live!").format(stream=stream) m = await channel.send(content, embed=embed) stream._messages_cache.append(m)