Exemple #1
0
    async def age(self, ctx, *, timespec: str = None):
        """
        Set the maximum age of non-art posts
        """
        channel = ctx.message.channel

        if not timespec:
            sec = self.settings_for(channel)["EXPIRATION"]
            await self.bot.say("Current maximum age is %s." % _generate_timespec(sec))
        else:
            try:
                sec = _parse_time(timespec)
            except BadTimeExpr as e:
                await self.bot.say(error(e.args[0]))
                return

            if sec >= (14 * 24 * 60 * 60):
                await self.bot.say(error(
                    "Discord limits bulk deletes to messages posted within two weeks. "
                    "Please choose a maximum age shorter than that."
                ))
                return

            self.update_setting(channel, "EXPIRATION", sec)
            msg = "Maximum post age set to %s." % _generate_timespec(sec)

            if sec < POLL_INTERVAL:
                poll_spec = _generate_timespec(POLL_INTERVAL)
                msg += "\n\n" + warning("Note: this cog only checks message history every %s." % poll_spec)

            await self.bot.say(msg)
Exemple #2
0
    async def age(self, ctx, *, timespec: str = None):
        """Set the maximum age of non-art posts"""
        channel = ctx.message.channel
        if not timespec:
            sec = self.settings_for(channel)['EXPIRATION']
            await self.bot.say('Current maximum age is %s.' %
                               _generate_timespec(sec))
        else:
            try:
                sec = _parse_time(timespec)
            except BadTimeExpr as e:
                await self.bot.say(error(e.args[0]))
                return

            self.update_setting(channel, 'EXPIRATION', sec)
            await self.bot.say('Maximum post age set to %s.' %
                               _generate_timespec(sec))
Exemple #3
0
    async def _add_centralized(self,
                               ctx,
                               name,
                               interval,
                               command,
                               repeat,
                               start=None,
                               start_in=None):
        channel = ctx.message.channel
        server = ctx.message.server
        author = ctx.message.author
        name = name.lower()
        now = datetime.now(tz=timezone.utc)

        min_time = 30 if repeat else 5

        prefix = await self.get_prefix(ctx.message)
        command = command.lstrip(prefix)

        try:
            interval = _parse_time(interval)
        except BadTimeExpr as e:
            await self.bot.say(error(e.args[0]))
            return

        if start_in:
            try:
                start_in = _parse_time(start_in)
            except BadTimeExpr as e:
                await self.bot.say(error(e.args[0]))
                return
            start = now + timedelta(seconds=start_in)
        elif start:
            try:
                start = self._get_start(start, now)
            except ValueError:
                await self.bot.say(error('Invalid timestamp format!'))
                return
        else:
            start = now

        if interval < min_time:
            await self.bot.say("I'm sorry, {}, I can't let you do that. "
                               "Your time interval is waaaay too short and "
                               "I'll likely get rate limited. Try going above"
                               " {} seconds.".format(author.name, min_time))
            return
        elif name in self.events.get(server.id, {}):
            if repeat:
                msg = warning("An event with that name already exists!")
            else:
                msg = warning("That command is already scheduled to run!")
            await self.bot.say(msg)
            return

        if repeat:
            logmsg = 'add {} "{}" to {} on {} every {}s starting {}'
            msg = '"{}" will run `{}` every {}, starting at {} ({}).'
        else:
            logmsg = 'add {} "{}" to {} on {} in {}s'
            msg = 'I will run `{1}` in {2}.'

        log.info(
            logmsg.format(name, command, channel.name, server.name, interval,
                          start.timestamp()))

        await self._add_event(name, command, server, channel, author, interval,
                              repeat, start)

        timeexpr = _generate_timespec(interval)

        delta = self._format_start(start, now)

        msg = msg.format(name, command, timeexpr, start, delta)
        await self.bot.say(msg)
    async def _add_centralized(self, ctx, name, interval, command, repeat, start=None, start_in=None):
        channel = ctx.message.channel
        server = ctx.message.server
        author = ctx.message.author
        name = name.lower()
        now = datetime.now(tz=timezone.utc)

        min_time = 30 if repeat else 5

        prefix = await self.get_prefix(ctx.message)
        command = command.lstrip(prefix)

        try:
            interval = _parse_time(interval)
        except BadTimeExpr as e:
            await self.bot.say(error(e.args[0]))
            return

        if start_in:
            try:
                start_in = _parse_time(start_in)
            except BadTimeExpr as e:
                await self.bot.say(error(e.args[0]))
                return
            start = now + timedelta(seconds=start_in)
        elif start:
            try:
                start = self._get_start(start, now)
            except ValueError:
                await self.bot.say(error('Invalid timestamp format!'))
                return
        else:
            start = now

        if interval < min_time:
            await self.bot.say("I'm sorry, {}, I can't let you do that. "
                               "Your time interval is waaaay too short and "
                               "I'll likely get rate limited. Try going above"
                               " {} seconds.".format(author.name, min_time))
            return
        elif name in self.events.get(server.id, {}):
            if repeat:
                msg = warning("An event with that name already exists!")
            else:
                msg = warning("That command is already scheduled to run!")

            await self.bot.say(msg)
            return

        if repeat:
            logmsg = 'add {} "{}" to {} on {} every {}s starting {}'
            msg = '"{}" will run `{}` every {}, starting at {} ({}).'
        else:
            logmsg = 'add {} "{}" to {} on {} in {}s'
            msg = 'I will run `{1}` in {2}.'

        log.info(logmsg.format(name, command, channel.name, server.name, interval, start.timestamp()))

        await self._add_event(name, command, server, channel, author, interval, repeat, start)

        timeexpr = _generate_timespec(interval)

        delta = self._format_start(start, now)

        msg = msg.format(name, command, timeexpr, start, delta)
        await self.bot.say(msg)