예제 #1
0
 async def search_reminders(self, ctx, date: Optional[str] = None):
     """Searches for reminders on a specific day"""
     if date:
         try:
             date = utils.split_date(date)
         except UnboundLocalError:
             await ctx.send(embed=utils.generate_embed(
                 "", "Date was not in the correct format."))
             return 1
         db_search = database.get_reminders(
             ctx.message.guild.id,
             **{
                 "year": date["year"],
                 "month": date["month"],
                 "day": date["day"]
             },
         )
     else:
         db_search = database.get_reminders(ctx.message.guild.id)
     message = ""
     for reminder in db_search:
         message += f'\n{reminder["reminder_id"]}\t{reminder["human_readable_time"]}\t{reminder["reminder_text"]}\n'
     if not message:
         message = "No reminders found"
     await ctx.send(
         embed=utils.generate_embed("Search Results:", f"```{message}```"))
예제 #2
0
async def send_reminders(get_dm_channel):
    rem_ids = []
    cur_time = datetime.now()
    reminders = database.get_reminders()
    for r in reminders:
        rem_time = datetime.strptime(r['rem_date'], "%b %d, %H:%M")
        rem_time = rem_time.replace(year=cur_time.year)
        if cur_time < rem_time:
            continue
        # Prepare message
        rem_str = ""
        if r['rem_type'] == 0:
            rem_str = "OVERDUE"
        elif r['rem_type'] == 1:
            rem_str = "Due in 1 day"
        rem_str += f": '{r['task_name']}', ID:{r['task_id']}"
        # Send reminder
        assigned_ids = [
            int(userid[2:-1]) for userid in r['assigned_to'].split(',')
        ]
        for uid in assigned_ids:
            dm_channel, backup_channel = await get_dm_channel(uid)
            try:
                await dm_channel.send(rem_str)
            except Forbidden:
                print(f"User {uid} has blocked DMs")
                rem_str = f"<@{uid}> {rem_str}"
                await backup_channel.send(rem_str)
        # Add to list of ids to remove
        rem_ids.append(r['rem_id'])
    # Remove reminders if sent
    database.remove_reminders(rem_ids)
예제 #3
0
 async def remind(self, reminder: dict):
     """Execute one reminder"""
     # Check if the reminder is in the future and if it exists in the database
     if reminder["date"] > time.time() and database.get_reminders(**reminder) != []:
         await asyncio.sleep(reminder["date"] - time.time())
         # Checks if the reminder is still exists, in case of deletion
         if database.get_reminders(**reminder) != [] and reminder in self.reminders:
             await self.bot.get_channel(reminder["channel"]).send(
                 f"Reminder:\n{reminder['reminder_text']}"
             )
             if reminder["repeating"] != False:
                 await self.schedule_repeat(reminder)
             self.reminders.remove(reminder)
         # Remove the reminder
         database.remove_reminder(reminder)
     # Remove a reminder that has passed
     else:
         database.remove_reminder(reminder)
예제 #4
0
async def setup_reminders():
    """Sets up the reminders"""
    # Stores all the reminder tasks
    tasks = []
    # Create tasks for all reminders, call the remind function
    for reminder in database.get_reminders():
        tasks.append(asyncio.create_task(remind(reminder)))
    # Run the tasks
    asyncio.gather(*tasks)
예제 #5
0
def update_reminders():
    """
    Called by scheduler every 10 seconds, to update reminders 
    :return:
        None
    """
    reminders = get_reminders()
    eel.updateReminders(' ', 1)
    for reminder in reminders:
        eel.updateReminders(reminder, 0)
예제 #6
0
 async def update_schedule(self):
     """Updates the schedule"""
     reminders = database.get_reminders()
     new_reminders = []
     for reminder in reminders:
         if reminder["date"] - time.time() < 0:
             database.remove_reminder(reminder)
         else:
             new_reminders.append(reminder)
         self.reminders.clear()
         self.reminders.extend(new_reminders)
예제 #7
0
async def delete_reminder(ctx, index: int):
    """Deletes a reminder at a specific index"""
    search_result = database.get_reminders(ctx.message.guild, **{"_id": index})
    if search_result != []:
        delete_result = database.remove_reminder(search_result[0])
        if delete_result:
            await ctx.send(embed=generate_embed(
                "Deleted Reminder", "The reminder was successfully removed"))
        else:
            await ctx.send(
                embed=generate_embed("Error", "Something went wrong"))
    else:
        await ctx.send(embed=generate_embed(
            "Error", "Could not find a reminder at this index"))
예제 #8
0
    def load_reminders(self):
        reminders = database.get_reminders()

        if len(reminders) <= 0:
            self.logger.info('No reminders were available to be scheduled')
            return

        for reminder in reminders:
            r_id = reminder[0]
            name = reminder[1]
            description = reminder[2]
            date_time = datetime.strptime(reminder[3], "%Y-%m-%d %H:%M:%S")
            date = str(date_time.date())
            time = str(date_time.time())
            if date_time > datetime.now():
                self.logger.info('Scheduling an existing reminder')
                self.store.append([r_id, name, description, date, time])
                self.add_job(r_id, name, description, date_time)
            else:
                self.logger.info('Removing an expired reminder')
                database.remove_reminder(r_id)
예제 #9
0
    def load_reminders(self):
        reminders = database.get_reminders()

        if len(reminders) <= 0:
            self.logger.info('No reminders were available to be scheduled')
            return

        for reminder in reminders:
            r_id = reminder[0]
            name = reminder[1]
            description = reminder[2]
            date_time = datetime.strptime(reminder[3], "%Y-%m-%d %H:%M:%S")
            date = str(date_time.date())
            time = str(date_time.time())
            if date_time > datetime.now():
                self.logger.info('Scheduling an existing reminder')
                self.store.append([r_id, name, description, date, time])
                self.add_job(r_id, name, description, date_time)
            else:
                self.logger.info('Removing an expired reminder')
                database.remove_reminder(r_id)
예제 #10
0
 async def schedule_repeat(self, reminder: dict):
     """Schedules a repeating reminder"""
     if reminder["repeating"] and database.get_reminders(**reminder) != []:
         # Calculate when the next reminder should be
         reminder_date = datetime.datetime.fromtimestamp(
             reminder["date"] + conversion_dict[reminder["repeating"]]
         )
         # Remove the old reminder
         database.remove_reminder(reminder)
         # Add the new reminder
         database.insert_reminder(
             reminder["guild"],
             reminder["channel"],
             reminder_date.year,
             reminder_date.month,
             reminder_date.day,
             reminder_date.hour,
             reminder_date.minute,
             reminder["reminder_text"],
             reminder["repeating"],
         )
         asyncio.create_task(self.setup_reminders())
예제 #11
0
def reminders():
    if "logged_in" not in session:
        return redirect(url_for("signIn"))
    reminders = db.get_reminders()
    return render_template("reminders.html", reminders=reminders)