コード例 #1
0
 def format_retry_after(retry_after):
     delta = timedelta(seconds=retry_after)
     hours, remainder = divmod(int(delta.total_seconds()), 3600)
     minutes, seconds = divmod(remainder, 60)
     days, hours = divmod(hours, 24)
     strings = []
     if days:
         # target = "time.days" if days > 1 else "time.day"
         # strings.append(f"{days} {_('common', target)}")
         string = "days" if days > 1 else "day"
         strings.append(f"{days} {string}")
     if hours:
         # target = "time.hours" if hours > 1 else "time.hour"
         # strings.append(f"{hours} {_('common', target)}")
         string = "hours" if hours > 1 else "hour"
         strings.append(f"{hours} {string}")
     if minutes:
         # target = "time.minutes" if minutes > 1 else "time.minute"
         # strings.append(f"{minutes} {_('common', target)}")
         string = "minutes" if minutes > 1 else "minute"
         strings.append(f"{minutes} {string}")
     if seconds:
         # target = "time.seconds" if seconds > 1 else "time.second"
         # strings.append(f"{seconds} {_('common', target)}")
         string = "seconds" if seconds > 1 else "second"
         strings.append(f"{seconds} {string}")
     if not strings:
         ms = int(round(delta.microseconds / 1000, 0))
         strings.append(f"{ms}ms")
     timestr = readable_list(strings)
     # TODO: Figure out when the best time to delete the message is
     delete_after = 0 if delta.total_seconds(
     ) > 10 else 1 if delta.total_seconds() < 1 else delta.total_seconds()
     # return _("errors", "on_cooldown", time=timestr)
     return f"You can try again in {timestr}!", delete_after
コード例 #2
0
ファイル: Social.py プロジェクト: hartl3y94/Naila.py
 def process_users(ctx: Context, users):
     users = [x for x in users if not isinstance(x, str)]
     if not users:
         raise commands.MissingRequiredArgument(ctx.command.params["users"])
     users = [x.mention for x in list(set(users)) if x is not ctx.author]
     if len(users) > 5:
         raise commands.BadArgument("You provided too many users!")
     if not users:
         raise errors.UsedOnSelf
     word = "was" if len(users) == 1 else "were"
     users = readable_list(users)
     return users, word
コード例 #3
0
ファイル: errors.py プロジェクト: hartl3y94/Naila.py
    def __init__(self, missing_perms, *args):
        # from utils.ctx import CustomContext
        # _ = CustomContext.translator
        self.missing_perms = missing_perms

        # missing = [_("permissions", perm) for perm in missing_perms]
        missing = [
            perm.replace("guild", "server").title() for perm in missing_perms
        ]

        permissions = readable_list(missing)
        # message = _("errors", "bot_missing_perms", permissions=permissions)
        message = f"I need the `{permissions}` permissions for this command to work!"
        super().__init__(message, *args)
コード例 #4
0
def get_relative_delta(time,
                       append_days: bool = False,
                       append_long: bool = False,
                       append_small: bool = False,
                       append_seconds: bool = True,
                       bold_string: bool = False):
    past = False
    delta = relativedelta(time, datetime.utcnow())
    if datetime.utcnow() > time:
        past = True
        delta = relativedelta(datetime.utcnow(), time)
    tme = []
    msg = time.strftime("%A, %B %d %Y @ %I:%M%p %Z") if append_long else ""
    if delta.years:
        years = delta.years
        tme.append(f"{years} years" if years != 1 else "1 year")
    if delta.months:
        months = delta.months
        tme.append(f"{months} months" if months != 1 else "1 month")
    if delta.days:
        days = delta.days
        tme.append(f"{days} days" if days != 1 else "1 day")
    if not tme or append_small:
        if not tme:
            append_days = False
        if delta.hours:
            hours = delta.hours
            tme.append(f"{hours} hours" if hours != 1 else "1 hour")
        if delta.minutes:
            minutes = delta.minutes
            tme.append(f"{minutes} minutes" if minutes != 1 else "1 minute")
        if delta.seconds and append_seconds:
            seconds = delta.seconds
            tme.append(f"{seconds} seconds" if seconds != 1 else "1 second")
    fixed = readable_list(tme)
    msg += "in " if not past else ""
    msg += "\n" if append_long else ""
    msg += bold(fixed) if bold_string else fixed
    msg += " ago" if past else ""
    if append_days and len(tme) != 1 and "days" not in tme[0]:
        msg += f" ({(datetime.utcnow() - time).days} days)"
    return msg