Ejemplo n.º 1
0
 public GuildMovieNight(
     string votingStartHangfireId,
     string votingEndHangfireId,
     string movieNightStartHangfireId,
     int numberOfSuggestions,
     OmdbParentalRating maximumRating,
     ulong guildId,
     ulong announcementChannelId,
     ulong hostId)
 {
     this.VotingStartHangfireId     = votingStartHangfireId;
     this.VotingEndHangfireId       = votingEndHangfireId;
     this.MovieNightStartHangfireId = movieNightStartHangfireId;
     this.NumberOfSuggestions       = numberOfSuggestions;
     this.MaximumRating             = maximumRating;
     this.GuildId = guildId;
     this.AnnouncementChannelId = announcementChannelId;
     this.HostId = hostId;
 }
Ejemplo n.º 2
0
 public Add(string votingStartId, string votingEndId, string movieNightStartId, int numSuggestions, OmdbParentalRating maxRating, DiscordGuild guild, DiscordChannel announcementChannel, DiscordUser host) :
     this(votingStartId, votingEndId, movieNightStartId, numSuggestions, maxRating, guild.Id, announcementChannel.Id, host.Id)
 {
 }
Ejemplo n.º 3
0
 public Add(string votingStartId, string votingEndId, string movieNightStartId, int numSuggestions, OmdbParentalRating maxRating, ulong guildId, ulong announcementChannelId, ulong hostId)
 {
     this.MovieNight = new GuildMovieNight(votingStartId, votingEndId, movieNightStartId, numSuggestions, maxRating, guildId, announcementChannelId, hostId);
 }
Ejemplo n.º 4
0
 public Add(string imdbId, DiscordUser suggestor, string title, DiscordGuild guild, int year, OmdbParentalRating parentalRating) :
     this(imdbId, suggestor.Id, title, guild.Id, year, parentalRating)
 {
 }
