Пример #1
0
    def run(self, m):
        input = get_input(m, ignore_reply=False)
        if not input:
            return self.bot.send_message(m,
                                         generate_command_help(
                                             self, m.content),
                                         extra={'format': 'HTML'})
            # return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={'format': 'HTML'})

        delay = first_word(input)
        if delay:
            delaytime = delay[:-1]
            unit = delay[-1:]
            if not is_int(delaytime) or is_int(unit) or not self.to_seconds(
                    delaytime, unit):
                return self.bot.send_message(
                    m, self.bot.trans.plugins.reminders.strings.wrongdelay)

        alarm = time() + self.to_seconds(delaytime, unit)

        text = all_but_first_word(input)
        if not text:
            return self.bot.send_message(
                m, self.bot.trans.plugins.reminders.strings.noreminder)

        reminder = DictObject(OrderedDict())
        reminder.id = '%s:%s' % (m.sender.id, time())
        reminder.alarm = alarm
        reminder.chat_id = m.conversation.id
        reminder.text = text
        reminder.first_name = m.sender.first_name
        if m.sender.username:
            reminder.username = m.sender.username

        self.bot.reminders = wait_until_received('reminders/' + self.bot.name)
        self.sort_reminders()
        self.bot.reminders['list'].append(reminder)
        self.sort_reminders()

        if unit == 's':
            delay = delay.replace('s', ' seconds')
        if unit == 'm':
            delay = delay.replace('m', ' minutes')
        if unit == 'h':
            delay = delay.replace('h', ' hours')
        if unit == 'd':
            delay = delay.replace('d', ' days')

        message = self.bot.trans.plugins.reminders.strings.added % (
            m.sender.first_name, delay, text)

        return self.bot.send_message(m, message, extra={'format': 'HTML'})
Пример #2
0
    def run(self, m):
        input = get_input(m, ignore_reply=False)
        if not input:
            return self.bot.send_message(
                m,
                self.bot.trans.errors.missing_parameter,
                extra={'format': 'HTML'})

        self.reminders.load_database()
        # Lists all pins #
        delay = first_word(input)
        if delay:
            delaytime = delay[:-1]
            unit = delay[-1:]
            if not is_int(delaytime) or is_int(unit):
                return self.bot.send_message(
                    m, self.bot.trans.plugins.reminders.strings.wrongdelay)

        alarm = time() + self.to_seconds(delaytime, unit)

        text = all_but_first_word(input)
        if not text:
            return self.bot.send_message(
                m, self.bot.trans.plugins.reminders.strings.noreminder)

        reminder = DictObject(OrderedDict())
        reminder.id = '%s:%s' % (m.sender.id, time())
        reminder.alarm = alarm
        reminder.chat_id = m.conversation.id
        reminder.text = text
        reminder.first_name = m.sender.first_name
        reminder.username = m.sender.username

        self.reminders.list.append(reminder)
        self.sort_reminders()
        self.reminders.store_database()

        if unit == 's':
            delay = delay.replace('s', ' segundos')
        if unit == 'm':
            delay = delay.replace('m', ' minutos')
        if unit == 'h':
            delay = delay.replace('h', ' horas')
        if unit == 'd':
            delay = delay.replace('d', ' días')

        message = self.bot.trans.plugins.reminders.strings.added % (
            m.sender.first_name, delay, text)

        return self.bot.send_message(m, message, extra={'format': 'HTML'})
Пример #3
0
    def run(self, m):
        input = get_input(m, ignore_reply=False)
        if not input:
            return self.bot.send_message(m, self.bot.trans.errors.missing_parameter, extra={"format": "HTML"})

        self.reminders.load_database()
        # Lists all pins #
        delay = first_word(input)
        if delay:
            delaytime = delay[:-1]
            unit = delay[-1:]
            if not is_int(delaytime) or is_int(unit):
                return self.bot.send_message(m, self.bot.trans.plugins.reminders.strings.wrongdelay)

        alarm = time() + self.to_seconds(delaytime, unit)

        text = all_but_first_word(input)
        if not text:
            return self.bot.send_message(m, self.bot.trans.plugins.reminders.strings.noreminder)

        reminder = DictObject(OrderedDict())
        reminder.id = "%s:%s" % (m.sender.id, time())
        reminder.alarm = alarm
        reminder.chat_id = m.conversation.id
        reminder.text = text
        reminder.first_name = m.sender.first_name
        reminder.username = m.sender.username

        self.reminders.list.append(reminder)
        self.sort_reminders()
        self.reminders.store_database()

        if unit == "s":
            delay = delay.replace("s", " seconds")
        if unit == "m":
            delay = delay.replace("m", " minutes")
        if unit == "h":
            delay = delay.replace("h", " hours")
        if unit == "d":
            delay = delay.replace("d", " days")

        message = self.bot.trans.plugins.reminders.strings.added % (m.sender.first_name, delay, text)

        return self.bot.send_message(m, message, extra={"format": "HTML"})