public async Task UnsuggestAsync(CommandContext context)
        {
            DbResult <IEnumerable <GuildMovieSuggestion> > suggestionsResult = await GetSuggestionsResult(context);

            if (!suggestionsResult.TryGetValue(out IEnumerable <GuildMovieSuggestion>?result))
            {
                await context.RespondAsync("Something went wrong while attempting to get the suggestions. Please contact the developer.");

                return;
            }

            if (!result.Any())
            {
                await context.RespondAsync("You do not have any suggestions to delete.");

                return;
            }

            List <GuildMovieSuggestion> suggestions   = result.ToList();
            InteractivityExtension      interactivity = context.Client.GetInteractivity();
            IEnumerable <Page>          pages         = GetGuildMovieSuggestionsPages(suggestions.ToList(), interactivity);

            CustomResult <int> waitResult = await context.WaitForMessageAndPaginateOnMsg(pages,
                                                                                         PaginationMessageFunction.CreateWaitForMessageWithIntInRange(context.User, context.Channel, 1, suggestions.Count + 1)
                                                                                         );

            if (waitResult.Cancelled)
            {
                await context.RespondAsync("Ok, I won't delete any suggestion. Please try again if so desired.");

                return;
            }

            if (waitResult.TimedOut)
            {
                await context.RespondAsync("You never gave me a valid input. Please try again if so desired.");

                return;
            }

            Reaction reaction = await interactivity.AddAndWaitForYesNoReaction(
                await context.Channel.SendMessageAsync($"You want me to do delete the suggestion `{suggestions[waitResult.Result - 1].Title}`?"),
                context.Member
                );

            if (reaction != Reaction.Yes)
            {
                await context.Channel.SendMessageAsync("Ok!");

                return;
            }

            GuildMovieSuggestion chosen = suggestions[waitResult.Result - 1];

            await this.mediator.Send(new GuildMovieSuggestions.Delete(chosen));

            await context.Channel.SendMessageAsync($"{context.Member.Mention}, I have deleted the suggestion `{suggestions[waitResult.Result - 1].Title}`");
        }
예제 #2
0
        /// <summary>
        /// Determine the number of votes that each movie got and then select the highest ranked movie.
        /// If there is a tie on more than one of the movies, message the movie night creator with an
        /// embed where they will break the tie.
        /// </summary>
        /// <param name="movieNightId">ID for the movie night in the data store</param>
        public async Task CalculateVotes(int movieNightId)
        {
            GuildMovieNight movieNight = await GetGuildMovieNightAsync(movieNightId);

            (DiscordClient client, DiscordGuild guild, DiscordChannel channel) = await this.GetCommonDiscordObjects(movieNight);

            DiscordMessage votingMessage = await channel.GetMessageAsync(movieNight.VotingMessageId ?? throw new Exception("Somehow, some way, the voting message id was null... something done f$*@ed up."));

            Dictionary <string, DiscordReaction> mostReactedReactions = GetMostReactedReactons(votingMessage);

            DiscordMember host = await guild.GetMemberAsync(movieNight.HostId);

            GuildMovieSuggestion winningSuggestion = await GetWinningSuggestion(client, guild, host, movieNight, mostReactedReactions);

            movieNight.WinningMovieImdbId = winningSuggestion.ImdbId;
            DbResult movieNightUpdateResult = await this.mediator.Send(new GuildMovieNights.Update(movieNight));

            if (!movieNightUpdateResult.Success)
            {
                throw new Exception("An error occurred in updating the movie night with the winning suggestion");
            }

            RecurringJobDto rJobDto = GetMovieNightStartRecurringJobInfo(movieNight);

            LocalDateTime ldt     = LocalDateTime.FromDateTime(rJobDto.NextExecution !.Value);
            DateTimeZone  hostDTZ = await GetUserDateTimeZone(movieNight.HostId);

            ZonedDateTime zdt = ldt.InUtc();

            zdt = zdt.WithZone(hostDTZ);

            OmdbMovie movieInfo = await this.omdbClient.GetByImdbIdAsync(winningSuggestion.ImdbId, omdbPlotOption : OmdbPlotOption.SHORT);

            DiscordEmbedBuilder announceWinnerEmbed = movieInfo.ToDiscordEmbedBuilder(true)
                                                      .WithAuthor(host.DisplayName, iconUrl: host.AvatarUrl);
            DiscordMessageBuilder announceWinnerMessage = new DiscordMessageBuilder()
                                                          .WithContent($"@everyone, here's what {host.Mention} is showing {zdt.ToString("MM/dd/yyyy hh:mm x", null)}")
                                                          .WithEmbed(announceWinnerEmbed.Build());

            await channel.SendMessageAsync(announceWinnerMessage);
        }
예제 #3
0
 public Delete(GuildMovieSuggestion movieSuggestion)
 {
     this.GuildMovieSuggestion = movieSuggestion;
 }