예제 #1
0
def try_parse_reminder(message):
    def split_reminder_when(text):
        time_phrases = [
            regex("(.*)(" + p + ".*)")
            for p in (" every ", " today", " tomorrow", " next ", " sunday",
                      " monday", " tuesday", " wednesday", " thursday",
                      " friday", "saturday", " at ", " on ", " in ")
        ]
        possible_whens = []  #(int, reminder, datetime) tuples

        for time_phrase in time_phrases:
            match = time_phrase.search(text)
            if match:
                reminder_text = match.group(1).strip()
                when_text = match.group(2).strip()
                when, repetition = try_parse_when(when_text,
                                                  user)  # may be None
                possible_whens.append(
                    (len(when_text), reminder_text, when, repetition))

        great_whens = filter(lambda w: w[2], possible_whens)
        if len(great_whens):
            _, reminder_text, when, repetition = max(great_whens,
                                                     key=lambda pair: pair[0])
        elif len(possible_whens):
            _, reminder_text, when, repetition = max(possible_whens,
                                                     key=lambda pair: pair[0])
        else:
            reminder_text = text
            repetition = None
            when = None
        return reminder_text, when, repetition

    # Order: "remind" <when> "to" <what>
    user = message.user()
    reminder_without_when = None
    reminder2 = regex("(?:remind me|remind us|reminder) (.*?) to (.*)")
    match = reminder2.search(message.text)
    if match:
        reminder_text = match.group(2)
        when, repetition = try_parse_when(match.group(1), user)
        if when:
            return Reminder(reminder_text, when, repetition, user.name,
                            message.conv_id, message.db)
        else:
            reminder_without_when = reminder_text

    # Order: "remind" <what> "to" <when>
    match = regex("(?:remind me|remind us|reminder) to (.*)").search(
        message.text)
    if match:
        reminder_text, when, repetition = split_reminder_when(match.group(1))
        return Reminder(reminder_text, when, repetition, user.name,
                        message.conv_id, message.db)

    if reminder_without_when:
        return Reminder(reminder_without_when, None, None, user.name,
                        message.conv_id, message.db)
    return None
예제 #2
0
    def set_reminder(self, interval, incremental_interval):
        reminder = Reminder(self.id,
                            self.user_id,
                            interval=interval,
                            incremental_interval=incremental_interval)

        reminder_id = reminder.write_or_update()
        self.reminder = reminder_id
        self.write_or_update()
예제 #3
0
파일: main.py 프로젝트: frankdai320/ABot
 def set_reminder(self, timestamp, message, user_id, add_to_db=True):
     user_id = str(user_id)
     reminder = Reminder(message, user_id, timestamp)
     self.reminder_sched.enterabs(timestamp, 1, reminders.remind,
                                  (reminder, ))
     if add_to_db:
         self.db['reminders'].insert(
             dict(time=timestamp, message=message, user_id=user_id))
예제 #4
0
 def get_all_reminders(self):
     reminders = []
     with sqlite3.connect(self.db) as c:
         c.row_factory = sqlite3.Row
         cur = c.cursor()
         cur.execute(
             '''select rowid, * from reminders where conv_id=?
                 and reminder_time>=?
                 and deleted=0
                 order by reminder_time''',
             (self.id, util.to_ts(util.now_utc())))
         for row in cur:
             reminders.append(Reminder.from_row(row, self.db))
     return reminders
예제 #5
0
    async def test_reminder_errors(self, mockNow, mockRandom, mockKeybaseSend):
        await self.message_test(
            "remind me to foo tomorrow",
            "Ok! I'll remind you to foo on Monday at 9:02 PM",
            mockKeybaseSend,
        )
        mockNow.return_value = mockNow.return_value + datetime.timedelta(
            days=1)
        mockKeybaseSend.side_effect = Exception("failure to send reminder")
        await bot.send_reminders(self.bot, self.config)
        rs = get_due_reminders(DB, error_limit=0)
        assert len(rs) == 0
        rs = get_due_reminders(DB, error_limit=1)
        assert len(rs) == 1
        id = rs[0].id
        # try more than error_limit (10) times
        for i in range(15):
            await bot.send_reminders(self.bot, self.config)

        r = Reminder.lookup(id, DB)
        assert r.errors == 11
