Example #1
0
        public async Task DeleteAsync(CommandContext ctx,
                                      [Description("Channel for which to remove reminders.")] DiscordChannel channel = null)
        {
            if (!(channel is null) && channel.Type != ChannelType.Text)
            {
                throw new InvalidCommandUsageException("You must specify a text channel.");
            }

            if (!await ctx.WaitForBoolReplyAsync("Are you sure you want to remove all your reminders" + (channel is null ? "?" : $"in {channel.Mention}?")))
            {
                return;
            }

            List <DatabaseReminder> reminders;

            using (DatabaseContext db = this.Database.CreateContext()) {
                if (channel is null)
                {
                    reminders = await db.Reminders.Where(r => r.UserId == ctx.User.Id).ToListAsync();
                }
                else
                {
                    reminders = await db.Reminders.Where(r => r.UserId == ctx.User.Id && r.ChannelId == channel.Id).ToListAsync();
                }
            }

            await Task.WhenAll(reminders.Select(r => SavedTaskExecutor.UnscheduleAsync(this.Shared, ctx.User.Id, r.Id)));

            await this.InformAsync(ctx, "Successfully removed the specified reminders.", important : false);
        }
Example #2
0
        public async Task DeleteAsync(CommandContext ctx,
                                      [Description("Reminder ID.")] params int[] ids)
        {
            if (!ids.Any())
            {
                throw new InvalidCommandUsageException("Missing IDs of reminders to remove.");
            }

            if (!this.Shared.RemindExecuters.ContainsKey(ctx.User.Id))
            {
                throw new CommandFailedException("You have no reminders scheduled.");
            }

            var eb = new StringBuilder();

            foreach (int id in ids)
            {
                if (!this.Shared.RemindExecuters[ctx.User.Id].Any(texec => texec.Id == id))
                {
                    eb.AppendLine($"Reminder with ID {Formatter.Bold(id.ToString())} does not exist (or is not scheduled by you)!");
                    continue;
                }

                await SavedTaskExecutor.UnscheduleAsync(this.Shared, ctx.User.Id, id);
            }

            if (eb.Length > 0)
            {
                await this.InformFailureAsync(ctx, $"Action finished with following warnings/errors:\n\n{eb.ToString()}");
            }
            else
            {
                await this.InformAsync(ctx, "Successfully removed all specified reminders.", important : false);
            }
        }
Example #3
0
        public async Task DeleteAsync(CommandContext ctx,
                                      [Description("Reminder ID.")] params int[] ids)
        {
            if (ids is null || !ids.Any())
            {
                throw new InvalidCommandUsageException("Missing IDs of the reminders to remove");
            }

            if (!this.Shared.RemindExecuters.TryGetValue(ctx.User.Id, out ConcurrentDictionary <int, SavedTaskExecutor> texecs))
            {
                throw new CommandFailedException("You currently have no reminders schedule.");
            }

            var sb = new StringBuilder();

            foreach (int id in ids)
            {
                if (!texecs.TryGetValue(id, out _))
                {
                    sb.AppendLine($"Reminder with ID {Formatter.Bold(id.ToString())} does not exist (or it is not scheuled by you)!");
                    continue;
                }

                await SavedTaskExecutor.UnscheduleAsync(this.Shared, ctx.User.Id, id);
            }

            if (sb.Length > 0)
            {
                await this.InformOfFailureAsync(ctx, $"Action finished with the following warnings/errors:\n\n{sb.ToString()}");
            }
            else
            {
                await this.InformAsync(ctx, "Successfully removed all of the specified remidners.", important : false);
            }
        }