diff --git a/administrator/utils.py b/administrator/utils.py index 32e609f..6908e4e 100644 --- a/administrator/utils.py +++ b/administrator/utils.py @@ -13,3 +13,13 @@ def time_pars(s: str) -> timedelta: w, d, h, m, s = [i if i else 0 for i in [w, d, h, m, s]] return timedelta(weeks=int(w), days=int(d), hours=int(h), minutes=int(m), seconds=int(s)) raise BadArgument() + + +def seconds_to_time_string(seconds: float) -> str: + days, seconds = divmod(seconds, 86400) + hours, seconds = divmod(seconds, 3600) + minutes, seconds = divmod(seconds, 60) + return f"""{f"{days}d {hours}h {minutes}m {seconds}s" + if days > 0 else f"{hours}h {minutes}m {seconds}s" + if hours > 0 else f"{minutes}m {seconds}s" + if minutes > 0 else f"{seconds}s"}""" diff --git a/db/WarnAction.py b/db/WarnAction.py index 634e29d..2f6cfe1 100644 --- a/db/WarnAction.py +++ b/db/WarnAction.py @@ -1,14 +1,14 @@ from datetime import timedelta from db import Base -from sqlalchemy import Column, Integer, BigInteger, Float, String +from sqlalchemy import Column, Integer, BigInteger, String class WarnAction(Base): __tablename__ = "warn_actions" id = Column(Integer, primary_key=True) guild = Column(BigInteger, nullable=False) - count = Column(Float, nullable=False, unique=True) + count = Column(Integer, nullable=False, unique=True) action = Column(String, nullable=False) duration = Column(BigInteger) diff --git a/extensions/reminder.py b/extensions/reminder.py index d2b8913..1003f30 100644 --- a/extensions/reminder.py +++ b/extensions/reminder.py @@ -8,7 +8,7 @@ from discord.ext import tasks from administrator.logger import logger from administrator import db -from administrator.utils import time_pars +from administrator.utils import time_pars, seconds_to_time_string extension_name = "reminders" logger = logger.getChild(extension_name) @@ -45,12 +45,7 @@ class Reminders(commands.Cog, name="Reminder"): s.commit() s.close() - hours, seconds = divmod(time.seconds, 3600) - minutes, seconds = divmod(seconds, 60) - await ctx.send(f"""Remind you in {f"{time.days}d {hours}h {minutes}m {seconds}s" - if time.days > 0 else f"{hours}h {minutes}m {seconds}s" - if hours > 0 else f"{minutes}m {seconds}s" - if minutes > 0 else f"{seconds}s"} !""") + await ctx.send(f"""Remind you in {seconds_to_time_string(time.total_seconds())} !""") @reminder.group("list", pass_context=True) async def reminder_list(self, ctx: commands.Context): diff --git a/extensions/warn.py b/extensions/warn.py index e481856..17a0ade 100644 --- a/extensions/warn.py +++ b/extensions/warn.py @@ -4,7 +4,7 @@ from discord.ext.commands import BadArgument from administrator import db from administrator.logger import logger -from administrator.utils import time_pars +from administrator.utils import time_pars, seconds_to_time_string extension_name = "warn" logger = logger.getChild(extension_name) @@ -51,13 +51,16 @@ class Warn(commands.Cog): embed.add_field(name="add ", value="Send a warn to a user", inline=False) embed.add_field(name="remove ", value="Remove a number of warn to a user", inline=False) embed.add_field(name="purge ", value="Remove all warn of a user", inline=False) - embed.add_field(name="list [user]", value="List warn of the guild or a specified user", inline=False) + embed.add_field(name="list [user#discriminator|actions]", value="List warn of the guild or a specified user\n" + "If you specify `actions` instead of a user, " + "all the actions of the guild will be listed", + inline=False) embed.add_field(name="action ", value="Set an action for a count of warn\n" "Actions: `mute