예제 #1
0
        public async Task StartMovie(int movieNightId)
        {
            GuildMovieNight movieNight = await GetGuildMovieNightAsync(movieNightId);

            if (movieNight.WinningMovieImdbId == null)
            {
                throw new Exception("The Winning Movie IMDb ID was null at the point in time of the Start Movie.");
            }

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

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

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

            DiscordEmbedBuilder announceWinnerEmbed = movieInfo.ToDiscordEmbedBuilder()
                                                      .WithAuthor(host.DisplayName, iconUrl: host.AvatarUrl);
            DiscordMessageBuilder announceWinnerMessage = new DiscordMessageBuilder()
                                                          .WithContent($"@everyone, the movie below is starting now!")
                                                          .WithEmbed(announceWinnerEmbed.Build());

            await channel.SendMessageAsync(announceWinnerMessage);

            // Update movie suggestion with the time watched
            DbResult <GuildMovieSuggestion> getWinningMovieSuggestion = await this.mediator.Send(new GuildMovieSuggestions.GetMovieSuggestion(movieNight.WinningMovieImdbId, guild));

            if (!getWinningMovieSuggestion.TryGetValue(out GuildMovieSuggestion? winningMovieSuggestion))
            {
                return;
            }

            winningMovieSuggestion.InstantWatched = this.clock.GetCurrentInstant();
            await this.mediator.Send(new GuildMovieSuggestions.Update(winningMovieSuggestion));
        }
예제 #2
0
        private static List <Movie> FetchTopMovies(int offsetPage, int totalpageCount, TMDbClient client)
        {
            var totalCount    = 0;
            var currentPageNo = offsetPage + 1;
            var lastPageNo    = totalpageCount + offsetPage;
            //var lastPage = 1;
            var topMovies = new List <Movie>();

            while (currentPageNo <= lastPageNo)
            {
                var mvList      = client.GetMovieTopRatedListAsync(null, currentPageNo++);
                var currentPage = new List <Movie>();

                Console.WriteLine(String.Format("Fetching data of page no {0}", currentPageNo - 1));
                if (mvList.Result.Results.Count == 0)
                {
                    break;
                }
                foreach (var movie in mvList.Result.Results)
                {
                    totalCount++;
                    try
                    {
                        Console.WriteLine(string.Format("\t{0}. {1} Fetching data of movie {2}-{3}"
                                                        , totalCount,
                                                        DateTime.Now.ToString(),
                                                        movie.Title,
                                                        movie.ReleaseDate.HasValue ? movie.ReleaseDate.Value.Year.ToString() : "Unknown Year"));

                        var moveieDetails = client.GetMovieAsync(movie.Id,
                                                                 MovieMethods.AlternativeTitles |
                                                                 MovieMethods.Keywords |
                                                                 //MovieMethods.ReleaseDates |
                                                                 MovieMethods.Credits).Result;


                        OmdbMovie omdbData = null;
                        var       topMovie = ConvertToDbo(moveieDetails, omdbData);

                        currentPage.Add(topMovie);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(String.Format("Exception For movie {0}\n", movie.Title) + ex);
                    }
                }
                topMovies.AddRange(currentPage);
                var ctx = new DbContext();
                ctx.Movies.InsertManyAsync(currentPage);
                Console.WriteLine("Total Movies Saved {0}", totalCount);
            }
            return(topMovies);
        }