Ejemplo n.º 5
0
        public async Task CreateAsync(CommandContext context, [Description("The channel in which to announce the movie night")] DiscordChannel announcementChannel)
        {
            TimeZoneInfo hostTimeZoneInfo = await GetUserTimeZoneInfoAsync(context);

            DiscordMessage confirmationMessage = await context.RespondAsync("Hi, you'd like to schedule a recurring movie night?");

            InteractivityExtension interactivity = context.Client.GetInteractivity();
            Reaction reaction = await interactivity.AddAndWaitForYesNoReaction(confirmationMessage, context.Member);

            if (reaction != Reaction.Yes)
            {
                await context.Channel.SendMessageAsync("Ok. I will end the process.");

                return;
            }

            DayOfWeek movieStartDayOfWeek = await GetMovieStartDayOfWeek(context, interactivity);

            TimeSpan movieStartTimeOfDay = await GetMovieStartTimeOfDay(context, interactivity);

            await context.Channel.SendMessageAsync("How many days and hours before the movie starts do you want voting to end? Format: 0d0h");

            (int voteEndDays, int voteEndHours) = await GetDaysAndHours(context, interactivity);

            (DayOfWeek voteEndDayOfWeek, TimeSpan voteEndTimeSpan) = GenerateCronEspressoVariables(movieStartDayOfWeek, movieStartTimeOfDay, voteEndDays, voteEndHours);

            await context.Channel.SendMessageAsync("How many days and hours before the movie starts do you want voting to start? Format: 0d0h");

            (int voteStartDays, int voteStartHours) = await GetDaysAndHours(context, interactivity);

            (DayOfWeek voteStartDayOfWeek, TimeSpan voteStartTimeSpan) = GenerateCronEspressoVariables(movieStartDayOfWeek, movieStartTimeOfDay, voteStartDays, voteStartHours);

            OmdbParentalRating maxParentalRating = await GetMaxParentalRating(context, interactivity);

            int maximumNumberOfSuggestions = await GetMaximumNumberOfSuggestions(context, interactivity);

            string voteStartCron  = GenerateCronExpression(voteStartTimeSpan, voteStartDayOfWeek);
            string voteEndCron    = GenerateCronExpression(voteEndTimeSpan, voteEndDayOfWeek);
            string movieStartCron = GenerateCronExpression(movieStartTimeOfDay, movieStartDayOfWeek);

            string guid            = Guid.NewGuid().ToString();
            string voteStartJobId  = $"{context.Guild.Id}-{context.Member.Id}-{guid}-voting-start";
            string voteEndJobId    = $"{context.Guild.Id}-{context.Member.Id}-{guid}-voting-end";
            string startMovieJobId = $"{context.Guild.Id}-{context.Member.Id}-{guid}-start-movie";

            DbResult <GuildMovieNight> addMovieNightResult = await this.mediator.Send(new GuildMovieNights.Add(voteStartJobId, voteEndJobId, startMovieJobId, maximumNumberOfSuggestions, maxParentalRating, context.Guild, announcementChannel, context.Member));

            if (!addMovieNightResult.TryGetValue(out GuildMovieNight? movieNight))
            {
                await context.Channel.SendMessageAsync("I failed in adding the movie night to the database. Logs have been sent to the developer.");

                throw new Exception(
                          $@"voteStartJobId: {voteStartJobId}
voteEndJobId: {voteEndJobId}
startMovieJobId: {startMovieJobId}
maximumNumberOfSuggestions: {maximumNumberOfSuggestions}
maxParentalRating: {maxParentalRating}
guild: {context.Guild.Id}
announcementChannel: {announcementChannel.Id}
host: {context.Member.Id}");
            }

            RecurringJob.AddOrUpdate <MovieNightService>(voteStartJobId, mns => mns.StartVoting(movieNight.Id), voteStartCron, new RecurringJobOptions()
            {
                TimeZone = hostTimeZoneInfo
            });
            RecurringJob.AddOrUpdate <MovieNightService>(voteEndJobId, mns => mns.CalculateVotes(movieNight.Id), voteEndCron, new RecurringJobOptions()
            {
                TimeZone = hostTimeZoneInfo
            });
            RecurringJob.AddOrUpdate <MovieNightService>(startMovieJobId, mns => mns.StartMovie(movieNight.Id), movieStartCron, new RecurringJobOptions()
            {
                TimeZone = hostTimeZoneInfo
            });
            Dictionary <string, RecurringJobDto>?rJobDtos = JobStorage.Current
                                                            .GetConnection()
                                                            .GetRecurringJobs(new List <string>()
            {
                voteStartJobId, voteEndJobId, startMovieJobId
            })
                                                            .ToDictionary(x => x.Id);

            await context.Channel.SendMessageAsync("Your movie night has been scheduled.");

            if (rJobDtos[voteStartJobId].NextExecution !.Value > rJobDtos[startMovieJobId].NextExecution !.Value)
            {
                await context.Channel.SendMessageAsync($"{context.Member.Mention}, the next scheduled voting will happen after the movie night is supposed to happen. To handle this, we are going to open voting now and close voting at the normal scheduled time. If the normal scheduled time to close voting can't be used, we will cancel the next movie night altogether and will not open voting.");

                if (rJobDtos[voteEndJobId].NextExecution !.Value > rJobDtos[startMovieJobId].NextExecution !.Value)
                {
                    JobStorage.Current.GetConnection().SetRangeInHash(
                        $"recurring-job:{startMovieJobId}",
                        new[] { new KeyValuePair <string, string>("skip", "true") }
                        );
                }

                BackgroundJob.Enqueue <MovieNightService>(mns => mns.StartVoting(movieNight.Id));
            }
        }
Ejemplo n.º 6
0
 public Add(string imdbId, ulong suggestorId, string title, ulong guildId, int year, OmdbParentalRating parentalRating)
 {
     this.MovieSuggestion = new GuildMovieSuggestion(imdbId, suggestorId, title, guildId, year, parentalRating);
 }
Ejemplo n.º 7
0
 public GetRandomGuildMovieSuggestions(DiscordGuild guild, int numSuggestions, OmdbParentalRating maximumRating)
     : this(guild.Id, numSuggestions, maximumRating)
 {
 }
Ejemplo n.º 8
0
 public GetRandomGuildMovieSuggestions(ulong guildId, int numSuggestions, OmdbParentalRating maximumRating)
 {
     this.GuildId             = guildId;
     this.NumberOfSuggestions = numSuggestions;
     this.MaximumRating       = maximumRating;
 }
 public static string ToQueryValue(this OmdbParentalRating rating)
 => rating switch
 {
 public GuildMovieSuggestion(string imdbId, ulong suggesterId, string title, ulong guildId, int year, OmdbParentalRating rating)
 {
     this.ImdbId      = imdbId;
     this.SuggesterId = suggesterId;
     this.Title       = title;
     this.GuildId     = guildId;
     this.Rating      = rating;
     this.Year        = year;
 }