How to use the cogs.utils.time.human_timedelta function in Cogs

To help you get started, we’ve selected a few Cogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Rapptz / RoboDanny / cogs / splatoon.py View on Github external
async def paginated_splatoon2_schedule(self, ctx, mode):
        try:
            data = self.sp2_map_data[mode]
        except KeyError:
            return await ctx.send('Sorry, no map data found...')

        entries = [
            (f'Now: {r.mode}' if r.current else f'In {time.human_timedelta(r.start_time)}: {r.mode}',
            f'{r.stage_a} and {r.stage_b}')
            for r in data
        ]

        try:
            p = FieldPages(ctx, entries=entries, per_page=4)
            p.embed.colour = 0xF02D7D
            await p.paginate()
        except Exception as e:
            await ctx.send(e)
github Rapptz / RoboDanny / cogs / meta.py View on Github external
def format_date(dt):
            if dt is None:
                return 'N/A'
            return f'{dt:%Y-%m-%d %H:%M} ({time.human_timedelta(dt, accuracy=3)})'
github techwithtim / Discord-Bot / cogs / commands.py View on Github external
async def reps_(self, ctx, member: typing.Optional[commands.MemberConverter]):
        """How many reps do you have?"""
        member = member or ctx.author
        user = await self.bot.db.get_user(member.id, get_reps=True)

        reps = len(user.reps)
        ret = f'{member.display_name} has received `{reps}` reps'
        if reps > 0:
            last_rep = max(user.reps, key=lambda r: r.repped_at)
            ret += f'\nLast rep: {human_timedelta(last_rep.repped_at)}'

        await ctx.send(ret)
github Rapptz / RoboDanny / cogs / stats.py View on Github external
def get_bot_uptime(self, *, brief=False):
        return time.human_timedelta(self.bot.uptime, accuracy=None, brief=brief, suffix=False)
github Rapptz / RoboDanny / cogs / reminder.py View on Github external
def human_delta(self):
        return time.human_timedelta(self.created_at)
github Rapptz / RoboDanny / cogs / splatoon.py View on Github external
def prepare_embed(self, salmon, page, *, first=False):
        self.embed = e = discord.Embed(colour=0xFF7500, title='Salmon Run')

        if salmon.image:
            e.set_image(url=salmon.image)

        now = datetime.datetime.utcnow()
        if now <= salmon.start_time:
            e.set_footer(text='Starts').timestamp = salmon.start_time
            e.description = f'Starts in {time.human_timedelta(salmon.start_time)}'
        elif now <= salmon.end_time:
            e.set_footer(text='Ends').timestamp = salmon.end_time
            e.description = f'Ends in {time.human_timedelta(salmon.end_time)}'

        e.add_field(name='Weapons', value='\n'.join(salmon.weapons) or 'Unknown')
        e.add_field(name='Map', value=salmon.stage or 'Unknown')

        if self.maximum_pages > 1:
            e.title = f'Salmon Run {page} out of {self.maximum_pages}'
github Rapptz / RoboDanny / cogs / reminder.py View on Github external
records = await ctx.db.fetch(query, str(ctx.author.id))

        if len(records) == 0:
            return await ctx.send('No currently running reminders.')

        e = discord.Embed(colour=discord.Colour.blurple(), title='Reminders')

        if len(records) == 10:
            e.set_footer(text='Only showing up to 10 reminders.')
        else:
            e.set_footer(text=f'{len(records)} reminder{"s" if len(records) > 1 else ""}')

        for _id, expires, message in records:
            shorten = textwrap.shorten(message, width=512)
            e.add_field(name=f'{_id}: In {time.human_timedelta(expires)}', value=shorten, inline=False)

        await ctx.send(embed=e)