예제 #3
0
        private void FormSearch_Load(object sender, EventArgs e)
        {
            string omdbTitle = sNewTitle + "(" + sYear + ")";

            lblTitleNew.Text = sNewTitle;
            omdbNewMovie     = _omdbRepository.SearchOmdbMovie(sNewTitle, sYear);

            string sWriters = omdbNewMovie.Writer;

            sWriters = sWriters.Replace(", ", "\n");
            string sActors = omdbNewMovie.Actors;

            sActors = sActors.Replace(", ", "\n");

            pictureBoxNew.ImageLocation = omdbNewMovie.Poster;
            pictureBoxNew.SizeMode      = PictureBoxSizeMode.StretchImage;
            lblRatedNew.Text            = omdbNewMovie.Rated;
            lblRuntimeNew.Text          = omdbNewMovie.Runtime;
            lblGenreNew.Text            = omdbNewMovie.Genre;
            lblDirectorNew.Text         = omdbNewMovie.Director;
            lblWriterNew.Text           = sWriters;
            lblActorsNew.Text           = sActors;
            lblPlotNew.Text             = omdbNewMovie.Plot;
            lblReleasedNew.Text         = omdbNewMovie.Released;
            lblRuntime2New.Text         = omdbNewMovie.Runtime;
            labelGenre2New.Text         = omdbNewMovie.Genre;
            lblCountryNew.Text          = omdbNewMovie.Country;
            lblLanguageNew.Text         = omdbNewMovie.Language;
            lblAwardsNew.Text           = omdbNewMovie.Awards;
            lblBoxOfficeNew.Text        = omdbNewMovie.BoxOffice;
            lblProductionNew.Text       = omdbNewMovie.Production;
            lblTypeNew.Text             = omdbNewMovie.Type;
            lblDVDNew.Text        = omdbNewMovie.DVD;
            lblMetascoreNew.Text  = Convert.ToString(omdbNewMovie.Metascore);
            lblimdbRatingNew.Text = omdbNewMovie.imdbRating;
            lblimdbVotesNew.Text  = Convert.ToString(omdbNewMovie.imdbVotes);
            lblimdbIDNew.Text     = omdbNewMovie.imdbID;
            lblResponseNew.Text   = omdbNewMovie.Response;

            if (omdbNewMovie.Website != "N/A")
            {
                webBrowser.Url = new Uri(omdbNewMovie.Website);
            }
        }
예제 #4
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);
        }
예제 #5
0
        public static DiscordEmbedBuilder ToDiscordEmbedBuilder(this OmdbMovie movieInfo, bool largePoster = false)
        {
            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
                                          .WithTitle(movieInfo.Title)
                                          .WithDescription($"{movieInfo.Plot}\n[View on IMDb](https://imdb.com/title/{movieInfo.ImdbId}/)")
                                          .AddField("Rated", movieInfo.Rated?.ToQueryValue() ?? "Unknown", true)
                                          .AddField("Runtime", movieInfo.Runtime ?? "Unknown", true)
                                          .AddField("Language", movieInfo.Language ?? "Unknown", true)
                                          .AddField("Country", movieInfo.Country ?? "Unknown", true)
                                          .WithFooter("Details provided courtesy of OMDb");

            if (largePoster)
            {
                builder.WithImageUrl(movieInfo.Poster);
            }
            else
            {
                builder.WithThumbnail(movieInfo.Poster);
            }

            return(builder);
        }
예제 #6
0
파일: Searches.cs 프로젝트: snoww/roki
        public async Task Movie([Leftover] string query)
        {
            await Context.Channel.TriggerTypingAsync().ConfigureAwait(false);

            OmdbMovie movie = await Service.GetMovieDataAsync(query).ConfigureAwait(false);

            if (movie == null)
            {
                await Context.Channel.SendErrorAsync("No results found.").ConfigureAwait(false);

                return;
            }

            EmbedBuilder embed = new EmbedBuilder().WithDynamicColor(Context)
                                 .WithTitle(movie.Title)
                                 .WithUrl($"http://www.imdb.com/title/{movie.ImdbId}/")
                                 .WithDescription(movie.Plot.TrimTo(1000))
                                 .AddField("Rating", movie.ImdbRating, true)
                                 .AddField("Genre", movie.Genre, true)
                                 .AddField("Year", movie.Year, true)
                                 .WithImageUrl(movie.Poster);

            await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
        }
        private async Task <OmdbMovie?> SelectMovieWithPaginatedEmbed(LazyOmdbList movieList, CommandContext context)
        {
            List <(OmdbMovie, DiscordEmbedBuilder)> omdbMovies = new();
            int currentIndex = 0;

            await context.RespondAsync(SELECT_MOVIE_TEXT);

            DiscordMessage msg = await context.Channel.SendMessageAsync($"{DiscordEmoji.FromGuildEmote(context.Client, 848012958851399710)} {Formatter.Bold(context.Guild.CurrentMember.DisplayName)} is getting your search results");

            _ = Task.Run(AddPaginationEmojis(msg));

            InteractivityExtension interactivity = context.Client.GetInteractivity();
            bool selected = false;

            do
            {
                if (currentIndex == omdbMovies.Count)
                {
                    try
                    {
                        OmdbMovie newMovie = await this.omdbClient.GetByImdbIdAsync(movieList.CurrentItem().ImdbId, omdbPlotOption : OmdbPlotOption.SHORT);

                        omdbMovies.Add((newMovie, newMovie.ToDiscordEmbedBuilder()));
                    }
                    catch (JsonException e)
                    {
                        await this.bot.LogExceptions(e);

                        if (movieList.HasNext())
                        {
                            await movieList.MoveNext();

                            continue;
                        }
                        else
                        {
                            currentIndex -= 1;
                        }
                    }
                }

                await msg.ModifyAsync(content: string.Empty, embed : omdbMovies[currentIndex].Item2.Build());

                InteractivityResult <MessageReactionAddEventArgs> waitForReactionResult = await interactivity.WaitForReactionAsync(this.ReactionIsPaginationEmoji, msg, context.Member);

                if (waitForReactionResult.TimedOut)
                {
                    await context.RespondAsync("You idled for too long and this search has been cancelled.");

                    return(null);
                }

                await waitForReactionResult.Result.Message.DeleteReactionAsync(waitForReactionResult.Result.Emoji, context.Member);

                switch (waitForReactionResult.Result.Emoji.Name)
                {
                case "⏪":
                    currentIndex = 0;
                    break;

                case "⬅️":
                    currentIndex = await MoveLeft(movieList, currentIndex);

                    break;

                case "✅":
                    selected = true;
                    break;

                case "➡️":
                    currentIndex = await MoveRight(movieList, currentIndex);

                    break;

                case "⏹️":
                    await context.RespondAsync("Stopping the search.");

                    return(null);

                default:
                    await SendInvalidSelectionMessage(context);

                    break;
                }
            }while (!selected);

            return(omdbMovies[currentIndex].Item1);
        }
