Beispiel #1
0
        private async Task DropItems(IReadOnlyCollection <Item> items)
        {
            if (items.Count > MaxRequestCount)
            {
                var clamped = $"Users are limited to {MaxRequestCount} items per command. Please use this bot responsibly.";
                await ReplyAsync(clamped).ConfigureAwait(false);

                items = items.Take(MaxRequestCount).ToArray();
            }

            var user        = Context.User;
            var mention     = Context.User.Mention;
            var requestInfo = new DropRequest(user.Username, user.Id, items)
            {
                OnFinish = success =>
                {
                    var reply = success
                        ? "Items have been dropped by the bot. Please pick them up!"
                        : "Failed to inject items. Please tell the bot owner to look at the logs!";
                    Task.Run(async() => await ReplyAsync($"{mention}: {reply}").ConfigureAwait(false));
                }
            };

            Globals.Bot.DropState.Injections.Enqueue(requestInfo);

            var msg = $"{mention}: Item drop request{(requestInfo.Items.Count > 1 ? "s" : string.Empty)} have been added to the queue and will be dropped momentarily.";

            await ReplyAsync(msg).ConfigureAwait(false);
        }
 public DropGameRequestViewModel(DropRequest dropRequest, IClock clock)
 {
     DropRequestID = dropRequest.DropRequestID;
     Timestamp     = dropRequest.Timestamp.ToDateTimeUtc();
     Successful    = dropRequest.Successful;
     MasterGame    = new MasterGameViewModel(dropRequest.MasterGame, clock);
 }
Beispiel #3
0
 public DropRequestEntity(DropRequest domain, bool successful)
 {
     DropRequestID = domain.DropRequestID;
     PublisherID   = domain.Publisher.PublisherID;
     MasterGameID  = domain.MasterGame.MasterGameID;
     Timestamp     = domain.Timestamp.ToDateTimeUtc();
     Successful    = successful;
 }
 public DropGameRequestViewModel(DropRequest dropRequest, LocalDate currentDate)
 {
     DropRequestID = dropRequest.DropRequestID;
     PublisherID   = dropRequest.Publisher.PublisherID;
     PublisherName = dropRequest.Publisher.PublisherName;
     Timestamp     = dropRequest.Timestamp;
     Successful    = dropRequest.Successful;
     MasterGame    = new MasterGameViewModel(dropRequest.MasterGame, currentDate);
 }
Beispiel #5
0
 public DropRequestEntity(DropRequest domain, bool successful, Guid processSetID)
 {
     DropRequestID = domain.DropRequestID;
     PublisherID   = domain.Publisher.PublisherID;
     MasterGameID  = domain.MasterGame.MasterGameID;
     Timestamp     = domain.Timestamp;
     Successful    = successful;
     ProcessSetID  = processSetID;
 }
Beispiel #6
0
 public DropRequestEntity(DropRequest domain)
 {
     DropRequestID = domain.DropRequestID;
     PublisherID   = domain.Publisher.PublisherID;
     MasterGameID  = domain.MasterGame.MasterGameID;
     Timestamp     = domain.Timestamp;
     Successful    = domain.Successful;
     ProcessSetID  = domain.ProcessSetID;
 }
        internal void PlayerDrop()
        {
            DropRequest request = new DropRequest
            {
                user_id = int.Parse(GameVariables.userId),
                room_id = roomId,
            };

            SocketConnectionManager.GetInstance.SendSocketRequest(GameVariables.SocketRequestType.drop, request);
        }
Beispiel #8
0
        public async Task <Result> RemoveDropRequest(DropRequest dropRequest)
        {
            if (dropRequest.Successful != null)
            {
                return(Result.Fail("Drop request has already been processed"));
            }

            await _fantasyCriticRepo.RemoveDropRequest(dropRequest);

            return(Result.Ok());
        }
        public void DropDatabase()
        {
            var request = new DropRequest();

            var response = Channel.SendRequest(request);

            if (response is ExceptionResponse exResponse)
            {
                throw new CacheException("Error while dropping database. ", exResponse.Message,
                                         exResponse.CallStack);
            }
        }
