From 676f34185d2f137ffe6833325da09f2adf1b5a00 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 21 Jan 2021 08:41:28 -0500 Subject: [PATCH] [Core] Add sensible character lengths to activity statuses (#4663) * Add sensible character lengths * Add translation function Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/core_commands.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index a18e28caa..e54e3d664 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1842,7 +1842,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): if game: if len(game) > 128: - await ctx.send("The maximum length of game descriptions is 128 characters.") + await ctx.send(_("The maximum length of game descriptions is 128 characters.")) return game = discord.Game(name=game) else: @@ -1862,6 +1862,11 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 else discord.Status.online if listening: + if len(listening) > 128: + await ctx.send( + _("The maximum length of listening descriptions is 128 characters.") + ) + return activity = discord.Activity(name=listening, type=discord.ActivityType.listening) else: activity = None @@ -1881,6 +1886,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 else discord.Status.online if watching: + if len(watching) > 128: + await ctx.send(_("The maximum length of watching descriptions is 128 characters.")) + return activity = discord.Activity(name=watching, type=discord.ActivityType.watching) else: activity = None @@ -1898,6 +1906,11 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 else discord.Status.online if competing: + if len(competing) > 128: + await ctx.send( + _("The maximum length of competing descriptions is 128 characters.") + ) + return activity = discord.Activity(name=competing, type=discord.ActivityType.competing) else: activity = None @@ -1938,11 +1951,13 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): await ctx.bot.change_presence(status=status, activity=game) await ctx.send(_("Status changed to {}.").format(status)) - @_set.command(name="streaming", aliases=["stream"], usage="[( )]") + @_set.command( + name="streaming", aliases=["stream", "twitch"], usage="[( )]" + ) @checks.bot_in_a_guild() @checks.is_owner() async def stream(self, ctx: commands.Context, streamer=None, *, stream_title=None): - """Sets [botname]'s streaming status. + """Sets [botname]'s streaming status to a twitch stream. Leaving both streamer and stream_title empty will clear it.""" @@ -1952,6 +1967,12 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): stream_title = stream_title.strip() if "twitch.tv/" not in streamer: streamer = "https://www.twitch.tv/" + streamer + if len(streamer) > 511: + await ctx.send(_("The maximum length of the streamer url is 511 characters.")) + return + if len(stream_title) > 128: + await ctx.send(_("The maximum length of the stream title is 128 characters.")) + return activity = discord.Streaming(url=streamer, name=stream_title) await ctx.bot.change_presence(status=status, activity=activity) elif streamer is not None: