Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow temprole to use seconds and minutes #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions temprole/temprole.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

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
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."
Expand Down Expand Up @@ -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}!")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down