Beispiel #10
0
        public async Task <ActionResult <BoolResult> > Drop([FromBody] DropRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Channels))
            {
                return(Unauthorized());
            }

            await _channelRepository.DropAsync(request.SiteId, request.SourceId, request.TargetId, request.DropType);

            return(new BoolResult
            {
                Value = true
            });
        }
    public DropResult CanDropGame(DropRequest request, LeagueYear leagueYear, Publisher publisher)
    {
        List <ClaimError> dropErrors = new List <ClaimError>();

        var basicErrors = GetBasicErrors(leagueYear.League, publisher);

        dropErrors.AddRange(basicErrors);

        var currentDate      = _clock.GetToday();
        var masterGameErrors = GetGenericSlotMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, true, currentDate, currentDate, false, false, false);

        dropErrors.AddRange(masterGameErrors);

        //Drop limits
        var publisherGame = publisher.GetPublisherGame(request.MasterGame);

        if (publisherGame is null)
        {
            return(new DropResult(Result.Failure("Cannot drop a game that you do not have")));
        }
        if (dropErrors.Any())
        {
            return(new DropResult(Result.Failure("Game is no longer eligible for dropping.")));
        }
        bool gameWasDrafted = publisherGame.OverallDraftPosition.HasValue;

        if (!gameWasDrafted && leagueYear.Options.DropOnlyDraftGames)
        {
            return(new DropResult(Result.Failure("You can only drop games that you drafted due to your league settings.")));
        }

        var  otherPublishers      = leagueYear.GetAllPublishersExcept(publisher);
        bool gameWasCounterPicked = otherPublishers
                                    .SelectMany(x => x.PublisherGames)
                                    .Where(x => x.CounterPick)
                                    .ContainsGame(request.MasterGame);

        if (gameWasCounterPicked && leagueYear.Options.CounterPicksBlockDrops)
        {
            return(new DropResult(Result.Failure("You cannot drop that game because it was counter picked.")));
        }

        bool gameWillRelease = publisherGame.WillRelease();
        var  dropResult      = publisher.CanDropGame(gameWillRelease, leagueYear.Options);

        return(new DropResult(dropResult));
    }
        public DropResult CanDropGame(DropRequest request, IEnumerable <SupportedYear> supportedYears, LeagueYear leagueYear, Publisher publisher, IEnumerable <Publisher> otherPublishers)
        {
            List <ClaimError> dropErrors = new List <ClaimError>();

            var basicErrors = GetBasicErrors(request.Publisher.LeagueYear.League, publisher, supportedYears);

            dropErrors.AddRange(basicErrors);

            var masterGameErrors = GetMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, false, true, null);

            dropErrors.AddRange(masterGameErrors);

            //Drop limits
            var publisherGame = publisher.GetPublisherGame(request.MasterGame);

            if (publisherGame.HasNoValue)
            {
                return(new DropResult(Result.Failure("Cannot drop a game that you do not have"), false));
            }
            bool gameWillRelease = publisherGame.Value.WillRelease();

            if (dropErrors.Any())
            {
                return(new DropResult(Result.Failure("Game is no longer eligible for dropping."), !gameWillRelease));
            }
            bool gameWasDrafted = publisherGame.Value.OverallDraftPosition.HasValue;

            if (!gameWasDrafted && leagueYear.Options.DropOnlyDraftGames)
            {
                return(new DropResult(Result.Failure("You can only drop games that you drafted due to your league settings."), false));
            }

            bool gameWasCounterPicked = otherPublishers
                                        .SelectMany(x => x.PublisherGames)
                                        .Where(x => x.CounterPick)
                                        .ContainsGame(request.MasterGame);

            if (gameWasCounterPicked && leagueYear.Options.CounterPicksBlockDrops)
            {
                return(new DropResult(Result.Failure("You cannot drop that game because it was counter picked."), false));
            }

            var dropResult = publisher.CanDropGame(gameWillRelease);

            return(new DropResult(dropResult, !gameWillRelease));
        }
        public async Task <DropResult> MakeDropRequest(Publisher publisher, PublisherGame publisherGame)
        {
            if (publisherGame.CounterPick)
            {
                return(new DropResult(Result.Failure("You can't drop a counterpick."), false));
            }

            if (publisherGame.MasterGame.HasNoValue)
            {
                return(new DropResult(Result.Failure("You can't drop a game that is not linked to a master game. Please see the FAQ section on dropping games."), false));
            }

            MasterGame masterGame = publisherGame.MasterGame.Value.MasterGame;
            IReadOnlyList <DropRequest> dropRequests = await _fantasyCriticRepo.GetActiveDropRequests(publisher);

            bool alreadyDropping = dropRequests.Select(x => x.MasterGame.MasterGameID).Contains(masterGame.MasterGameID);

            if (alreadyDropping)
            {
                return(new DropResult(Result.Failure("You cannot have two active drop requests for the same game."), false));
            }

            DropRequest dropRequest    = new DropRequest(Guid.NewGuid(), publisher, publisher.LeagueYear, masterGame, _clock.GetCurrentInstant(), null);
            var         supportedYears = await _fantasyCriticRepo.GetSupportedYears();

            var publishersInLeague = await _fantasyCriticRepo.GetPublishersInLeagueForYear(publisher.LeagueYear);

            var otherPublishers = publishersInLeague.Except(new List <Publisher>()
            {
                publisher
            });

            var dropResult = CanDropGame(dropRequest, supportedYears, publisher.LeagueYear, publisher, otherPublishers);

            if (dropResult.Result.IsFailure)
            {
                return(dropResult);
            }

            await _fantasyCriticRepo.CreateDropRequest(dropRequest);

            return(dropResult);
        }
    public async Task <DropResult> MakeDropRequest(LeagueYear leagueYear, Publisher publisher, PublisherGame publisherGame, bool justCheck)
    {
        if (publisherGame.CounterPick)
        {
            return(new DropResult(Result.Failure("You can't drop a counter pick.")));
        }

        if (publisherGame.MasterGame is null)
        {
            return(new DropResult(Result.Failure("You can't drop a game that is not linked to a master game. Please see the FAQ section on dropping games.")));
        }

        MasterGame masterGame = publisherGame.MasterGame.MasterGame;
        IReadOnlyList <DropRequest> dropRequests = await _fantasyCriticRepo.GetActiveDropRequests(leagueYear, publisher);

        bool alreadyDropping = dropRequests.Select(x => x.MasterGame.MasterGameID).Contains(masterGame.MasterGameID);

        if (alreadyDropping)
        {
            return(new DropResult(Result.Failure("You cannot have two active drop requests for the same game.")));
        }

        DropRequest dropRequest = new DropRequest(Guid.NewGuid(), publisher, leagueYear, masterGame, _clock.GetCurrentInstant(), null, null);
        var         dropResult  = CanDropGame(dropRequest, leagueYear, publisher);

        if (dropResult.Result.IsFailure)
        {
            return(dropResult);
        }

        if (!justCheck)
        {
            await _fantasyCriticRepo.CreateDropRequest(dropRequest);
        }

        return(dropResult);
    }
 public Task RemoveDropRequest(DropRequest dropRequest)
 {
     throw new NotImplementedException();
 }
 public Task CreateDropRequest(DropRequest currentDropRequest)
 {
     throw new NotImplementedException();
 }