Exemple #1
0
    async def mute(
        self,
        ctx: commands.Context,
        member: discord.Member,
        *,
        time: UserFriendlyTime(default='No reason', assume_reason=True) = None
    ) -> None:
        """Mutes a user"""
        if get_perm_level(member, await self.bot.db.get_guild_config(
                ctx.guild.id))[0] >= get_perm_level(
                    ctx.author, await self.bot.db.get_guild_config(ctx.guild.id
                                                                   ))[0]:
            await ctx.send('User has insufficient permissions')
        else:
            duration = None
            reason = None
            if not time:
                duration = None
            else:
                if time.dt:
                    duration = time.dt - ctx.message.created_at
                if time.arg:
                    reason = time.arg
            await self.alert_user(ctx,
                                  member,
                                  reason,
                                  duration=format_timedelta(duration))
            await self.bot.mute(ctx.author, member, duration, reason=reason)

            if ctx.author != ctx.guild.me:
                await ctx.send(self.bot.accept)
Exemple #2
0
    async def slowmode(self, ctx: commands.Context, *, time: UserFriendlyTime(converter=commands.TextChannelConverter, default=False, assume_reason=True)) -> None:
        """Enables slowmode, max 6h

        Examples:
        !!slowmode 2h
        !!slowmode 2h #general
        !!slowmode off
        !!slowmode 0s #general
        """
        duration = timedelta()
        channel = ctx.channel
        if time.dt:
            duration = time.dt - ctx.message.created_at
        if time.arg:
            if isinstance(time.arg, str):
                try:
                    channel = await commands.TextChannelConverter().convert(ctx, time.arg)
                except commands.BadArgument:
                    if time.arg != 'off':
                        raise
            else:
                channel = time.arg

        seconds = int(duration.total_seconds())

        if seconds > 21600:
            await ctx.send('Slowmode only supports up to 6h max at the moment')
        else:
            fmt = format_timedelta(duration, assume_forever=False)
            await channel.edit(slowmode_delay=int(duration.total_seconds()))
            await self.send_log(ctx, channel, fmt)
            if duration.total_seconds():
                await ctx.send(f'Enabled `{fmt}` slowmode on {channel.mention}')
            else:
                await ctx.send(f'Disabled slowmode on {channel.mention}')
Exemple #3
0
        async def timestamp(created):
            delta = format_timedelta(ctx.message.created_at - created)
            guild_config = await self.bot.db.get_guild_config(ctx.guild.id)
            created += timedelta(hours=guild_config.time_offset)

            return f"{delta} ago ({created.strftime('%H:%M:%S')})"