예제 #6
0
def add_reminder(title: str):
    r = Reminder()
    r.title = title
    r.due_date = datetime.now()
    r.save()
예제 #7
0
 def get_reminder(self):
     if not self.reminder_id:
         return None
     return Reminder.lookup(self.reminder_id, self.db)
예제 #8
0
파일: __init__.py 프로젝트: vogth/chandler
def installParcel(parcel, oldVersion=None):
    view = parcel.itsView

    # Create our one collection of indexDefinition mappings; when each gets
    # created, its __init__ will add it to this collection automagically.
    AllIndexDefinitions.update(parcel, "allIndexDefinitions")
    Reference.update(parcel, "currentContact")

    MailPreferences.update(parcel, "MailPrefs")
    Reference.update(parcel, "currentMeEmailAddress")

    cur = Reference.update(parcel, "currentIncomingAccount")
    cur1 = Reference.update(parcel, "currentOutgoingAccount")

    if cur.item is None:
        cur.item = IMAPAccount(
            itsView=view,
            displayName=_(u"Incoming Mail"),
            replyToAddress=EmailAddress(itsView=view),
            password=password.Password(itsView=view),
        )

    if cur1.item is None:
        cur1.item = SMTPAccount(itsView=view, displayName=_(u"Outgoing Mail"), password=password.Password(itsView=view))

    trashCollection = ListCollection.update(parcel, "trashCollection", displayName=_(u"Trash"))

    notes = KindCollection.update(parcel, "noteCollection", kind=Note.getKind(view), recursive=True)

    mine = UnionCollection.update(parcel, "mine")

    # it would be nice to get rid of these intermediate fully-fledged
    # item collections, and replace them with lower level Set objects
    mineNotes = IntersectionCollection.update(parcel, "mineNotes", sources=[mine, notes])

    nonOccurrenceFilter = NonOccurrenceFilter(None, parcel)

    nonRecurringNotes = FilteredCollection.update(
        parcel,
        "nonRecurringNotes",
        source=mineNotes,
        filterMethod=(nonOccurrenceFilter, "isNonOccurrence"),
        filterAttributes=[EventStamp.occurrenceFor.name, EventStamp.modificationFor.name, EventStamp.occurrences.name],
    )
    nonRecurringNotes.addIndex("__adhoc__", "numeric")

    allContentItems = KindCollection.update(parcel, "allContentItems", kind=ContentItem.getKind(view), recursive=True)

    contentItems = FilteredCollection.update(
        parcel,
        "contentItems",
        source=allContentItems,
        filterMethod=(nonOccurrenceFilter, "isNotPureOccurrence"),
        filterAttributes=[EventStamp.occurrenceFor.name, EventStamp.modificationFor.name],
    )

    allReminders = KindCollection.update(parcel, "allReminders", kind=Reminder.getKind(view), recursive=True)

    allFutureReminders = FilteredCollection.update(
        parcel,
        "allFutureReminders",
        source=allReminders,
        filterMethod=(UnexpiredFilter(None, parcel), "notExpired"),
        filterAttributes=[UnexpiredFilter.findValuePair[0]],
    )

    allFutureReminders.addIndex(
        "reminderPoll",
        "method",
        method=(UnexpiredFilter(None, parcel), "compare"),
        monitor=[UnexpiredFilter.findValuePair[0]],
    )

    # the "All" / "My" collection
    allCollection = SmartCollection.update(
        parcel,
        "allCollection",
        displayName=_(u"Dashboard"),
        source=nonRecurringNotes,
        exclusions=trashCollection,
        trash=None,
    )
    # kludge to improve on bug 4144 (not a good long term fix but fine for 0.6)
    allCollection.addIndex("__adhoc__", "numeric")

    events = EventStamp.getCollection(view)
    eventComparator = EventComparator.update(parcel, "eventComparator")

    EventStamp.addIndex(
        events,
        "effectiveStart",
        "method",
        method=(eventComparator, "cmpStartTime"),
        monitor=(EventStamp.startTime, EventStamp.allDay, EventStamp.anyTime),
        kind=ContentItem.getKind(view),
    )
    EventStamp.addIndex(
        events,
        "effectiveEnd",
        "method",
        method=(eventComparator, "cmpEndTime"),
        monitor=(EventStamp.startTime, EventStamp.allDay, EventStamp.anyTime, EventStamp.duration),
        kind=ContentItem.getKind(view),
    )

    # floatingEvents need to be reindexed in effectiveStart and effectiveEnd
    # when the floating timezone changes
    filterAttributes = [entry[0] for entry in _FILTER_ATTRIBUTES]
    floatingEvents = FilteredCollection.update(
        parcel,
        "floatingEvents",
        source=events,
        filterMethod=(FloatingEventFilter(None, parcel), "isFloatingEvent"),
        filterAttributes=filterAttributes,
    )
    floatingEvents.addIndex("__adhoc__", "numeric")

    # UTCEvents need to be reindexed in effectiveStartNoTZ and effectiveEndNoTZ
    # when the floating timezone changes, because UTC events are treated
    # specially
    UTCEvents = FilteredCollection.update(
        parcel,
        "UTCEvents",
        source=events,
        filterMethod=(UTCEventFilter(None, parcel), "isUTCEvent"),
        filterAttributes=filterAttributes,
    )
    UTCEvents.addIndex("__adhoc__", "numeric")

    longEvents = FilteredCollection.update(
        parcel,
        "longEvents",
        source=events,
        filterMethod=(LongEventFilter(None, parcel), "isLongEvent"),
        filterAttributes=[EventStamp.duration.name],
    )
    longEvents.addIndex("effectiveStart", "subindex", superindex=(events, events.__collection__, "effectiveStart"))
    longEvents.addIndex("effectiveEnd", "subindex", superindex=(events, events.__collection__, "effectiveEnd"))

    filterAttributes = (EventStamp.rruleset.name, EventStamp.occurrences.name)
    masterFilter = "view.hasTrueValues(uuid, '%s', '%s')" % filterAttributes
    nonMasterFilter = "not " + masterFilter

    masterEvents = FilteredCollection.update(
        parcel, "masterEvents", source=events, filterExpression=masterFilter, filterAttributes=list(filterAttributes)
    )

    nonMasterEvents = FilteredCollection.update(
        parcel,
        "nonMasterEvents",
        source=events,
        filterExpression=nonMasterFilter,
        filterAttributes=list(filterAttributes),
    )

    MasterEventWatcher.update(parcel, "masterEventWatcher", targetCollection=masterEvents)

    EventStamp.addIndex(
        masterEvents,
        "recurrenceEnd",
        "method",
        method=(eventComparator, "cmpRecurEnd"),
        monitor=(EventStamp.recurrenceEnd,),
    )

    EventStamp.addIndex(
        masterEvents, "effectiveStart", "subindex", superindex=(events, events.__collection__, "effectiveStart")
    )

    locations = KindCollection.update(parcel, "locations", kind=Location.getKind(view), recursive=True)

    locations.addIndex("locationName", "value", attribute="displayName", nodefer=True)

    mailCollection = mail.MailStamp.getCollection(view)

    kind = mail.EmailAddress.getKind(view)
    emailAddressCollection = KindCollection.update(parcel, "emailAddressCollection", kind=kind, recursive=True)
    emailComparator = EmailComparator.update(parcel, "emailComparator")
    emailAddressCollection.addIndex(
        "emailAddress", "method", method=(emailComparator, "cmpAddress"), monitor="emailAddress", nodefer=True
    )
    emailAddressCollection.addIndex(
        "fullName", "method", method=(emailComparator, "cmpFullName"), monitor="fullName", nodefer=True
    )
    emailAddressCollection.addIndex(
        "both",
        "method",
        method=(emailComparator, "cmpBoth"),
        monitor=("emailAddress", "fullName"),
        nodefer=True,
        kind=kind,
    )

    # Contains all current me addresses (that is, referenced by an account)
    currentMeEmailAddresses = ListCollection.update(parcel, "currentMeEmailAddresses")

    currentMeEmailAddresses.addIndex(
        "emailAddress", "method", method=(emailComparator, "cmpAddress"), monitor="emailAddress"
    )

    # Contains all current and former me addresses
    meEmailAddressCollection = ListCollection.update(parcel, "meEmailAddressCollection")

    meEmailAddressCollection.addIndex(
        "emailAddress", "method", method=(emailComparator, "cmpAddress"), monitor="emailAddress"
    )

    inSource = ToMeFilter.makeCollection(parcel, "inSource", mailCollection)
    # this index must be added to shield from the duplicate
    # source (mailCollection) that is going to be in mine
    inSource.addIndex("__adhoc__", "numeric")

    # The "In" collection
    inCollection = SmartCollection.update(
        parcel, "inCollection", displayName=_(u"In"), source=inSource, trash=trashCollection, visible=True
    )
    mine.addSource(inCollection)

    outSource = FromMeFilter.makeCollection(parcel, "outSource", mailCollection)
    # this index must be added to shield from the duplicate
    # source (mailCollection) that is going to be in mine
    outSource.addIndex("__adhoc__", "numeric")

    # The "Out" collection
    outCollection = SmartCollection.update(
        parcel, "outCollection", displayName=_(u"Out"), visible=True, source=outSource, trash=trashCollection
    )
    mine.addSource(outCollection)

    allEventsCollection = IntersectionCollection.update(parcel, "allEventsCollection", sources=[allCollection, events])

    searchResultsUnfiltered = SmartCollection.update(parcel, "searchResultsUnfiltered", displayName=messages.UNTITLED)

    searchResults = DifferenceCollection.update(
        parcel, "searchResults", sources=[searchResultsUnfiltered, masterEvents], displayName=messages.UNTITLED
    )

    TriageStatusReminder.update(parcel, "triageStatusReminder")
    startup.Startup.update(parcel, "installWatchers", invoke=__name__ + ".installWatchers")

    tzInstallParcel(parcel)
