async def stream(self, ctx: commands.Context, member: discord.Member, duration: Expiry = None) -> None: """ Temporarily grant streaming permissions to a member for a given duration. A unit of time should be appended to the duration. Units (∗case-sensitive): \u2003`y` - years \u2003`m` - months∗ \u2003`w` - weeks \u2003`d` - days \u2003`h` - hours \u2003`M` - minutes∗ \u2003`s` - seconds Alternatively, an ISO 8601 timestamp can be provided for the duration. """ log.trace( f"Attempting to give temporary streaming permission to {member} ({member.id})." ) if duration is None: # Use default duration and convert back to datetime as Embed.timestamp doesn't support Arrow duration = arrow.utcnow() + timedelta( minutes=VideoPermission.default_permission_duration) duration = duration.datetime elif duration.tzinfo is None: # Make duration tz-aware. # ISODateTime could already include tzinfo, this check is so it isn't overwritten. duration.replace(tzinfo=timezone.utc) # Check if the member already has streaming permission already_allowed = any(Roles.video == role.id for role in member.roles) if already_allowed: await ctx.send( f"{Emojis.cross_mark} {member.mention} can already stream.") log.debug( f"{member} ({member.id}) already has permission to stream.") return # Schedule task to remove streaming permission from Member and add it to task cache self.scheduler.schedule_at(duration, member.id, self._revoke_streaming_permission(member)) await self.task_cache.set(member.id, duration.timestamp()) await member.add_roles(discord.Object(Roles.video), reason="Temporary streaming access granted") await ctx.send( f"{Emojis.check_mark} {member.mention} can now stream until {discord_timestamp(duration)}." ) # Convert here for nicer logging revoke_time = format_infraction_with_duration(str(duration)) log.debug( f"Successfully gave {member} ({member.id}) permission to stream until {revoke_time}." )
async def off_command(self, ctx: Context, duration: Expiry) -> None: """ Temporarily removes the pingable moderators role for a set amount of time. A unit of time should be appended to the duration. Units (∗case-sensitive): \u2003`y` - years \u2003`m` - months∗ \u2003`w` - weeks \u2003`d` - days \u2003`h` - hours \u2003`M` - minutes∗ \u2003`s` - seconds Alternatively, an ISO 8601 timestamp can be provided for the duration. The duration cannot be longer than 30 days. """ delta = duration - arrow.utcnow() if delta > datetime.timedelta(days=30): await ctx.send( ":x: Cannot remove the role for longer than 30 days.") return mod = ctx.author until_date = duration.replace( microsecond=0).isoformat() # Looks noisy with microseconds. await mod.remove_roles(self.moderators_role, reason=f"Turned pings off until {until_date}.") await self.pings_off_mods.set(mod.id, duration.isoformat()) # Allow rescheduling the task without cancelling it separately via the `on` command. if mod.id in self._role_scheduler: self._role_scheduler.cancel(mod.id) self._role_scheduler.schedule_at(duration, mod.id, self.reapply_role(mod)) embed = Embed(timestamp=duration, colour=Colours.bright_green) embed.set_footer(text="Moderators role has been removed until", icon_url=Icons.green_checkmark) await ctx.send(embed=embed)
async def stream(self, ctx: commands.Context, user: discord.Member, duration: Expiry = None, *_) -> None: """ Temporarily grant streaming permissions to a user for a given duration. A unit of time should be appended to the duration. Units (∗case-sensitive): \u2003`y` - years \u2003`m` - months∗ \u2003`w` - weeks \u2003`d` - days \u2003`h` - hours \u2003`M` - minutes∗ \u2003`s` - seconds Alternatively, an ISO 8601 timestamp can be provided for the duration. """ # if duration is none then calculate default duration if duration is None: now = datetime.datetime.utcnow() duration = now + datetime.timedelta( minutes=VideoPermission.default_permission_duration) # Check if user already has streaming permission already_allowed = any(Roles.video == role.id for role in user.roles) if already_allowed: await ctx.send(f"{Emojis.cross_mark} This user can already stream." ) return # Schedule task to remove streaming permission from Member and add it to task cache self.scheduler.schedule_at(duration, user.id, self._remove_streaming_permission(user)) await self._add_to_redis_cache(user.id, duration.timestamp()) await user.add_roles(discord.Object(Roles.video), reason="Temporary streaming access granted") duration = format_infraction_with_duration(str(duration)) await ctx.send( f"{Emojis.check_mark} {user.mention} can now stream until {duration}." )