Example #1
0
 public PersistentReminder AddReminder(PersistentReminder reminder)
 {
     reminder.ReminderNumber = PersistentReminders.Any() ? PersistentReminders.Where(x => x.Reminder.UserId == reminder.UserId).Max(x => x.Reminder.ReminderNumber) + 1 : 1;
     PersistentReminders.Add(MakeTimer(reminder));
     Database.Store(reminder, PersistentReminder.DocumentName(reminder.GuildId, reminder.UserId, reminder.ReminderNumber));
     return(reminder);
 }
Example #2
0
        public async Task DeleteDailyReminder(int reminderNumber)
        {
            var reminder = ReminderHandler.Database.Load <PersistentReminder>(PersistentReminder.DocumentName(Context.Guild.Id, Context.User.Id, reminderNumber));

            if (reminder == null)
            {
                await ReplyAsync("Invalid reminder number specified.");

                return;
            }

            ReminderHandler.RemoveReminder(reminder);
            await ReplyAsync("Reminder removed.");
        }
Example #3
0
        public void RemoveReminder(PersistentReminder reminder)
        {
            PersistentReminders = PersistentReminders.Where(x =>
            {
                if (x.Reminder.UserId == reminder.UserId && x.Reminder.ReminderNumber == reminder.ReminderNumber)
                {
                    x.Timer.Dispose();
                    return(false);
                }

                return(true);
            }).ToList();
            Database.Remove <PersistentReminder>(PersistentReminder.DocumentName(reminder.GuildId, reminder.UserId, reminder.ReminderNumber));
        }
Example #4
0
        public async Task SetGMTOffset(int reminderNumber, int offset)
        {
            var reminder = ReminderHandler.Database.Load <PersistentReminder>(PersistentReminder.DocumentName(Context.Guild.Id, Context.User.Id, reminderNumber));

            if (reminder == null)
            {
                await ReplyAsync("Invalid reminder number specified.");

                return;
            }

            reminder.GMTAdjustment = offset;

            var cachedReminder = ReminderHandler.PersistentReminders.FirstOrDefault(x => x.Reminder.UserId == Context.User.Id && x.Reminder.ReminderNumber == reminderNumber);

            cachedReminder.Reminder.GMTAdjustment = offset;
            cachedReminder.Timer.Dispose();
            cachedReminder.Timer = new Timer(x => ReminderHandler.ExecutePersistentReminder(cachedReminder.Reminder), null, ReminderHandler.GetTimerFirstRunTime(cachedReminder.Reminder), new TimeSpan(24, 0, 0));
            ReminderHandler.Database.Store(reminder, PersistentReminder.DocumentName(Context.Guild.Id, Context.User.Id, reminder.ReminderNumber));
            await ReplyAsync("Your GMT adjustment has been set for the specified reminder.");
        }