예제 #8
0
        public async Task GetByMovieTitleFeatureWithSpecifiedTitle(string imdbId, string title, OmdbPlotOption plotOption, OmdbMovie expected)
        {
            OmdbMovie result = await this._client.GetByMovieTitleAsync(title, omdbPlotOption : plotOption);

            Assert.AreEqual(expected, result, $"Expected: \n{expected.ToDetailedString()}\nActual: \n{result.ToDetailedString()}\n");
        }
예제 #9
0
        private static Movie ConvertToDbo(TMDbLib.Objects.Movies.Movie arg, OmdbMovie omdbData)
        {
            var movie = new Movie()
            {
                MovieId  = ObjectId.GenerateNewId(),
                TmdbData = new VendorMovieData()
                {
                    MovieId      = arg.Id.ToString(),
                    BackdropPath = arg.BackdropPath,
                    PosterPath   = arg.PosterPath,
                    Rating       = new Rating()
                    {
                        DataSourceName = "The Movie Database",
                        AveragePoint   = arg.VoteAverage,
                        FullPoint      = 10,
                        TotalVote      = arg.VoteCount
                    }
                },
                ImdbData = new VendorMovieData()
                {
                    MovieId = arg.ImdbId,
                },
                Credits          = arg.Credits,
                Adult            = arg.Adult,
                Budget           = arg.Budget,
                Homepage         = arg.Homepage,
                OriginalLanguage = arg.OriginalLanguage,
                OriginalTitle    = arg.OriginalTitle,
                Overview         = arg.Overview,
                ReleaseDate      = arg.ReleaseDate,
                Revenue          = arg.Revenue,
                Runtime          = arg.Runtime,
                Status           = arg.Status,
                Tagline          = arg.Tagline,
                Title            = arg.Title,
                Video            = arg.Video,
                Genres           = arg.Genres
            };

            if (omdbData != null)
            {
                movie.ImdbData.
                Rating = new Rating()
                {
                    AveragePoint   = double.Parse(omdbData.imdbRating),
                    DataSourceName = "Internet Movie Database",
                    FullPoint      = 10,
                    TotalVote      = int.Parse(omdbData.imdbVotes.Trim(','))
                };
                movie.Awards = omdbData.Awards;
            }

            if (arg.AlternativeTitles != null)
            {
                movie.AlternativeTitles = new List <AlternativeTitle>();
                foreach (var title in arg.AlternativeTitles.Titles)
                {
                    movie.AlternativeTitles.Add(ConvertToDbo(title));
                }
            }

            if (arg.Keywords != null)
            {
                movie.Keywords = new List <Keyword>();
                foreach (var keyword in arg.Keywords.Keywords)
                {
                    movie.Keywords.Add(ConvertToDbo(keyword));
                }
            }

            return(movie);
        }