예제 #9
0
def installParcel(parcel, oldVersion=None):
    view = parcel.itsView

    # Create our one collection of indexDefinition mappings; when each gets
    # created, its __init__ will add it to this collection automagically.
    AllIndexDefinitions.update(parcel, "allIndexDefinitions")
    Reference.update(parcel, 'currentContact')

    MailPreferences.update(parcel, 'MailPrefs')
    Reference.update(parcel, 'currentMeEmailAddress')

    cur = Reference.update(parcel, 'currentIncomingAccount')
    cur1 = Reference.update(parcel, 'currentOutgoingAccount')

    if cur.item is None:
        cur.item = IMAPAccount(itsView=view,
                               displayName=_(u'Incoming Mail'),
                               replyToAddress=EmailAddress(itsView=view),
                               password=password.Password(itsView=view))

    if cur1.item is None:
        cur1.item = SMTPAccount(
            itsView=view,
            displayName=_(u'Outgoing Mail'),
            password=password.Password(itsView=view),
        )

    trashCollection = ListCollection.update(parcel,
                                            'trashCollection',
                                            displayName=_(u"Trash"))

    notes = KindCollection.update(parcel,
                                  'noteCollection',
                                  kind=Note.getKind(view),
                                  recursive=True)

    mine = UnionCollection.update(parcel, 'mine')

    # it would be nice to get rid of these intermediate fully-fledged
    # item collections, and replace them with lower level Set objects
    mineNotes = IntersectionCollection.update(parcel,
                                              'mineNotes',
                                              sources=[mine, notes])

    nonOccurrenceFilter = NonOccurrenceFilter(None, parcel)

    nonRecurringNotes = FilteredCollection.update(
        parcel,
        'nonRecurringNotes',
        source=mineNotes,
        filterMethod=(nonOccurrenceFilter, 'isNonOccurrence'),
        filterAttributes=[
            EventStamp.occurrenceFor.name, EventStamp.modificationFor.name,
            EventStamp.occurrences.name
        ])
    nonRecurringNotes.addIndex('__adhoc__', 'numeric')

    allContentItems = KindCollection.update(parcel,
                                            'allContentItems',
                                            kind=ContentItem.getKind(view),
                                            recursive=True)

    contentItems = FilteredCollection.update(
        parcel,
        'contentItems',
        source=allContentItems,
        filterMethod=(nonOccurrenceFilter, 'isNotPureOccurrence'),
        filterAttributes=[
            EventStamp.occurrenceFor.name, EventStamp.modificationFor.name
        ])

    allReminders = KindCollection.update(parcel,
                                         'allReminders',
                                         kind=Reminder.getKind(view),
                                         recursive=True)

    allFutureReminders = FilteredCollection.update(
        parcel,
        'allFutureReminders',
        source=allReminders,
        filterMethod=(UnexpiredFilter(None, parcel), 'notExpired'),
        filterAttributes=[UnexpiredFilter.findValuePair[0]],
    )

    allFutureReminders.addIndex('reminderPoll',
                                'method',
                                method=(UnexpiredFilter(None,
                                                        parcel), 'compare'),
                                monitor=[UnexpiredFilter.findValuePair[0]])

    # the "All" / "My" collection
    allCollection = SmartCollection.update(
        parcel,
        'allCollection',
        displayName=_(u"Dashboard"),
        source=nonRecurringNotes,
        exclusions=trashCollection,
        trash=None,
    )
    # kludge to improve on bug 4144 (not a good long term fix but fine for 0.6)
    allCollection.addIndex('__adhoc__', 'numeric')

    events = EventStamp.getCollection(view)
    eventComparator = EventComparator.update(parcel, 'eventComparator')

    EventStamp.addIndex(events,
                        'effectiveStart',
                        'method',
                        method=(eventComparator, 'cmpStartTime'),
                        monitor=(EventStamp.startTime, EventStamp.allDay,
                                 EventStamp.anyTime),
                        kind=ContentItem.getKind(view))
    EventStamp.addIndex(events,
                        'effectiveEnd',
                        'method',
                        method=(eventComparator, 'cmpEndTime'),
                        monitor=(EventStamp.startTime, EventStamp.allDay,
                                 EventStamp.anyTime, EventStamp.duration),
                        kind=ContentItem.getKind(view))

    # floatingEvents need to be reindexed in effectiveStart and effectiveEnd
    # when the floating timezone changes
    filterAttributes = [entry[0] for entry in _FILTER_ATTRIBUTES]
    floatingEvents = FilteredCollection.update(
        parcel,
        'floatingEvents',
        source=events,
        filterMethod=(FloatingEventFilter(None, parcel), 'isFloatingEvent'),
        filterAttributes=filterAttributes)
    floatingEvents.addIndex('__adhoc__', 'numeric')

    # UTCEvents need to be reindexed in effectiveStartNoTZ and effectiveEndNoTZ
    # when the floating timezone changes, because UTC events are treated
    # specially
    UTCEvents = FilteredCollection.update(parcel,
                                          'UTCEvents',
                                          source=events,
                                          filterMethod=(UTCEventFilter(
                                              None, parcel), 'isUTCEvent'),
                                          filterAttributes=filterAttributes)
    UTCEvents.addIndex('__adhoc__', 'numeric')

    longEvents = FilteredCollection.update(
        parcel,
        'longEvents',
        source=events,
        filterMethod=(LongEventFilter(None, parcel), 'isLongEvent'),
        filterAttributes=[EventStamp.duration.name])
    longEvents.addIndex('effectiveStart',
                        'subindex',
                        superindex=(events, events.__collection__,
                                    'effectiveStart'))
    longEvents.addIndex('effectiveEnd',
                        'subindex',
                        superindex=(events, events.__collection__,
                                    'effectiveEnd'))

    filterAttributes = (EventStamp.rruleset.name, EventStamp.occurrences.name)
    masterFilter = "view.hasTrueValues(uuid, '%s', '%s')" % filterAttributes
    nonMasterFilter = "not " + masterFilter

    masterEvents = FilteredCollection.update(
        parcel,
        'masterEvents',
        source=events,
        filterExpression=masterFilter,
        filterAttributes=list(filterAttributes))

    nonMasterEvents = FilteredCollection.update(
        parcel,
        'nonMasterEvents',
        source=events,
        filterExpression=nonMasterFilter,
        filterAttributes=list(filterAttributes))

    MasterEventWatcher.update(parcel,
                              'masterEventWatcher',
                              targetCollection=masterEvents)

    EventStamp.addIndex(masterEvents,
                        "recurrenceEnd",
                        'method',
                        method=(eventComparator, 'cmpRecurEnd'),
                        monitor=(EventStamp.recurrenceEnd, ))

    EventStamp.addIndex(masterEvents,
                        'effectiveStart',
                        'subindex',
                        superindex=(events, events.__collection__,
                                    'effectiveStart'))

    locations = KindCollection.update(parcel,
                                      'locations',
                                      kind=Location.getKind(view),
                                      recursive=True)

    locations.addIndex('locationName',
                       'value',
                       attribute='displayName',
                       nodefer=True)

    mailCollection = mail.MailStamp.getCollection(view)

    kind = mail.EmailAddress.getKind(view)
    emailAddressCollection = \
        KindCollection.update(parcel, 'emailAddressCollection',
                              kind=kind,
                              recursive=True)
    emailComparator = EmailComparator.update(parcel, 'emailComparator')
    emailAddressCollection.addIndex('emailAddress',
                                    'method',
                                    method=(emailComparator, 'cmpAddress'),
                                    monitor='emailAddress',
                                    nodefer=True)
    emailAddressCollection.addIndex('fullName',
                                    'method',
                                    method=(emailComparator, 'cmpFullName'),
                                    monitor='fullName',
                                    nodefer=True)
    emailAddressCollection.addIndex('both',
                                    'method',
                                    method=(emailComparator, 'cmpBoth'),
                                    monitor=('emailAddress', 'fullName'),
                                    nodefer=True,
                                    kind=kind)

    # Contains all current me addresses (that is, referenced by an account)
    currentMeEmailAddresses = ListCollection.update(parcel,
                                                    'currentMeEmailAddresses')

    currentMeEmailAddresses.addIndex('emailAddress',
                                     'method',
                                     method=(emailComparator, 'cmpAddress'),
                                     monitor='emailAddress')

    # Contains all current and former me addresses
    meEmailAddressCollection = ListCollection.update(
        parcel, 'meEmailAddressCollection')

    meEmailAddressCollection.addIndex('emailAddress',
                                      'method',
                                      method=(emailComparator, 'cmpAddress'),
                                      monitor='emailAddress')

    inSource = ToMeFilter.makeCollection(parcel, 'inSource', mailCollection)
    # this index must be added to shield from the duplicate
    # source (mailCollection) that is going to be in mine
    inSource.addIndex('__adhoc__', 'numeric')

    # The "In" collection
    inCollection = SmartCollection.update(parcel,
                                          'inCollection',
                                          displayName=_(u"In"),
                                          source=inSource,
                                          trash=trashCollection,
                                          visible=True)
    mine.addSource(inCollection)

    outSource = FromMeFilter.makeCollection(parcel, 'outSource',
                                            mailCollection)
    # this index must be added to shield from the duplicate
    # source (mailCollection) that is going to be in mine
    outSource.addIndex('__adhoc__', 'numeric')

    # The "Out" collection
    outCollection = SmartCollection.update(
        parcel,
        'outCollection',
        displayName=_(u"Out"),
        visible=True,
        source=outSource,
        trash=trashCollection,
    )
    mine.addSource(outCollection)

    allEventsCollection = IntersectionCollection.update(
        parcel, 'allEventsCollection', sources=[allCollection, events])

    searchResultsUnfiltered = SmartCollection.update(
        parcel, 'searchResultsUnfiltered', displayName=messages.UNTITLED)

    searchResults = DifferenceCollection.update(
        parcel,
        'searchResults',
        sources=[searchResultsUnfiltered, masterEvents],
        displayName=messages.UNTITLED)

    TriageStatusReminder.update(parcel, 'triageStatusReminder')
    startup.Startup.update(parcel,
                           "installWatchers",
                           invoke=__name__ + ".installWatchers")

    tzInstallParcel(parcel)
예제 #10
0
def add_reminder(title: str):
  r = Reminder()
  r.title = title
  r.due_date = datetime.now()
  r.save()