public async Task UnscheduleGuildEvent(CommandContext context)
        {
            using IBotAccessProvider provider = this.accessBuilder.Build();
            InteractivityExtension interactivity = context.Client.GetInteractivity();

            DiscordMessage msg = await context.RespondAsync(
                $":wave: Hi, {context.User.Mention}! You want to unschedule an event for your guild?");

            Reaction reaction = await interactivity.AddAndWaitForYesNoReaction(msg, context.User);

            if (reaction != Reaction.Yes)
            {
                return;
            }

            await context.Message.DeleteAsync();

            DateTimeZone memberTimeZone = this.timeZoneProvider[provider.GetUsersTimeZone(context.User.Id).TimeZoneId];

            List <GuildBackgroundJob> guildEventJobs = provider.GetAllAssociatedGuildBackgroundJobs(context.Guild.Id)
                                                       .Where(x => x.GuildJobType == GuildJobType.SCHEDULED_EVENT)
                                                       .OrderBy(x => x.ScheduledTime)
                                                       .ToList();

            DiscordEmbedBuilder removeEventEmbed = new DiscordEmbedBuilder()
                                                   .WithTitle("Select an event to unschedule by typing: <event number>")
                                                   .WithColor(context.Member.Color);

            CustomResult <int> result = await context.WaitForMessageAndPaginateOnMsg(
                GetScheduledEventsPages(guildEventJobs.Select(x => x.WithTimeZoneConvertedTo(memberTimeZone)), interactivity, removeEventEmbed),
                PaginationMessageFunction.CreateWaitForMessageWithIntInRange(context.User, context.Channel, 1, guildEventJobs.Count + 1),
                msg : msg);

            if (result.TimedOut || result.Cancelled)
            {
                DiscordMessage snark = await context.RespondAsync("You never gave me a valid input. Thanks for wasting my time. :triumph:");

                await Task.Delay(5000);

                await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> {
                    msg, snark
                });

                return;
            }

            GuildBackgroundJob job = guildEventJobs[result.Result - 1];

            msg = await msg.ModifyAsync($"{context.User.Mention}, are you sure you want to unschedule this event?", embed : null);

            reaction = await interactivity.AddAndWaitForYesNoReaction(msg, context.User);

            BackgroundJob.Delete(job.HangfireJobId);
            provider.DeleteGuildBackgroundJob(job);
            await msg.DeleteAllReactionsAsync();

            await msg.ModifyAsync("Ok, I've unscheduled that event!", embed : null);
        }
Exemple #2
0
 public Delete(GuildBackgroundJob job)
 {
     this.Job = job;
 }