Exemple #1
0
    async def silence(self,
                      ctx: Context,
                      duration: HushDurationConverter = 10) -> None:
        """
        Silence the current channel for `duration` minutes or `forever`.

        Duration is capped at 15 minutes, passing forever makes the silence indefinite.
        Indefinitely silenced channels get added to a notifier which posts notices every 15 minutes from the start.
        """
        await self._get_instance_vars_event.wait()
        log.debug(f"{ctx.author} is silencing channel #{ctx.channel}.")
        if not await self._silence(
                ctx.channel, persistent=(duration is None), duration=duration):
            await ctx.send(
                f"{Emojis.cross_mark} current channel is already silenced.")
            return
        if duration is None:
            await ctx.send(
                f"{Emojis.check_mark} silenced current channel indefinitely.")
            return

        await ctx.send(
            f"{Emojis.check_mark} silenced current channel for {duration} minute(s)."
        )

        self.scheduler.schedule_later(duration * 60, ctx.channel.id,
                                      ctx.invoke(self.unsilence))
Exemple #2
0
    async def lock(self,
                   ctx: Context = None,
                   duration: t.Optional[Duration] = None,
                   *,
                   reason: t.Optional[str]) -> None:
        """
        Disallow everyones permission to talk in this channel
        for given `duration` or indefinitely.
        """
        logger.debug(f"Channel #{ctx.channel} was silenced by {ctx.author}.")

        if not await self._lock(ctx.channel):
            await ctx.send(":x: This channel is already locked.")
            return

        reason = "No reason specified" if not reason else reason

        if not duration:
            await ctx.send(f"🔒 Channel locked indefinitely: {reason}.")
            return

        await ctx.send(
            f"🔒 Channel locked for {stringify_reldelta(relativedelta(seconds=duration))}: {reason}."
        )
        self.timer.delay(duration, ctx.channel.id, ctx.invoke(self.unlock))
Exemple #3
0
 async def _schedule_unsilence(self, ctx: Context,
                               duration: Optional[int]) -> None:
     """Schedule `ctx.channel` to be unsilenced if `duration` is not None."""
     if duration is None:
         await self.unsilence_timestamps.set(ctx.channel.id, -1)
     else:
         self.scheduler.schedule_later(duration * 60, ctx.channel.id,
                                       ctx.invoke(self.unsilence))
         unsilence_time = datetime.now(tz=timezone.utc) + timedelta(
             minutes=duration)
         await self.unsilence_timestamps.set(ctx.channel.id,
                                             unsilence_time.timestamp())
Exemple #4
0
 async def start_(self,ctx: commands.Context,arg):
     if ctx.author.id in self.active_users: ctx.invoke(self.stop_)
     try:
         gid = int(arg)
     except:
         embed = utility.Embed(None,"That isn't a valid server ID!")
         await ctx.send(embed=embed)
         return
     try:
         guild = self.bot.get_guild(gid) or await self.bot.fetch_guild(gid)
         member = guild.get_member(ctx.author.id) or await guild.fetch_member(ctx.author.id)
     except discord.Forbidden:
         embed = utility.Embed(None,"I couldn't find that server, are you sure I'm in it?")
         await ctx.send(embed=embed)
         return
     except:
         raise
     embed = utility.Embed("Monitoring your messages","Will go until you run `..stop` or 10 minutes of silence, use `..continue` to refresh timer")
     await ctx.send(embed=embed)
     event = asyncio.Event()
     self.active_users[ctx.author.id] = { "id":gid, "timer": asyncio.create_task(self.timer(event)), "event": event } 
     if len(self.active_users) == 1:
         self.bot.add_listener(self.monitor, "on_message")
     asyncio.create_task(self.wait_to_stop(ctx, event))
Exemple #5
0
    async def lock(self,
                   ctx: Context,
                   duration: t.Optional[Duration] = None,
                   *,
                   reason: t.Optional[str]) -> None:
        """
        Disallow everyones permission to talk in this channel
        for given `duration` or indefinitely.
        """
        if duration is None:
            duration = float("inf")

        max_duration = await Permissions.get_permission_from_member(
            self.bot.db_engine, self.bot, "lock", ctx.guild, ctx.author)
        if duration > max_duration:
            raise MissingPermissions(["sufficient_locktime"])

        logger.debug(f"Channel #{ctx.channel} was silenced by {ctx.author}.")

        status = await self._lock(ctx.channel)
        if status == 0:
            await ctx.send(":x: This channel is already locked.")
            return
        elif status == -1:
            await ctx.send(
                ":x: This channel was already locked manually using channel permissions."
            )
            return

        reason = "No reason specified" if not reason else reason

        if duration == float("inf"):
            await ctx.send(f"🔒 Channel locked indefinitely: {reason}.")
            return

        await ctx.send(
            f"🔒 Channel locked for {stringify_duration(duration)}: {reason}.")
        self.timer.delay(duration, ctx.channel.id, ctx.invoke(self.unlock))
Exemple #6
0
    async def lock(self,
                   ctx: Context,
                   duration: t.Optional[Duration] = None,
                   *,
                   reason: t.Optional[str]) -> None:
        """
        Disallow everyones permission to talk in this channel
        for given `duration` or indefinitely.
        """
        if duration == float("inf"):
            duration = None

        max_duration = await self.permissions_db.get_locktime(
            ctx.guild, ctx.author)

        if any([
                not duration and max_duration != -1, duration
                and max_duration != -1 and duration > max_duration
        ]):
            raise MissingPermissions(["sufficient_locktime"])

        logger.debug(f"Channel #{ctx.channel} was silenced by {ctx.author}.")

        if not await self._lock(ctx.channel):
            await ctx.send(":x: This channel is already locked.")
            return

        reason = "No reason specified" if not reason else reason

        if not duration:
            await ctx.send(f"🔒 Channel locked indefinitely: {reason}.")
            return

        await ctx.send(
            f"🔒 Channel locked for {stringify_duration(duration)}: {reason}."
        )
        self.timer.delay(duration, ctx.channel.id, ctx.invoke(self.unlock))