Skip to content

Commit

Permalink
Make use of dpy commands.Range on set status commands (#6227)
Browse files Browse the repository at this point in the history
  • Loading branch information
PredaaA authored Aug 10, 2023
1 parent 9e23c3a commit a06a704
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,13 @@ async def _set_status(self, ctx: commands.Context):
)
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_stream(self, ctx: commands.Context, streamer=None, *, stream_title=None):
async def _set_status_stream(
self,
ctx: commands.Context,
streamer: commands.Range[str, 1, 489] = None,
*,
stream_title: commands.Range[str, 1, 128] = None,
):
"""Sets [botname]'s streaming status to a twitch stream.
This will appear as `Streaming <stream_title>` or `LIVE ON TWITCH` depending on the context.
Expand All @@ -3056,12 +3062,6 @@ async def _set_status_stream(self, ctx: commands.Context, streamer=None, *, stre
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:
Expand All @@ -3074,7 +3074,9 @@ async def _set_status_stream(self, ctx: commands.Context, streamer=None, *, stre
@_set_status.command(name="playing", aliases=["game"])
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_game(self, ctx: commands.Context, *, game: str = None):
async def _set_status_game(
self, ctx: commands.Context, *, game: commands.Range[str, 1, 128] = None
):
"""Sets [botname]'s playing status.
This will appear as `Playing <game>` or `PLAYING A GAME: <game>` depending on the context.
Expand All @@ -3090,9 +3092,6 @@ async def _set_status_game(self, ctx: commands.Context, *, game: str = None):
"""

if game:
if len(game) > 128:
await ctx.send(_("The maximum length of game descriptions is 128 characters."))
return
game = discord.Game(name=game)
else:
game = None
Expand All @@ -3106,7 +3105,9 @@ async def _set_status_game(self, ctx: commands.Context, *, game: str = None):
@_set_status.command(name="listening")
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_listening(self, ctx: commands.Context, *, listening: str = None):
async def _set_status_listening(
self, ctx: commands.Context, *, listening: commands.Range[str, 1, 128] = None
):
"""Sets [botname]'s listening status.
This will appear as `Listening to <listening>`.
Expand All @@ -3123,11 +3124,6 @@ async def _set_status_listening(self, ctx: commands.Context, *, listening: str =

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
Expand All @@ -3142,7 +3138,9 @@ async def _set_status_listening(self, ctx: commands.Context, *, listening: str =
@_set_status.command(name="watching")
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_watching(self, ctx: commands.Context, *, watching: str = None):
async def _set_status_watching(
self, ctx: commands.Context, *, watching: commands.Range[str, 1, 128] = None
):
"""Sets [botname]'s watching status.
This will appear as `Watching <watching>`.
Expand All @@ -3159,9 +3157,6 @@ async def _set_status_watching(self, ctx: commands.Context, *, watching: str = N

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
Expand All @@ -3174,7 +3169,9 @@ async def _set_status_watching(self, ctx: commands.Context, *, watching: str = N
@_set_status.command(name="competing")
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_competing(self, ctx: commands.Context, *, competing: str = None):
async def _set_status_competing(
self, ctx: commands.Context, *, competing: commands.Range[str, 1, 128] = None
):
"""Sets [botname]'s competing status.
This will appear as `Competing in <competing>`.
Expand All @@ -3191,11 +3188,6 @@ async def _set_status_competing(self, ctx: commands.Context, *, competing: str =

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
Expand All @@ -3210,7 +3202,9 @@ async def _set_status_competing(self, ctx: commands.Context, *, competing: str =
@_set_status.command(name="custom")
@commands.bot_in_a_guild()
@commands.is_owner()
async def _set_status_custom(self, ctx: commands.Context, *, text: str = None):
async def _set_status_custom(
self, ctx: commands.Context, *, text: commands.Range[str, 1, 128] = None
):
"""Sets [botname]'s custom status.
This will appear as `<text>`.
Expand All @@ -3227,9 +3221,6 @@ async def _set_status_custom(self, ctx: commands.Context, *, text: str = None):

status = ctx.bot.guilds[0].me.status if len(ctx.bot.guilds) > 0 else discord.Status.online
if text:
if len(text) > 128:
await ctx.send(_("The maximum length of custom statuses is 128 characters."))
return
activity = discord.Activity(name=text, state=text, type=discord.ActivityType.custom)
else:
activity = None
Expand Down

0 comments on commit a06a704

Please sign in to comment.