From fca9b55343999fc12051be7ef2e5cb17fbd0a69f Mon Sep 17 00:00:00 2001 From: crayyy_zee <65814383+i-am-zaidali@users.noreply.github.com> Date: Fri, 7 Oct 2022 23:13:01 +0500 Subject: [PATCH 1/2] Allow temprole to use seconds and minutes --- temprole/temprole.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/temprole/temprole.py b/temprole/temprole.py index efec0b3..bcbdefa 100644 --- a/temprole/temprole.py +++ b/temprole/temprole.py @@ -34,9 +34,9 @@ TimeConverter = timedelta else: TimeConverter = commands.converter.TimedeltaConverter( - minimum=timedelta(hours=1), - allowed_units=["weeks", "days", "hours"], - default_unit="days" + minimum=timedelta(seconds=30), + allowed_units=["weeks", "days", "hours", "seconds", "minutes"], + default_unit="minutes" ) OVERFLOW_ERROR = "The time set is way too high, consider setting something reasonable." From a10af607601f0f3df5539deff4ff13dfc799c2f7 Mon Sep 17 00:00:00 2001 From: crayyy_zee <65814383+i-am-zaidali@users.noreply.github.com> Date: Sat, 8 Oct 2022 18:21:03 +0500 Subject: [PATCH 2/2] edit docstring and fix time formatting --- temprole/temprole.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/temprole/temprole.py b/temprole/temprole.py index bcbdefa..cd2ce09 100644 --- a/temprole/temprole.py +++ b/temprole/temprole.py @@ -28,7 +28,7 @@ import discord from redbot.core import commands, Config -from redbot.core.utils.chat_formatting import humanize_list +from redbot.core.utils.chat_formatting import humanize_list, humanize_timedelta if typing.TYPE_CHECKING: TimeConverter = timedelta @@ -80,7 +80,7 @@ async def _add(self, ctx: commands.Context, user: discord.Member, role: discord. """ Assign a temporary role to expire after a time. - For the time, enter in terms of weeks (w), days (d), and/or hours (h). + For the time, enter in terms of weeks (w), days (d), hours (h), minutes (m) and/or seconds (s). """ if role in user.roles: return await ctx.send(f"That user already has {role.mention}!") @@ -104,12 +104,12 @@ async def _add(self, ctx: commands.Context, user: discord.Member, role: discord. if role not in user.roles: await user.add_roles( role, - reason=f"TempRole: added by {ctx.author}, expires in {time.days}d {time.seconds//3600}h" + reason=f"TempRole: added by {ctx.author}, expires in {huamnize_timedelta(timedelta=time)}" ) else: return await ctx.send("I cannot assign this role!") - message = f"TempRole {role.mention} for {user.mention} has been added. Expires in {time.days} days {time.seconds//3600} hours." + message = f"TempRole {role.mention} for {user.mention} has been added. Expires in {huamnize_timedelta(timedelta=time)}." await self._maybe_confirm(ctx, message) await self._maybe_send_log(ctx.guild, message) @@ -160,14 +160,14 @@ async def _self_add(self, ctx: commands.Context, role: discord.Role, *, time: Ti if role not in ctx.author.roles: await ctx.author.add_roles( role, - reason=f"TempRole: added by {ctx.author}, expires in {time.days}d {time.seconds//3600}h" + reason=f"TempRole: added by {ctx.author}, expires in {huamnize_timedelta(timedelta=time)}" ) else: return await ctx.send("You already have this role!") else: return await ctx.send("I cannot assign this role!") - message = f"Self-TempRole {role.mention} has been added. Expires in {time.days} days {time.seconds//3600} hours." + message = f"Self-TempRole {role.mention} has been added. Expires in {huamnize_timedelta(timedelta=time)}." await self._maybe_confirm(ctx, message) await self._maybe_send_log(ctx.guild, message) @@ -205,7 +205,7 @@ async def _remaining(self, ctx: commands.Context, role: discord.Role): allowed_mentions=discord.AllowedMentions.none() ) r_time = datetime.fromtimestamp(cur_tr) - datetime.now() - return await ctx.maybe_send_embed(f"**Time remaining:** {r_time.days} days {round(r_time.seconds/3600, 1)} hours") + return await ctx.maybe_send_embed(f"**Time remaining:** {huamnize_timedelta(timedelta=r_time)}") @commands.bot_has_permissions(embed_links=True) @commands.admin_or_permissions(manage_roles=True) @@ -229,7 +229,7 @@ async def _list(self, ctx: commands.Context, user: discord.Member = None): role: discord.Role = ctx.guild.get_role(int(temp_role)) if role: r_time = datetime.fromtimestamp(end_ts) - datetime.now() - desc += f"{role.mention}: ends in {r_time.days}d {round(r_time.seconds/3600, 1)}h\n" + desc += f"{role.mention}: ends in {huamnize_timedelta(timedelta=r_time)}\n" else: del member_temp_roles[temp_role] return await ctx.send(embed=discord.Embed(