Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
async def remind(reminder: dict):
    """Execute one reminder"""
    # Check if the reminder is in the future
    if reminder["date"] - time.time() > 0:
        # Get the channel object to send the message
        channel = REMINDER_BOT.get_channel(reminder["channel"])
        # Wait until the reminder should go off
        await asyncio.sleep(reminder["date"] - time.time())
        # Send the reminder text in the channel
        await channel.send(
            embed=generate_embed("Reminder", reminder["reminder_text"]))
        # Remove the reminder
        database.remove_reminder(reminder)
    # Schedules a repeating eminder
    if reminder["repeating"]:
        # Calculate when the next remidner 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"],
        )
    # Remove a reminder that has passed
    else:
        database.remove_reminder(reminder)
Ejemplo n.º 6
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())
Ejemplo n.º 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"))
Ejemplo n.º 8
0
 def remove_from_list(self, r_id):
     for row in self.store:
         if row[0] == r_id:
             self.store.remove(row.iter)
             database.remove_reminder(r_id)
             break
Ejemplo n.º 9
0
 def job_message(self, r_id, title, msg):
     notification.notify_user(title, msg)
     self.remove_from_list(r_id)
     database.remove_reminder(r_id)
Ejemplo n.º 10
0
 def remove_from_list(self, r_id):
     for row in self.store:
         if row[0] == r_id:
             self.store.remove(row.iter)
             database.remove_reminder(r_id)
             break
Ejemplo n.º 11
0
 def job_message(self, r_id, title, msg):
     notification.notify_user(title, msg)
     self.remove_from_list(r_id)
     database.remove_reminder(r_id)