protected async override void ViewIsDisappearing(object sender, EventArgs e)
        {
            await ScheduleReminders();

            Settings.ReminderStorage = JsonConvert.SerializeObject(Reminders.ToList());

            base.ViewIsDisappearing(sender, e);
        }
Ejemplo n.º 2
0
        public void TimerEvent(object _)
        {
            //Don't allow multiple to run at the same time and generate possible race conditions
            if (TimerWait)
            {
                return;
            }

            TimerWait = true;

            //TODO: Check that bot is actually logged in before running
            try
            {
                foreach (var reminder in Reminders.ToList())
                {
                    if (reminder.TimeStamp + reminder.Length < DateTime.UtcNow)
                    {
                        if (!LocalManagementService.LastConfig.IsAcceptable(reminder.GuildId))
                        {
                            return;
                        }

                        var channel = Client.GetGuild(reminder.GuildId)?.GetTextChannel(reminder.ChannelId);
                        var user    = Client.GetUser(reminder.UserId);
                        if (user == null)
                        {
                            RemoveReminder(reminder);
                            continue;
                        }

                        if (channel == null)
                        {
                            //DM User if available.
                            var dmChannel = user.GetOrCreateDMChannelAsync().Result;
                            if (dmChannel != null)
                            {
                                //TODO: Pretty up the message
                                dmChannel.SendMessageAsync(reminder.ReminderMessage).ConfigureAwait(false);
                            }
                            RemoveReminder(reminder);
                            continue;
                        }

                        channel.SendMessageAsync($"{user.Mention}", false, new EmbedBuilder()
                        {
                            Description = $"{reminder.ReminderMessage}".FixLength(1024),
                            Color       = Color.Green
                        }.Build()).ConfigureAwait(false);
                        RemoveReminder(reminder);
                    }
                }
            }
            finally
            {
                TimerWait = false;
            }
        }
Ejemplo n.º 3
0
        void Search()
        {
            if (!string.IsNullOrWhiteSpace(SearchText))
            {
                TabSelectedChanged(TabIndex);

                var temp_Filtered_reminders = Reminders.ToList();

                Reminders = new ObservableCollection <RemindersModel>(temp_Filtered_reminders.Where((arg) => arg.Name.ToLower().Contains(SearchText.ToLower()) || arg.Content.ToLower().Contains(SearchText.ToLower())));
            }
            else
            {
                TabSelectedChanged(TabIndex);
            }
        }